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)
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值