ubuntu16.04下安装配置caffe2和detectron(亲测有效,非常简单)

介绍

Detectron是FAIR推出的一款优秀的物体检测、分割框架,基于caffe2,其中包含了Faster RCNN、Mask RCNN、FPN、RetinaNet、R-FCN、Openpose等常见的模型。可能是由于何凯明的缘故吧,Facebook集成了许多他提出的模型。该框架可以很方便的把这些模型应用到自己的工程和项目中,下面将具体介绍如何安装和配置caffe2和detectron。

安装配置caffe2

caffe2的安装网上教程有很多,但是有可能安装不成功,facebook开源的pytorch框架已经把caffe2集成到里面去啦~所以只需要安装pytorch即可。首先安装下依赖环境:

$ sudo apt-get update
$ sudo apt-get install -y --no-install-recommends \
    build-essential \
    cmake \
    git \
    libgoogle-glog-dev \
    libgtest-dev \
    libiomp-dev \
    libleveldb-dev \
    liblmdb-dev \
    libopencv-dev \
    libopenmpi-dev \
    libsnappy-dev \
    libprotobuf-dev \
    openmpi-bin \
    openmpi-doc \
    protobuf-compiler \
    python-dev \
    python-pip                          
$ sudo pip install \
    future \
    numpy \
    protobuf
 
# for Ubuntu 16.04
$ sudo apt-get install -y --no-install-recommends libgflags-dev

然后进入pytorch官网 "https://pytorch.org"找到适合自己的pytorch版本,然后根据推荐的指令进行安装即可,在这里我的是 pip3 install torch torchvision
ubuntu16.04下安装配置caffe2和detectron(亲测有效,非常简单)_第1张图片
然后在命令栏中进行安装即可。安装完成之后,进行测试,没有报错,说明安装成功。

oliver@oliver-System-Product-Name:~$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe2
>>> 

当出现No module named ‘past’ 错误之后,进行以下两个命令即可:

pip install future
pip install --upgrade future

当下面测试通过时,说明caffe2的安装配置成功啦~

$ python3 -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
Success
$ python3 -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())'
1

安装配置detectron

当完成caffe2的环境搭建之后,就可以配置detectron啦~,首先需要把源文件下载到本地

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

然后转到detectorn文件夹内:

pip install -r requirements.txt

如果权限不够的话:
pip install --user -r requirements.txt

接着:

make

make完成之后就算配置好detectron啦,下面来测试下,是否配置成功,进入requirements.txt目录下:

python detectron/tests/test_spatial_narrow_as_op.py

出现以下结果即是配置成功:

oliver@oliver-System-Product-Name:~/detectron$ python detectron/tests/test_spatial_narrow_as_op.py
net_drawer will not run correctly. Please install the correct dependencies.
[E init_intrinsics_check.cc:43] CPU feature avx is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
[E init_intrinsics_check.cc:43] CPU feature avx2 is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
[E init_intrinsics_check.cc:43] CPU feature fma is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
Found Detectron ops lib: /home/oliver/.local/lib/python3.6/site-packages/torch/lib/libcaffe2_detectron_ops_gpu.so
...
----------------------------------------------------------------------
Ran 3 tests in 2.160s

OK

你可能感兴趣的:(深度学习)