MMDetection教程(一)数据测试

MMDetection教程(一)数据测试

测试

测试单张图片

python demo/image_demo.py ${IMAGE_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${GPU_ID}] [--score-thr ${SCORE_THR}]

例如使用Faster R-CNN模型测试demo.jpg图片,输入如下命令:

python demo/image_demo.py demo/demo.jpg configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
    checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth --device cpu

高阶API整合

from mmdet.apis import inference_detector, init_detector

# 训练配置文件
config = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'

# 网络权重路径
checkpoint = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'

# 创建模型
model = init_detector(config, checkpoint, device='cuda:0')

# 示例图片
img = 'demo/demo.jpg'

# inference
result = inference_detector(model, img)

# 在新窗口中展示检测结果
model.show_result(img, result)
# 将检测结果保存在文件中
model.show_result(img, result, out_file='result.jpg')