23 lines
592 B
Python
23 lines
592 B
Python
|
# Copyright (c) OpenMMLab. All rights reserved.
|
||
|
from distutils.command.config import config
|
||
|
|
||
|
from mmdet.apis import inference_detector, init_detector
|
||
|
from PIL import Image
|
||
|
from io import BytesIO
|
||
|
|
||
|
config = "model/yolox_s_8x8_300e_cocotext_1280.py"
|
||
|
checkpoint = "model/best_bbox_mAP_epoch_294.pth"
|
||
|
device = "cpu"
|
||
|
|
||
|
|
||
|
def read_imagefile(file) -> Image.Image:
|
||
|
image = Image.open(BytesIO(file))
|
||
|
return image
|
||
|
|
||
|
|
||
|
def detection_predict(image):
|
||
|
model = init_detector(config, checkpoint, device=device)
|
||
|
# test a single image
|
||
|
result = inference_detector(model, image)
|
||
|
return result
|