安装环境:
Ubuntu16.04
cuda 10.2
pytorch 1.7.1
不管是mmcv还是mmdetection都有官方文档的安装教程,下面是地址:
安装mmcv:https://github.com/open-mmlab/mmcv
安装mmdetection: https://github.com/open-mmlab/mmdetection
pip install mmcv
(1)最简单的安装方法是直接运行指令:
pip install mmcv-full
(2)知道自己的cuda版本和pytorch版本之后可以使用如下指令来安装对应版本:
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
其中{cu_version}是电脑的cuda版本,{torch_version}是pytorch版本,比如cuda11.0和pytorch1.7.0对应的安装指令如下:
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
(3)如果要安装指定版本,可以使用如下指令:
pip install mmcv-full=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
类似的安装1.2.2版本可以这样:
pip install mmcv-full==1.2.2 -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
注意: mmcv和cuda的版本一定要对应,不然可能会出错。官方的GitHub仓库也给出了几个常用版本的cuda和pytorch版本的快速安装指令。
源码安装的官方地址如下:
https://mmcv.readthedocs.io/en/latest/build.html
安装方法:
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
MMCV_WITH_OPS=1 pip install -e . # 安装full版本
这个方法可能会出现cuda版本不符的情况,我试了几次没有成功。
下载地址:
https://download.openmmlab.com/mmcv/dist/index.html
从地址中找到对应的cuda、pytorch、Python和操作系统版本,下载下来之后使用如下指令安装:
pip install ***.whl
**是下载下来的whl文件的名字。
官方的安装教程:
https://github.com/open-mmlab/mmdetection
官方要求的基本配置为:
Linux or macOS (Windows is in experimental support)
Python 3.6+
PyTorch 1.3+
CUDA 9.2+ (If you build PyTorch from source, CUDA 9.0 is also compatible)
GCC 5+
MMCV
安装步骤:
1.下载源码:
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
2.安装依赖和mmdetection
pip install -r requirements/build.txt
pip install -v -e . # or "python setup.py develop"
经过一段时间的等待之后mmdetection就安装完成了。
首先需要下载想使用网络的模型,比如我想使用faster-rcnn,那么进入mmdetection/configs/faster_rcnn文件夹,里面有多个版本的faster-rcnn的配置文件,从里面选择一个,然后从README.md中下载对应的模型,将下载下来的pth文件放到checkpoints文件夹下。
可以在demo文件夹下新建demo.py,然后输入代码
from mmdet.apis import init_detector, inference_detector
import mmcv
# Specify the path to model config and checkpoint file
config_file = '../configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = '../checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# test a single image and show the results
img = 'demo.jpg' # or img = mmcv.imread(img), which will only load it once
result = inference_detector(model, img)
# visualize the results in a new window
model.show_result(img, result)
# or save the visualization results to image files
model.show_result(img, result, out_file='result.jpg')