如下是mmdetection的github地址:
https://github.com/open-mmlab/mmdetection
在github中的INSTALL.md文件中,对mmdetection的安装已经有详细的说明,但个人感觉还是有些坑,下面是个人总结的安装与测试步骤:
安装:
1. 安装依赖,我的机器上安装的python3.5、cuda9.0、pytorch1.1,注意pytorch要安装不要低于1.1的版本,否则测试的时候会报错,issues建议安装pytorch1.1版本。
2. 安装 cython
sudo pip install cython
3. 安装mmcv
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
sudo pip install .
4.安装pycocotools, 如果不安装测试的时候会报错
sudo pip install pycocotools
5. 安装mmdetection
下载:
git clone https://github.com/open-mmlab/mmdetection
cd mmdetection
编译cuda:
./compile.sh
安装mmdetection:
python setup.py develop
测试:
1.下载预训练模型
https://github.com/open-mmlab/mmdetection/blob/master/MODEL_ZOO.md
在上述链接中下载需要测试的预训练模型,比如我下载的是faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth,并在mmdetection目录下新建目录checkpoints,将模型存放到该目录下。
2. 创建测试目录
在mmdetection目录下创建my_code/test目录,稍后将测试代码以及待图像存放在该目录下
mkdir -p my_code/test
3. 测试代码
#coding=utf-8
from mmdet.apis import init_detector
from mmdet.apis import inference_detector
from mmdet.apis import show_result
# 模型配置文件
config_file = '../../configs/faster_rcnn_r50_fpn_1x.py'
# 预训练模型文件
checkpoint_file = '../../checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth'
# 通过模型配置文件与预训练文件构建模型
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# 测试单张图片并进行展示
img = 'test1.jpg'
result = inference_detector(model, img)
show_result(img, result, model.CLASSES)
# 测试一个图像列表并保存结果图像
imgs = ['test1.jpg', 'test2.jpg', 'test3.jpg']
for i, result in enumerate(inference_detector(model, imgs)):
show_result(imgs[i], result, model.CLASSES, out_file='result_{}.jpg'.format(i))
4. 测试结果:
git clone https://github.com/open-mmlab/mmcv.gitgit clone https://github.com/open-mmlab/mmcv.git