配置环境:
Win10
VS2019
CUDA11.0
Pytorch1.7
配置步骤:
1、下载FairMOT:
git clone --recursive https://github.com/ifzhang/FairMOT.git
2、使用anaconda创建并激活虚拟环境,安装pytorch1.7:
conda create -n FairMOT python=3.8
conda activate FairMOT
pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
3、在此处下载cython-bbox源码,并使用如下代码编译:
pip install cython
pip install ninja
cd cython-bbox
python setup.py build develop install
4、下载并编译DCNv2:
git clone -b pytorch_1.7 https://github.com/ifzhang/DCNv2.git
cd DCNv2
python setup.py build develop
5、安装依赖项:
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
6、至此FairMOT配置成功。
常见问题:
1、 cl版本检测问题
cpp_extension.py:237: UserWarning: Error checking compiler version for cl: 'utf-8' codec can't decode byte 0xd3 in position 0: invali
d continuation byte
解决方法:打开C:\anaconda3\envs\FairMOT\Lib\site-packages\torch\utils\cpp_extension.py,找到270行左右,将compiler_info.decode()改为compiler_info.decode('gbk'),如下图所示
2、编译cython-bbox时,报找不到cl错误
cpp_extension.py:189: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。
解决方法:
将Visual Studio中cl.exe
所在的目录添加到系统变量中的Path
变量,便可解决问题
3、编译DCNv2时报如下错误
ImportError: cannot import name '_nt_quote_args' from 'distutils.spawn' (C:\anaconda3\envs\FairMOT\lib\site-packages\setuptools\_distutils\spawn.py)
解决方法:将setuptools版本降低
pip install setuptools==59.6.0
4、DCNv2编译通过,但是运行时import _ext as _backend出错
解决方法:在一开始配置过程中,本文采用的是CUDA10.2,于是编译完成之后报了此错误,于是将CUDA改为11.0,重新编译DCNv2,再次运行时错误解决,因此有可能是pytorch的cuda版本与系统的cuda版本不一致导致的问题。
5、如果采用的是更高计算能力的显卡,比如3090,可能会出现如下问题
unsupported gpu architecture 'compute_86'
解决方法:
可以安装CUDA11.1,该版本支持compute_86,或者参考这篇文章将CUDA计算能力降级
6、DCNv2编译过程报错:error: identifier "THCudaBlas_SgemmBatched" is undefined,或者是无法打开<TH\TH.h>等问题
解决方法:大概率是因为pytorch版本较高,使用pytorch1.7版本的不会出现此类问题