-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
33 lines (28 loc) · 997 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from mmdet.apis import init_detector, inference_detector
# 目标检测配置文件
config_file = 'configs/yolox/yolox_tiny_8x8_300e_voc.py'
# 训练模型
checkpoint_file = '/data1/yuxinyi/project/search_yolox/tiny_tfs/epoch_300.pth'
# 配置模型
model = init_detector(config=config_file,
checkpoint=checkpoint_file,
device='cuda:0')
img = 'BUPT.jpg'
# 推理实际调用语句
# results = model(return_loss=False, rescale=True, **data)
result = inference_detector(model=model, imgs=img)
# 打印结果
# print(model.CLASSES)
# for i in result:
# print(i)
from PIL import Image, ImageDraw
# 打开原图
img = Image.open(img).convert('RGB')
# 画出目标框,因为一个类别可能对应多个目标
for item in result:
for rec in item:
x, y, w, h = rec[0], rec[1], rec[2], rec[3]
draw = ImageDraw.Draw(img)
draw.rectangle((x, y, w, h), width=2, outline='#41fc59')
# 保存结果图片
img.save('result.png')