cuda10.1 安装mmdetection

安装

1.使用 conda 新建虚拟环境,并进入该虚拟环境;

conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab

2.安装pytorch和torchvision

conda install pytorch torchvision -c pytorch

如果下载太慢/服务器无法翻墙,可以使用Anaconda清华镜像源,https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/。替换仓库源之后使用以下命令安装,去掉-c pytorch

conda install pytorch torchvision

3.安装mmcv-full

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.0/index.html

4.安装mmdetection

pip install mmdet

5.下载mmdet代码

git clone https://github.com/open-mmlab/mmdetection.git

验证MMdetection安装是否成功

1.下载预训练模型,并将模型放入代码的checkpoint文件夹中(如果没有,请新建该文件夹)
下载地址: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
2. 在mmdetection主目录中新建test_demo.py文件,文件内容为

from mmdet.apis import init_detector, inference_detector, show_result_pyplot
  
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
result = inference_detector(model, 'demo/demo.jpg')
img = 'demo/demo.jpg'
show_result_pyplot(model, img, result)

3.此时运行改代码会报错,还需要修改一个文件mmdet/core/visualization/image.py。
在该文件的函数 imshow_det_bboxes 开头添加

show=False
out_file='result.jpg' #会输出检测后的图片到主目录的result.jpg中

4.运行该文件,输出结果如下。安装成功。
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值