1、论文下载地址:
MMDetection: Open MMLab Detection Toolbox and Benchmark. [paper]
2、代码下载地址:
https://github.com/open-mmlab/mmdetection
3、创建虚拟环境并激活
conda create -n openmmlab python=3.7 -y
conda activate openmmlab
4、安装pytorch和torchvision
pip install torch===1.4.0 -f https://download.pytorch.org/whl/torch_stable.html
pip install torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
5、安装mmcv-full
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu100/torch1.4.0/index.html
我的CUDA版本是10.0,torch版本是1.4.0,大家针对性更改。安装编译需要很长一段时间,耐心等待。
6、安装apex
下载apex:
git clone https://github.com/NVIDIA/apex.git
进入apex目录安装
cd apex
python setup.py install
7、安装MMDetection
进入第2步骤下载的工程路径运行:
pip install -r requirements/build.txt
python setup.py develop
可能遇到错误:
No local packages or working download links found for panopticapi@ git+https://github.com/cocodataset/panopticapi.git
error: Could not find suitable distribution for Requirement.parse('panopticapi@ git+https://github.com/cocodataset/panopticapi.git')
错误原因:
服务器上网络问题,连不上github,所以git库包panopticapi失败。
解决方法:
1)手动下载panopticapi包
https://github.com/cocodataset/panopticapi
2)放到工程路径解压
3)手动编译
python panopticapi/setup.py develop
4)打开runtime.txt,删除第三行的 @ git+https://github.com.cnpmjs.org/cocodataset/panopticapi.git
5)重新运行python setup.py develop,编译成功。
8、下载预训练模型
下载地址:
https://github.com/open-mmlab/mmdetection/blob/master/docs/model_zoo.md
以faster R-CNN为例
1)
2)
3)新建checkpoints路径,将下载的模型放入
9、新建demo.py文件,输入以下代码
from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import cv2
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: https://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
image='demo/demo.jpg'
result = inference_detector(model, image)
show_result_pyplot(model, image, result, score_thr=0.3)
# image = model.show_result(image, result, score_thr=0.3)
#
# cv2.imshow('demo', image)
# cv2.waitKey()
10、运行得到结果
python demo.py