如何在ubuntu下安装detectron2_ubuntu16.04安装detectron教程

本教程详述了在Ubuntu 16.04上安装Detectron2的步骤,包括创建conda环境、安装CUDA 8、CuDNN 7、NCCL,以及Caffe2、COCO API和Detectron2的安装与验证。通过该教程,读者将能够成功配置运行Detectron2的环境。
摘要由CSDN通过智能技术生成

ubuntu16.04安装detectron教程

系统环境要求:NVIDIA GPU, Linux, Python2

Caffe2, 部分Python包, COCO API

1. python2.7

Detectron必须在python2环境,python3不支持, 推荐使用conda 创建一个新的环境python27,并且切换到新环境

conda create -n python27 python=2.7

conda activate python27

以下所有操作都在python2.7下执行

2. 安装 CUDA 8 + CuDNN 7 + NCCL

2.1 CUDA8安装

安装过程略

验证安装:nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2016 NVIDIA Corporation

Built on Tue_Jan_10_13:22:03_CST_2017

Cuda compilation tools, release 8.0, V8.0.61

2.2 从Debian文件安装CuDNN 7

# 1.Install the runtime library, for example:

sudo dpkg -i libcudnn7_7.0.3.11-1+cuda9.0_amd64.deb

# 2.Install the developer library, for example:

sudo dpkg -i libcudnn7-devel_7.0.3.11-1+cuda9.0_amd64.deb

# 3.Install the code samples and the cuDNN Library User Guide, for example:

sudo dpkg -i libcudnn7-doc_7.0.3.11-1+cuda9.0_amd64.deb

2.3 测试CuDNN 7

样例在/usr/src/cudnn_samples_v7路径下

1.Copy the cuDNN sample to a writable path.

$cp -r /usr/src/cudnn_samples_v7/ $HOME

2.Go to the writable path.

$ cd $HOME/cudnn_samples_v7/mnistCUDNN

3.Compile the mnistCUDNN sample.

$make clean && make

4.Run the mnistCUDNN sample.

$ ./mnistCUDNN

显示如下,表示安装成功: Test passed!

2.4 cuDNN从v6升级到v7

cuDNN v7可以与之前版本的cuDNN共存,例如v5或v6。 cuDNN v7 can coexist with previous versions of cuDNN, such as v5 or v6.

2.5 NCCL安装

下载安装包并安装

sudo dpkg -i nccl-repo-ubuntu1604-2.2.13-ga-cuda8.0_1-1_amd64.deb

3. 安装Caffe2

3.1 conda安装Caffe2

使用Anaconda在GPU + CUDA8 + CuDNN7环境下

conda install pytorch-nightly cuda80 -c pytorch

3.2 验证Caffe2

检查Caffe2的GPU依赖是否正确,下面命令输出的GPU卡的数量必须要大于0 ,否则不能使用Detectron

# To check if Caffe2 build was successful

python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"

# To check if Caffe2 GPU build was successful

# This must print a number > 0 in order to use Detectron

python -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())'

验证过程显示Failure,terminal重新输入 python -c 'from caffe2.python import core',可以显示错误信息

错误1: No module named google.protobuf.internal 解决方法:pip install protobuf

错误2: no moudle named past.builtins 解决方法:pip install future

4. 安装COCO API

# COCOAPI=/path/to/clone/cocoapi

git clone https://github.com/cocodataset/cocoapi.git $COCOAPI

cd $COCOAPI/PythonAPI

# Install into global site-packages

make install

# Alternatively, if you do not have permissions or prefer

# not to install the COCO API into global site-packages

python setup.py install --user

在make install 如出现错误error: pycocotools/_mask.c: No such file or directory:

解决方法:pip install cython

5. 安装Detectron

5.1 安装

Clone the Detectron repository:

# DETECTRON=/path/to/clone/detectron

git clone https://github.com/facebookresearch/detectron $DETECTRON

Install Python dependencies:

pip install -r $DETECTRON/requirements.txt

Set up Python modules:

cd $DETECTRON && make

Check that Detectron tests pass (e.g. for SpatialNarrowAsOp test):

python $DETECTRON/detectron/tests/test_spatial_narrow_as_op.py

5.2 运行Detectron

可以使用tools目录下内置的infer_simple.py 来使用预训练的模型来预测实际的照片,infer_simple.py里面调用的是detectron封装的vis_utils.vis_one_image API。

python tools/infer_simple.py \

--cfg configs/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml \

--output-dir /tmp/detectron-visualizations \

--image-ext jpg \

--wts https://dl.fbaipublicfiles.com/detectron/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl \

demo

最终,检测结果就以pdf的格式输出到了/tmp/detectron-visualizations目录下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值