Mask rcnn environment configuration
After installing the Anaconda you can configure the Mask RCNN. Here I use the maskrcnn-benchmark, the environment is relatively simple to build.
1. Create a virtual environment:
source activate conda create -n MaskRCNN python = 3 conda activate MaskRCNN
After completion, the interface can be seen as follows:
2. Install the various dependencies:
conda install ipython pip install ninja yacs cython matplotlib tqdm opencv-python
3. Install PyTorch
PyTorch official website , according to their own computer configuration selected, there will be a corresponding command.
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
Here torchvision can test whether the installation was successful. If not installed, you need to download the source code to compile and install (do not worry, followed by write).
:~$ python >>>>import torch >>>>import torchvision
4. Install directory
export INSTALL_DIR = / data_1 / software / pytorch / MaskRCNN // set your own installation directory cd $INSTALL_DIR
5. Installation torchvision (if not previously successfully installed, perform this step; otherwise, skip to)
git clone https://github.com/pytorch/vision.git cd vision/ python setup.py install
6. Install pycocotools
git clone https://github.com/cocodataset/cocoapi.git cd cocoapi/PythonAPI python setup.py build_ext install
7. Install the apex
cd $INSTALL_DIR git clone https://github.com/NVIDIA/apex.git cd apex python setup.py install --cuda_ext --cpp_ext
8. Installation 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
Bingo!^-^ !
Error Collection
Question 1:
(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<x) { ys=0; ye=h-1; } ^ 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: No such file or directory error: command 'gcc' failed with exit status 1
Solution :
_Mask.c manually generated by cython
cd $MaskRCNN_Root/cocoapi/PythonAPI/pycocotools cython _mask.pyx cd .. python setup.py build_ext install
Question 2 :
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 <module> 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'
Suggesting that no nvcc, but the input nvcc --version, but they can be displayed properly.
Solution :
Modify environment variables Configuration
sudo ~/.bashrc export CUDA_HOME=$CUDA_HOME:/usr/local/cuda # The above statement is modified to: export CUDA_HOME=/usr/local/cuda:$CUDA_HOME source ~/.bashrc
Open a new terminal, execute the re-installed in the installation directory
$ python setup.py install --cuda_ext --cpp_ext
Question 3:
(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 <module> from predictor import COCODemo File "/data_1/software/pytorch/MaskRCNN/maskrcnn-benchmark/demo/predictor.py", line 4, in <module> from torchvision import transforms as T File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/__init__.py", line 1, in <module> from torchvision import models File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/models/__init__.py", line 11, in <module> from . import detection File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/models/detection/__init__.py", line 1, in <module> from .faster_rcnn import * File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/models/detection/faster_rcnn.py", line 7, in <module> 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 <module> from .boxes import nms, box_iou File "/home/em/.conda/envs/MaskRCNN/lib/python3.6/site-packages/torchvision/ops/boxes.py", line 2, in <module> 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
Solution :
The problem is that no torchvision well, you can install it by source, as described in Article V configuration mask rcnn the environment.
Question 4:
In the vision catalog python-> import torchvision no problem, change directories on the error.
Solution :
The torchvision and torchvision.egg-info file in the folder to /.conda/envs/MaskRCNN/lib/python3.6/site-packages/ vision below to delete the original.