配置环境:Python3.6.9、Ubuntu 18.04、PyTorch 1.2.0、CUDA 10.1、NCCL 2、GCC 7.5.0、GTX1660Ti
显卡驱动安装
执行命令,查看当前推荐显卡 ubuntu-drivers devices
安装推荐版本 sudo apt install nvidia-440 nvidia-settings nvidia-prime
CUDA 安装
https://developer.nvidia.com/cuda-10.1-download-archive-update1
也可以根据自己的需求下载对应的版本。
执行命令 chmod +x cuda_10.1.168_418.67_linux.run
注意:因为我们已经安装好了驱动,所以此时不需要安装驱动418.67了。
等待安装完毕之后执行以下命令:
sudo nano ~/.bashrc
打开.bashrc文件之后,将以下两句写到最末尾
export PATH="/usr/local/cuda-10.1/bin:$PATH"
export LD_LIBRARY_PATH="/usr/lcoal/cuda-10.1/lib64:$LD_LIBRARY_PATH"
完成之后,保存退出。最后执行以下命令
source ~/.bashrc
cudnn下载及其安装
https://developer.nvidia.com/cudnn
选择好与cuda对应版本的cudnn下载, 我当时选择的是cuDNN Library for Linux
下载完成之后,执行以下命令,将相关文件复制到cuda文件夹中。注意的是,cuDNN解压后的文件夹名称就是cuda。
sudo cp cuda/lib64/* /usr/local/cuda-10.1/lib64/
sudo cp cuda/include/* /usr/local/cuda-10.1/include/
pytorch1.2.0安装
https://pytorch.org/get-started/previous-versions/
这里为什么选择以前的版本安装,是因为使用pytorch1.5后,安装mmdetection可能会报错。
报错结果可能如下:
mmdet/ops/nms/src/nms_cuda.cpp:4:23: error: ‘AT_CHECK’ was not declared in this scope
#define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ")
后来,我重新安装了pytorch1.2版本,则没有报错。
在安装过程中,可能会出现如下错误:
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-392mjzes/future/setup.py'"'"'; __file__='"'"'/tmp/pip-install-392mjzes/future/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-wsfxr0g3
cwd: /tmp/pip-install-392mjzes/future/
Complete output (3 lines):
Traceback (most recent call last):
File "
ModuleNotFoundError: No module named 'setuptools'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
解决方案:
sudo pip3 install setuptools
mmcv安装
https://github.com/open-mmlab/mmcv
下载mmcv文件到本地,cd到mmcv文件夹下,执行命令:
sudo pip3 install -e .
注意:-e后面有一个空格和一个点,在输入命令时一定要带上空格和点
可能会遇到以下错误:
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/MyPC/DetectionTools/mmcv/setup.py'"'"'; __file__='"'"'/home/MyPC/DetectionTools/mmcv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
cwd: /home/MyPC/DetectionTools/mmcv/
Complete output (24 lines):
running develop
running egg_info
creating mmcv.egg-info
writing mmcv.egg-info/PKG-INFO
writing dependency_links to mmcv.egg-info/dependency_links.txt
writing requirements to mmcv.egg-info/requires.txt
writing top-level names to mmcv.egg-info/top_level.txt
writing manifest file 'mmcv.egg-info/SOURCES.txt'
reading manifest file 'mmcv.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'mmcv.egg-info/SOURCES.txt'
running build_ext
cythoning ./mmcv/video/optflow_warp/flow_warp_module.pyx to ./mmcv/video/optflow_warp/flow_warp_module.cpp
building 'mmcv._ext' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/mmcv
creating build/temp.linux-x86_64-3.6/mmcv/video
creating build/temp.linux-x86_64-3.6/mmcv/video/optflow_warp
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I/usr/include/python3.6m -c ./mmcv/video/optflow_warp/flow_warp.cpp -o build/temp.linux-x86_64-3.6/./mmcv/video/optflow_warp/flow_warp.o
x86_64-linux-gnu-gcc: error trying to exec 'cc1plus': execvp: No such file or directory
/home/MyPC/DetectionTools/mmcv/.eggs/Cython-0.29.17-py3.6-linux-x86_64.egg/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/MyPC/DetectionTools/mmcv/mmcv/video/optflow_warp/flow_warp_module.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/MyPC/DetectionTools/mmcv/setup.py'"'"'; __file__='"'"'/home/MyPC/DetectionTools/mmcv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.
出错原因:是因为gcc和g++版本不一致
解决方案:将版本变成一致即可。
或许你又可能遇到以下错误:
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/MyPC/DetectionTools/mmcv/setup.py'"'"'; __file__='"'"'/home/MyPC/DetectionTools/mmcv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
cwd: /home/MyPC/DetectionTools/mmcv/
Complete output (30 lines):
WARNING: The wheel package is not available.
WARNING: The wheel package is not available.
running develop
running egg_info
creating mmcv.egg-info
writing mmcv.egg-info/PKG-INFO
writing dependency_links to mmcv.egg-info/dependency_links.txt
writing requirements to mmcv.egg-info/requires.txt
writing top-level names to mmcv.egg-info/top_level.txt
writing manifest file 'mmcv.egg-info/SOURCES.txt'
reading manifest file 'mmcv.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'mmcv.egg-info/SOURCES.txt'
running build_ext
cythoning ./mmcv/video/optflow_warp/flow_warp_module.pyx to ./mmcv/video/optflow_warp/flow_warp_module.cpp
building 'mmcv._ext' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/mmcv
creating build/temp.linux-x86_64-3.6/mmcv/video
creating build/temp.linux-x86_64-3.6/mmcv/video/optflow_warp
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I/usr/include/python3.6m -c ./mmcv/video/optflow_warp/flow_warp.cpp -o build/temp.linux-x86_64-3.6/./mmcv/video/optflow_warp/flow_warp.o
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I/usr/include/python3.6m -c ./mmcv/video/optflow_warp/flow_warp_module.cpp -o build/temp.linux-x86_64-3.6/./mmcv/video/optflow_warp/flow_warp_module.o
./mmcv/video/optflow_warp/flow_warp_module.cpp:4:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
/home/MyPC/DetectionTools/mmcv/.eggs/Cython-0.29.17-py3.6-linux-x86_64.egg/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/MyPC/DetectionTools/mmcv/mmcv/video/optflow_warp/flow_warp_module.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/MyPC/DetectionTools/mmcv/setup.py'"'"'; __file__='"'"'/home/MyPC/DetectionTools/mmcv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.
解决方案:sudo apt install python3-dev
安装nccl(选装)
因为我安装的是老版本的mmdetection,新版本的nccl好像没有在INSTALL.md文件中写需要安装。
https://developer.nvidia.com/nccl
选择好需要的文件,下载运行即可。
mmdetection安装
https://github.com/open-mmlab/mmdetection
下载到本地后,cd到mmdetection的目录内,执行以下命令:
sudo pip3 install -r requirements/build.txt
sudo pip3 install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
sudo python3 setup.py develop
这个时候,可能又要报错啦,报错如下:
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-q_8woy5e/PythonAPI/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-q_8woy5e/PythonAPI/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-kyhfn6ds
cwd: /tmp/pip-req-build-q_8woy5e/PythonAPI
Complete output (65 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/pycocotools
copying pycocotools/mask.py -> build/lib.linux-x86_64-3.6/pycocotools
copying pycocotools/__init__.py -> build/lib.linux-x86_64-3.6/pycocotools
copying pycocotools/coco.py -> build/lib.linux-x86_64-3.6/pycocotools
copying pycocotools/cocoeval.py -> build/lib.linux-x86_64-3.6/pycocotools
running build_ext
building 'pycocotools._mask' extension
creating build/common
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/pycocotools
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I../common -I/usr/include/python3.6m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.6/../common/maskApi.o -Wno-cpp -Wno-unused-function -std=c99
../common/maskApi.c: In function ‘rleDecode’:
../common/maskApi.c:46:7: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
for( k=0; k
^~~
../common/maskApi.c:46:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
for( k=0; k
^
../common/maskApi.c: In function ‘rleFrPoly’:
../common/maskApi.c:166:3: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
for(j=0; j
^~~
../common/maskApi.c:166:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
for(j=0; j
^
../common/maskApi.c:167:3: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
for(j=0; j
^~~
../common/maskApi.c:167:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
for(j=0; j
^
../common/maskApi.c: In function ‘rleToString’:
../common/maskApi.c:212:7: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
if(more) c |= 0x20; c+=48; s[p++]=c;
^~
../common/maskApi.c:212:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
if(more) c |= 0x20; c+=48; s[p++]=c;
^
../common/maskApi.c: In function ‘rleFrString’:
../common/maskApi.c:220:3: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
while( s[m] ) m++; cnts=malloc(sizeof(uint)*m); m=0;
^~~~~
../common/maskApi.c:220:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘while’
while( s[m] ) m++; cnts=malloc(sizeof(uint)*m); m=0;
^~~~
../common/maskApi.c:228:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
if(m>2) x+=(long) cnts[m-2]; cnts[m++]=(uint) x;
^~
../common/maskApi.c:228:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
if(m>2) x+=(long) cnts[m-2]; cnts[m++]=(uint) x;
^~~~
../common/maskApi.c: In function ‘rleToBbox’:
../common/maskApi.c:141:31: warning: ‘xp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if(j%2==0) xp=x; else if(xp
^
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I../common -I/usr/include/python3.6m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.6/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99
x86_64-linux-gnu-gcc: error: pycocotools/_mask.c: No such file or directory
x86_64-linux-gnu-gcc: fatal error: no input files
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pycocotools
解决方案:sudo pip3 install cython
如果已经存在,那就先卸载再重装
最后重新执行以下命令:
sudo pip3 install -r requirements/build.txt
sudo pip3 install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
sudo python3 setup.py develop
这个时候等慢慢编译安装吧。