1、参考官网假设当前已经成功安装 CUDA 10.1,这里提供了一个完整的基于 conda 安装 MMDetection 的脚本
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=11.0 -c pytorch -y # 去掉-c下载会快一点 记得找对相应的版本号
安装最新版本的 mmcv
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.1/index.html
安装 MMDetection
git clone https://github.com/open-mmlab/mmdetection.git(就是下载mmdetection文件到本地,再cd到目录里)
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e
pip install mmdet
(运行时,再相应的补充所需要的库)
验证
官网里有下载权重的链接
from mmdet.apis import init_detector, inference_detector
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# 从 model zoo 下载 checkpoint 并放在 `checkpoints/` 文件下
# 网址为: 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'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
img = 'demo/demo.jpg'
result = inference_detector(model, img)
model.show_result(img, result)
model.show_result(img, result, out_file='demo.jpg')
最后可能会有一个报错,但图片是可以运行保存下来的,应该是安装好了,以后再碰到问题再看,目前是这样安装就运行出来了。