##创建虚拟环境:
source activate
conda create -n MaskRCNN python=3.6
conda activate MaskRCNN
##安装依赖包:
conda install ipython
pip install ninja yacs cython matplotlib tqdm opencv-python
##安装PyTorch
###官网:https://pytorch.org/get-started/locally/
pip3 install torch torchvision
# follow PyTorch installation in https://pytorch.org/get-started/locally/
# we give the instructions for CUDA 9.0
conda install -c pytorch pytorch-nightly torchvision cudatoolkit=9.0
######
python测试vision是否安装成功。
python
>>>>
##安装torchvision
git clone https://github.com/pytorch/vision.git
cd vision/
python setup.py install
##安装目录
export INSTALL_DIR=/data_1/software/pytorch/MaskRCNN
cd $INSTALL_DIR
##安装pycocotools
git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
python setup.py build_ext install
##安装apex
cd $INSTALL_DIR
git clone https://github.com/NVIDIA/apex.git
cd apex
python setup.py install --cuda_ext --cpp_ext
##安装maskrcnn-benchmark
cd $INSTALL_DIR
git clone https://github.com/facebookresearch/maskrcnn-benchmark.git
cd maskrcnn-benchmark
## the following will install the lib with
## symbolic links, so that you can modify
## the files if you want and won't need to
## re-build it
python setup.py build develop
错误集锦
(MaskRCNN) em@B-GUWEIXIN:/data_1/software/pytorch/MaskRCNN/cocoapi/PythonAPI$ python setup.py build_ext install
running build_ext
building 'pycocotools._mask' extension
gcc -pthread -B /home/em/.conda/envs/MaskRCNN/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/numpy/core/include -I../common -I/home/em/.conda/envs/MaskRCNN/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 ‘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
^
gcc -pthread -B /home/em/.conda/envs/MaskRCNN/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/numpy/core/include -I../common -I/home/em/.conda/envs/MaskRCNN/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
gcc: error: pycocotools/_mask.c: 没有那个文件或目录
error: command 'gcc' failed with exit status 1
解决方法:
手动用cython生成_mask.c
cd $MaskRCNN_Root/cocoapi/PythonAPI/pycocotools
cython _mask.pyx
cd ..
python setup.py build_ext install
em@B-GUWEIXIN:/data_1/software/pytorch/MaskRCNN/apex$ python setup.py install --cuda_ext --cpp_ext
torch.__version__ = 1.2.0.dev20190704
Traceback (most recent call last):
File "setup.py", line 64, in
check_cuda_torch_binary_vs_bare_metal(torch.utils.cpp_extension.CUDA_HOME)
File "setup.py", line 37, in check_cuda_torch_binary_vs_bare_metal
raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"], universal_newlines=True)
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ':/usr/local/cuda-9.0/bin/nvcc': ':/usr/local/cuda-9.0/bin/nvcc'
提示找不到 nvcc, 但是输入 nvcc --version, 却可以正常显示.
解决方法:
sudo ~/.bashrc
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
# 将上面的语句修改成:
export CUDA_HOME=/usr/local/cuda:$CUDA_HOME
source ~/.bashrc
打开新终端执行$ python setup.py install --cuda_ext --cpp_ext
(MaskRCNN) em@B-GUWEIXIN:/data_1/software/pytorch/MaskRCNN/maskrcnn-benchmark/demo$ python webcam.py
Traceback (most recent call last):
File "webcam.py", line 6, in
from predictor import COCODemo
File "/data_1/software/pytorch/MaskRCNN/maskrcnn-benchmark/demo/predictor.py", line 4, in
from torchvision import transforms as T
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/__init__.py", line 1, in
from torchvision import models
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/models/__init__.py", line 11, in
from . import detection
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/models/detection/__init__.py", line 1, in
from .faster_rcnn import *
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/models/detection/faster_rcnn.py", line 7, in
from torchvision.ops import misc as misc_nn_ops
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/ops/__init__.py", line 1, in
from .boxes import nms, box_iou
File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/ops/boxes.py", line 2, in
from torchvision import _C
ImportError: /home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/_C.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2at7getTypeERKNS_6TensorE
解决方法:
git clone https://github.com/pytorch/vision.git
cd vision/
python setup.py install