安装好mmdetectionV2.11后,测试demo不出现图片

from mmdet.apis import init_detector, inference_detector

config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: 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'
# init a detector
model = init_detector(config_file, checkpoint_file, device=device)
# inference the demo image
inference_detector(model, 'demo/demo.jpg')
print("finish")

加了最后一行print来看看是否程序结束,我运行的结果为:

Use load_from_local loader
/home/ws/wmyProjects/a-seg/mm-test/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)
finish

出现了一个警告,然后我去mmdetection官方文档查了一下,具体解释为这个,于是我修改了mmdetection->configs->base->datasets->coco_detection.py中的代码,按照官方文档进行修改,于是就没有警告了。https://mmdetection.readthedocs.io/en/latest/1_exist_data_model.html?highlight=ImageToTensor

但是没有警告也没有弹出图片,然后又找到了它的官方的inference_demo.ipynb文件,跟着它用jupyter notebook走了一下,发现弹出图片效果了,然后查看代码如下:

from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: 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'
# 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
img = 'demo/demo.jpg'
result = inference_detector(model, img)
# show the results
show_result_pyplot(model, img, result)

发现它多导入了show_result_pyplot ,并且用这个展示了结果图片show_result_pyplot(model, img, result)。

最后在jupyternotebook 或pycharm中运行都能得到预测的图片了。效果图如下:我是远程连学校的服务器,然后用pycharm的专业版连接服务器,并且mapping好地址,再配置解释器环境就能远程运行了。

  • 13
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乐享时分

你觉得有价值的话再打赏谢谢

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值