安装MMDetection

MMDetection是一个基于Pytorch实现的深度学习和目标检测代码库,包含了Faster-RCNN,YOLO,SSD等主流的目标检测算法代码和已经训练好的模型,方便我们进行目标检测算法的研究.MMDetection的安装步骤如下:

1. 创建一个Conda环境并Activate,很简单,就不详细说了;

2. 安装Pytorch:

conda install pytorch=1.6.0 torchvision torchaudio cudatoolkit=10.1 -c pytorch

一定要注意根据CUDA版本选择适当的Pytorch版本,比如CUDA版本是10.1,可以选择Pytorch版本为1.6.0,如果CUDA版本是10.0及以下的,需要升级到至少10.1,否则MMDetection运行时会报错;

3. 使用Git下载mmcv和mmdetection,可以从Github上下载,但是速度比较慢,建议从Gitee下载:

git clone https://gitee.com/cubone/mmdetection.git
git clone https://gitee.com/cubone/mmcv.git

4. 安装mmcv或者mmcv-full,其中mmcv是CPU版本,mmcv-full是GPU版本,根据Pytorch和CUDA版本选择合适的mmcv-full版本:

pip install mmcv-full==1.1.5+torch1.6.0+cu101 -f https://download.openmmlab.com/mmcv/dist/index.html

5. 检测是否安装成功,运行下面的Demo代码:

from mmdet.apis import init_detector, inference_detector

config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
device = 'cuda:0'
# init a detector
model = init_detector(config_file, device=device)
# inference the demo image
inference_detector(model, 'demo/demo.jpg')

如果没有报错,则说明安装成功!

原文地址:https://www.cnblogs.com/mstk/p/14090952.html