新建环境
conda create -n mmdetection python=3.7
激活环境
conda activate mmdetection
安装pytorch(在官网pytorch.org上找到对应版本)
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.2 -c pytorch
安装mccv-full
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
其中cu_version和torch_version根据自己的版本选择,比如我的是cuda10.2对应的pytorch1.7.1,使用如下命令进行安装
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.7.1/index.html
在别的服务器上配环境的时候按照上述步骤报错 Could not build wheels for mmcv-full
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mmcv-full
Running setup.py clean for mmcv-full
Failed to build mmcv-full
ERROR: Could not build wheels for mmcv-full, which is required to install pyproject.toml-based projects
通过下述命令成功安装
pip install -U openmim
mim install mmcv-full
github上下载项目 (master版本)open-mmlab/mmdetection: OpenMMLab Detection Toolbox and Benchmark (github.com)
build
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e .
项目文件夹下新建文件夹checkpoints,下载权重文件放到checkpoints里面,测试demo
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
得到检测结果
可能会有这个报错
TypeError: FormatCode() got an unexpected keyword argument ‘verify‘
解决方法见mmdetection 报错 TypeError: FormatCode() got an unexpected keyword argument ‘verify‘-CSDN博客
可参考文档:
mmdetection github open-mmlab/mmdetection: OpenMMLab Detection Toolbox and Benchmark (github.com)