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

编程入门 行业动态 更新时间:2024-10-11 15:15:12

安装mmdetection进行测试<a href=https://www.elefans.com/category/jswz/34/1769814.html style=不出图片和报错记录"/>

安装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/` 文件下
# 网址为: .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/` 文件下
# 网址为: .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 的学习传送门

更多推荐

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

本文发布于:2024-03-08 13:24:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1720998.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不出   报错   进行测试   图片   mmdetection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!