显卡:NVIDIA GEFORCE RTX 2060
python版本:3.7
CUDA: 11.0
PyTorch: 1.7.0+cu110
VS:Community 2017
1. 环境和包
- PyTorch: 偷懒直接clone另一个环境mmdet
conda create -n detectron2 --clone mmdet
conda list显示torch已经准备好了:
-
很多包:
pip install cython opencv-python pillow matplotlib termcolor cloudpickle tabulate tensorboard termcolor tqdm yacs mock fvcore pydot wheel future
-
pycocotools:
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
2. 修改部分代码
- …\Anaconda3\envs\detectron2\Lib\site-packages\torch\include\torch\csrc\jit\runtime\下的argument_spec.h文件
第160行的static constexpr size_t ARG_SPEC_DEPTH_LIMIT = 128
改为static const size_t ARG_SPEC_DEPTH_LIMIT = 128
- …\Anaconda3\envs\detectron2\Lib\site-packages\torch\include\pybind11\下的cast.h文件
第1449行的explicit operator type&() { return *(this->value); }
改为explicit operator type&() { return ((type)this->value); }
3. build
python setup.py build develop
等待一会,Build完成:
...
Finished processing dependencies for detectron2==0.2
conda list显示detectron2:
TIps:
- 如果你安装了多版本的VS,比如VS2015/2017/2019,想要用对应版本的VS时(以VS community 2017为例),需要运行
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
(确认一下自己的路径)和set DISTUTILS_USE_SDK=1
- 如果你的CUDA及PyTorch版本过高这一步可能会报错,我当时没有保存。大概需要改动的就是修改对应文件的函数名(ceil改为ceilf; floor改为floorf; round改为roundf)看具体的报错。