参考博客 https://blog.csdn.net/david_lee13/article/details/102940221
本人使用的版本
- python=3.6
- cuda=10.0
- cudnn=7.5.1
- pytorch=1.2.0
- torchversion=0.4.0
软件方面,以下软件都是几年前装TensorFlow、Keras的时候已经装过的,包括
vs2017、cuda10.0、cudnn7.5.1
创建了个虚拟环境 mmdet,并激活
conda create -n mmdet python=3.6
conda activate mmdet
因为参考的博客中说python3.7兼容不好,就用了3.6
安装pytorch、torchvision
好像使用命令行安装总出问题,另外,我在另外的虚拟环境(python=3.7)中也装过pytorch,貌似会产生冲突,于是使用了下载到本地安装的方法。
下载的网址: https://download.pytorch.org/whl/torch_stable.html
pip install torch-1.2.0-cp36-cp36m-win_amd64.whl
安装mmcv
这一步我记得好像是通过pip安装的
pip install mmcv
安装Cython
pip install Cython
安装pycocotools
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
安装mmdetection (这个我不小心安装在了存放下载的pytorch安装包的文件夹里,应该不影响使用)(如果没有git要先安装)
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
补充安装依赖包requirements:
这里我直接pip install -r requirements.txt 是有报错的,于是参考了https://mp.csdn.net/console/editor/html/107444096 的:
1.python项目中必须包含一个 requirements.txt 文件,用于记录所有依赖包及其精确的版本号。以便新环境部署。
requirements.txt可以通过pip命令自动生成和安装。
2.生成requirements.txt文件:pip freeze > requirements.txt
3.安装requirements.txt依赖:pip install -r requirements.txt
就生成requirement了
修改编译文件:
参考了网上资料,
1.将~Lib\site-packages\torch\utils\cpp_extension.py 中 ,所有decode() 都改成了decode("utf8","ignore")
2.修改setup.py文件中extra_compile_args 相关代码,增加cxx的:"-DMS_WIN64","-MD"
也就是将def make_cuda_ext(name, module, sources) 整个函数改为
def make_cuda_ext(name, module, sources):
return CUDAExtension(
name='{}.{}'.format(module, name),
sources=[os.path.join(*module.split('.'), p) for p in sources],
extra_compile_args={
'cxx': ["-DMS_WIN64","-MD"],
'nvcc': [
'-D__CUDA_NO_HALF_OPERATORS__',
'-D__CUDA_NO_HALF_CONVERSIONS__',
'-D__CUDA_NO_HALF2_OPERATORS__',
]
})
编译setup.py
在当前文件夹进行编译:
python setup.py build_ext --inplace
但出错,distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('torch>=1.3')
这里其实不是很懂,我看了mmdetection文件夹中requirements文件夹下的txt文件,将build.txt 和 runtime.txt 中的torch>=1.3都改成torch>=1.2,OK了。
又出现新的错误:error in mmdet setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.
这里参考了https://blog.csdn.net/baidu_23491131/article/details/99671929,更新setuptools的版本:
pip install --upgrade setputools
重新编译,显示 running build_ext, 这样应该通过了吧....
最后安装:
python setup.py install develop
Finish!
pip list
Package Version
--------------- ----------------
addict 2.2.1
certifi 2016.2.28
cycler 0.10.0
Cython 0.29.21
kiwisolver 1.2.0
matplotlib 3.3.0
mmcv 1.0.3
mmdet 2.3.0rc0+adc65ff
numpy 1.19.0
opencv-python 4.3.0.36
Pillow 7.2.0
pip 20.1.1
pycocotools 2.0
pyparsing 3.0.0a2
python-dateutil 2.8.1
PyYAML 5.3.1
setuptools 49.2.0
six 1.15.0
terminaltables 3.1.0
torch 1.2.0
torchvision 0.4.0
wheel 0.29.0
wincertstore 0.2
yapf 0.30.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)