mmdetection是个非常好用的目标检测工具包,提供了大量的预训练模型,服务器上开发实在是太麻烦了,所以我尝试在我的windows电脑上安装了mmdetection,最终成功跑出了demo,如下:
版本信息如下:
- 显卡:RTX2070S
- 系统:Windows10
- cuda:11.1
- cudnn:8.1
- pytorch:1.8.0
- torchvision:0.9.0
- mmcv:1.3.9
- mmdetection:2.15.0
安装cuda和cudnn
下载cuda11.1并安装,下载地址如下:
CUDA Toolkit 11.1.0 | NVIDIA Developer
下载cudnn并复制到对应的cuda目录下,下载地址如下:
cuDNN Archive | NVIDIA Developer
不方便下载的小伙伴可以去这个地址下载:
cuda11和cudnn8.1.zip-深度学习文档类资源-CSDN下载
安装mmdetection
-
安装pytorch
这里我们安装的是1.8.0的pytorch
pip3 install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio===0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
有个规律是,一般你的torchvision会比你的torch高一个版本号。
-
安装mmcv
mmcv是mm系列的底层支持,包括安装mmclassification、mmsegmentation都会使用到mmcv,这里有两个安装版本,一个是简化的版本
mmcv
,一个是完整的版本mmcv-full
,完整的版本中包含了大量的算子,GPU下最好还是安装这个完整的版本,安装命令如下:pip install mmcv-full==1.3.9 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html
-
安装mmdetection
mmdetection和mmcv的版本要注意对应,这里的对应关系是:
MMDetection version MMCV version master mmcv-full>=1.3.8, <1.4.0 2.15.0 mmcv-full>=1.3.8, <1.4.0 2.14.0 mmcv-full>=1.3.8, <1.4.0 2.13.0 mmcv-full>=1.3.3, <1.4.0 2.12.0 mmcv-full>=1.3.3, <1.4.0 2.11.0 mmcv-full>=1.2.4, <1.4.0 2.10.0 mmcv-full>=1.2.4, <1.4.0 2.9.0 mmcv-full>=1.2.4, <1.4.0 2.8.0 mmcv-full>=1.2.4, <1.4.0 2.7.0 mmcv-full>=1.1.5, <1.4.0 2.6.0 mmcv-full>=1.1.5, <1.4.0 2.5.0 mmcv-full>=1.1.5, <1.4.0 2.4.0 mmcv-full>=1.1.1, <1.4.0 2.3.0 mmcv-full==1.0.5 2.3.0rc0 mmcv-full>=1.0.2 2.2.1 mmcv==0.6.2 2.2.0 mmcv==0.6.2 2.1.0 mmcv>=0.5.9, <=0.6.1 2.0.0 mmcv>=0.5.1, <=0.5.8 在上面的一步中我安装了1.3.9的mmcv,所以这步的安装我直接安装最新版本的mmdetection即可,执行下面一系列的操作即可:
# install mmdetection git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection pip install -r requirements/build.txt pip install -v -e .
测试demo
首先需要在mmdetection目录下新建一个checkpoints目录,下载FasterRcnn的权重到这个文件夹中,下载的地址是:
https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
在命令行中cd到mmdetection的路径,执行下列代码
python demo/image_demo.py demo/demo.jpg configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
成功!
另外,如果大家需要跑别的模型文件的话,可以去下面的网站找对应的模型和配置文件。
mmdetection/model_zoo.md at master · open-mmlab/mmdetection (github.com)