参考mmdetection中docs/install.md文件,总结安装步骤如下:
- 1、创建并激活虚拟环境
conda create -n mmdetection python=3.7
conda activate mmdetection
- 2、安装pytorch、cudatoolkit=10.0、 torchvision(cudatoolkit要与系统上安装的cuda版本匹配)
conda install pytorch cudatoolkit=10.0 torchvision
- 3、进入到mmdetection文件下,安装其它依赖库
cd mmdetection
python -m pip install -r requirements.txt
- 4、安装pycocotools
注意:安装pycocotools之前一定要先安装cython,否则会出错
conda install cython
官方给出在线安装命令,如下所示。但是由于网络原因,我们通常会安装失败。
#subdirectory=pycocotools代表安装cocoapi文件内的pycocotools文件
pip install "git+https://github.com/open-mmlab/cocoapi.git#subdirectory=pycocotools"
我们可以使用离线方式进行安装。首先使用gitee镜像下载cocoapi文件,然后打开cocoapi文件,将里面的pycocotools文件夹复制到对应虚拟环境的site-packages路径下,我的路径如下图所示:
执行pycocotools文件下的setup.py脚本,开始离线安装(执行此命令前,最好激活虚拟环境)
python setup.py install
- 5、安装mmdetection
python setup.py develop