maskrcnn-benchmark在Colab复现

官方安装要求:

https://github.com/facebookresearch/maskrcnn-benchmark/blob/master/INSTALL.md

 

首先需要安装miniconda

%%bash
MINICONDA_INSTALLER_SCRIPT=Miniconda3-4.5.4-Linux-x86_64.sh
MINICONDA_PREFIX=/usr/local
wget https://repo.continuum.io/miniconda/$MINICONDA_INSTALLER_SCRIPT
chmod +x $MINICONDA_INSTALLER_SCRIPT
./$MINICONDA_INSTALLER_SCRIPT -b -f -p $MINICONDA_PREFIX

配置conda环境

import sys
sys.path
_ = (sys.path
        .append("/usr/local/lib/python3.6/site-packages"))

这里有个问题是无法使用conda activate myenvs来激活环境,不过问题不大,用原始环境安装一样。

用pip安装一些包,会出现restart runtime的情况,不要管,要不然要重新安装conda

!pip install ninja yacs cython matplotlib tqdm opencv-python

 安装pytorch相关包

!conda install -c pytorch pytorch-nightly torchvision cudatoolkit=9.0 --yes

 这里用conda装一下Cython后面编译需要用,pip安装成功的可以忽略这一步,如果编译出现问题可能就是没装Cython

! conda install Cython

 colab自带的是cudn11.0,用下面几段代码下载cudn9.0

!wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
!apt-get update
!apt-get install cuda=9.0.176-1

 新建一个github的文件夹下载github上的文件

# install pycocotools
# install cityscapesScripts
!mkdir github
%cd github
git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
python setup.py build_ext install


%cd github
git clone https://github.com/mcordts/cityscapesScripts.git
cd cityscapesScripts/
python setup.py build_ext install


重点来了,安装apex编译会报错,一方面是colab的gcc是7.0的版本,我们需要降级到gcc 5.5版本

!apt-get install gcc-5 g++-5
!cd /usr/bin && sudo rm gcc-7 g++-7 gcc g++ && sudo ln gcc-5 gcc && sudo ln g++-5 g++

但其实这样还是会报错如下内容

 安装apex出错解决方法:csrc/mlp.cpp:71:54: error: expected primary-expression before ‘>’ token

按照如下代码编译成功

%cd github
git clone https://github.com/NVIDIA/apex.git
%cd apex
!git checkout f3a960f80244cf9e80558ab30f7f7e8cbf03c0a0
!python setup.py install --cuda_ext --cpp_ext

该问题参考链接https://www.codeleading.com/article/41114235968/

你可能感兴趣的:(C++/ROS)