前言
这里为大家整理下自己使用mmdetection的一些经验
一、mmdetection是什么?
mmdetection是商汤科技(2018 COCO 目标检测挑战赛冠军)和香港中文大学最近开源了一个基于Pytorch实现的深度学习目标检测工具箱。
二、mmdetection的安装
1.安装依赖的过程中一定要考虑MMDetection 和 MMCV 版本兼容性。
下面给的链接里有一个表格,里面有所有mmdet对应的mmcv版本。简单的按照链接里的教程走,一般都不会有问题。里面还有更加详细的教程
# 如果官网下载比较慢的话,可以自己先在自己创建的虚拟环境下安装好GPU版本的pytorch,然后在自己的虚拟环境下执行pip install openmim后的内容
conda create -n openmmlab python=3.7 pytorch==1.6.0 cudatoolkit=10.1 torchvision -c pytorch -y
conda activate openmmlab
pip install openmim
mim install mmcv-full
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e . #注意这里结尾有个点
2.如果不想安装最新版本的mmdetection,可以在下面图片的箭头出处下载其他版本的,但是下载其他版本的,要注意不要用上面的安装方法了,他是自动安装最新版本的一些配置,可以手动安装!
手动安装过程
conda create -n openmmlab python=3.7 -y
conda activate openmmlab
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=10.2
# 安装指定版本的mmcv-full,对应mmdetection,下面的链接里有表格
pip install mmcv-full=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
eg:pip install mmcv-full==1.5.3 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
# 这样安装的是最新的mmdetection,如果上面自己下载了,就不用这个操作了
git clone https://github.com/open-mmlab/mmdetection.git
#只要在mmdetection的文件夹路径就行
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e .
3.验证方法
from mmdet.apis import init_detector, inference_detector
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
inference_detector(model, 'demo/demo.jpg')
# 有结果显示就说明安装成功了
转中文教程链接:里面有多种方法https://mmdetection.readthedocs.io/zh_CN/latest/get_started.html#id2
总结
安装有什么问题,可以在评论区留言。