之前安装走了许多弯路,踩了很多坑,终于花费了挺长一段时间成功安装了mmdetection2.7.0。
我的电脑安装环境:
win10
CUDA 10.0
python 3.7
torch 1.6.0
torchversion 0.7.0
完成cuda及cudnn下载安装后,再进行以下步骤:
1.首先打开Anaconda Powershell Prompt(之前在通过cmd打开没能配置成功),新建一个环境:
conda create -n mm1 python=3.7 -y
然后激活: conda activate mm1 进入mm1环境。
conda activate mm1
2.安装pytorch:
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.2 -c pytorch -y
3.安装mmcv-full(不要安装mmcv,而是安装mmcv-full才不会报错)
在https://download.openmmlab.com/mmcv/dist/index.html中下载/1.1.5/torch1.6.0/cu102/mmcv_full-1.1.5+torch1.6.0+cu102-cp37-cp37m-win_amd64.whl
然后通过:cd 文件位置 ,进入然后使用pip安装,例如:
4.通过github下载mmdetection2.7.0,解压到某一位置。通过cd到该位置,运行python setup.py install 如下:
5.接着安装requirements.txt就好了
pip install -r requirements.txt
至此,mmcv-full和mmdetection配置完成。
6.(验证)在下载好的mmdetection2.7.0文件中新建一个python文件,命名“test.py",然后将以下代码复制进去:
from mmdet.apis import init_detector, inference_detector
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# 从 model zoo 下载 checkpoint 并放在 `checkpoints/` 文件下
# 网址为: 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'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
img = 'demo/demo.jpg'
result = inference_detector(model, img)
model.show_result(img, result)
# 将推理的结果保存
model.show_result(img, result, out_file='result1.jpg')
接着新建一个文件夹"checkpoints",通过http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pthhttp://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth下载权重文件
faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
然后运行出现result.jpg如下图,即mmdetection配置成功!