安装mmdetection进行测试不出图片和报错记录

mmdetection

  • 1.代码出现usewarning
  • 2.运行结果不出图片

测试代码:

from mmdet.apis import init_detector, inference_detector
import matplotlib.pyplot as plt
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# 从 model zoo 下载 checkpoint 并放在 `checkpoints/` 文件下
# 网址为: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
img='demo/demo.jpg'
result=inference_detector(model, img)
model.show_result(img, result, out_file='result.jpg')

mode zool下载代码链接model zoo,将这个压缩包的进行下载,然后将测试代码放在这个文件夹下,还需要新建一个checkpoints的文件夹,把pth的文件放进去。
运行代码会出错如下:

1.代码出现usewarning

UserWarning: “ImageToTensor” pipeline is replaced by “DefaultFormatBundle” for batch inference. It is recommended to manually replace it in the test data pipeline in your config file.
‘data pipeline in your config file.’, UserWarning)
在这里插入图片描述
提示我们需要将pipline中的“ImgeToTensor”换成“DefaultFormatBundle”,文件夹指引configs——>base——>datasets——>coco_detection.py,按ctrl+F进行搜索“test_pipline”,将transforms下的“ImageToTensor”改为“DefaultFormatBundle”,然后删除后面的 keys=[‘img’]。

运行结果不报错了,但是不出图片。解决方法如下。

2.运行结果不出图片

找到inference.py后发现,里面显示图片的函数是show_result_pyplot,因此需要import show_result_pyplot。然后在代码中进行如下改动:

from mmdet.apis import init_detector, inference_detector,show_result_pyplot
import matplotlib.pyplot as plt
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# 从 model zoo 下载 checkpoint 并放在 `checkpoints/` 文件下
# 网址为: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
img='demo/demo.jpg'
result=inference_detector(model, img)
show_result_pyplot(model,img, result)
model.show_result(img, result, out_file='result.jpg')


大功告成啦!!!
mmdetection的安装以及学习链接mmdetection 的学习传送门

你可能感兴趣的:(报错合集,深度学习,python,人工智能,object,detection)