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

下大禹了

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

暂无评论

发表评论

相关推荐

TensorFlow 新手踩坑杂谈

如果可以建议你有个好CPU,有块好显卡才来做这个事情,当然如果你有台矿机最好,因为做过一个测试,GPU 的计算能力是CPU的100倍以上,这还是在我6年前购买的笔记本上测试的结果。 ten

目标检测与识别(R-CNN理解)

R-CNN就是regions with convolutiional networks,,这个算法尝试选出一些区域用来喂入卷积网络,不再需要使用滑动窗口对图片中依次从左到右,从上到下滑动窗