mmdetection初步运行

1.安装conda虚拟环境时,按照官方说明一次就正常安装好了;
2.需要提前下载模型权重,运行时会自动下载resnet等模型的预训练权重,可以提前下载好后放进对应的隐藏文件夹内;
3.运行推理代码:

python demo/image_demo.py 'demo/demo.jpg' 'configs/detectors/detectors_cascade_rcnn_r50_1x_coco.py' 'checkpoints/detectors_cascade_rcnn_r50_1x_coco-32a10ba0.pth'

会报警告:

/home/lgy/PycharmProjects/mmdetection/mmdet/datasets/utils.py:68: 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)

官方对该警告的建议是不用搭理,个人按警告替换后,报了一些奇奇怪怪的错误。

或者直接新建个py文件运行:

from mmdet.apis import init_detector, inference_detector
import mmcv

# Specify the path to model config and checkpoint file
config_file = 'configs/detectors/detectors_cascade_rcnn_r50_1x_coco.py'
checkpoint_file = 'checkpoints/detectors_cascade_rcnn_r50_1x_coco-32a10ba0.pth'

# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# test a single image and show the results
img = 'demo/demo.jpg'
# img = mmcv.imread(img) # which will only load it once
result = inference_detector(model, img)
# visualize the results in a new window
# 可视化推理检测的结果
model.show_result(img, result)
# or save the visualization results to image files
# 将推理的结果保存
model.show_result(img, result, out_file='result.jpg')

# test a video and show the results
# 测试视频片段的推理结果
# video = mmcv.VideoReader('video.mp4')
# for frame in video:
#     result = inference_detector(model, frame)
#     model.show_result(frame, result, wait_time=1)

版权声明:本文为CSDN博主「下大禹了」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43541325/article/details/115615142

下大禹了

我还没有学会写个人说明!

暂无评论

发表评论

相关推荐

实战 | 实时的目标检测与识别简单应用

吃粽子迎端午计算机视觉研究院专栏作者:Edison_G最近总是有很多入门的朋友问我,我进入计算机视觉这个领域难不难?是不是要学习很多知识?到底哪个方向比较好?长按扫描二维码关

【目标检测】ObjectDetection结构组成理解

目标检测结构理解 通常来说,对于目标检测而言,我们经常听到别人讲,”更换一下这个网络的backbone试试?“、”换个检测头吧“等相关这方面的术语。本篇讲围绕目标检测结构中的几个概念进行介