安装mmcv-full
首先查看torch和cuda版本
官方给的命令如下:
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
我的torch_version是1.7.1, cu_version是cu101,应当使用如下命令:
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.1/index.html
但mmdetection安装mmcv-full一直在build,安装很多次都不行,故使用下面的链接,也就是将torch1.7.1换成torch1.7.0,最终很快就build通过。
pip install mmcv-full==1.3.9 -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.0/index.html
安装mmcv-full之后clone mmdetection
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
从gitee的镜像上clone,会快很多
git clone git@gitee.com:mirrors/mmdetection.git
pip install -r requirements/build.txt
pip install -v -e . # or "python setup.py develop"
Verification
用下面的代码进行验证即可
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')