【深度学习】Caffe2安装 ubuntu16.04

1.介绍

一个轻量级的深度学习框架,商用项目上面貌似用的比较多,废话不多说,看看怎么装

2.安装

应为官网流程很详细,直接给出官网链接,针对一些有问题的地方给予补充(算了,我还是写一下)。我使用的平台式Ubuntu 16.04,CUDA ,CUDNN,OPENCV都已经装好

Caffe2官网

3.先安装依赖库

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

4. 下载代码

由于国内下载很慢,我将下好的代码上传到CSDN,后附链接

# Clone Caffe2's source code from our Github repository
git clone --recursive https://github.com/pytorch/pytorch.git && cd pytorch
git submodule update --init

5. 编译

# Create a directory to put Caffe2's build files in
mkdir build && cd build
# Configure Caffe2's build
# This looks for packages on your machine and figures out which functionality
# to include in the Caffe2 installation. The output of this command is very
# useful in debugging.
cmake ..
# Compile, link, and install Caffe2
sudo make install

6.编译时候遇到一个的问题

意思是说Eigen的版本太低了

【深度学习】Caffe2安装 ubuntu16.04_第1张图片

#error "Caffe2 requires Eigen to be at least 3.3.0.";
#error "Caffe2 requires Eigen to be at least 3.3.0.";

解决办法:

1.首先检查自己的 Eigen 版本:

cat /usr/include/eigen3/Eigen/src/Core/util/Macros.h | grep VERSION

我的是这个样子,版本低于3.3.0

EIGEN_WORLD_VERSION 3
EIGEN_MAJOR_VERSION 2
EIGEN_MINOR_VERSION 92

2.去下载高版本的Eigen

下载最github上的新版本的,不要下官网上的,项目已经迁移到github上面去了。

被墙下不了的点这个CSDN

如果下的是官网上的可能会下面的报错,应为cuda9需要高版本才能支持

usr/local/cuda-9.0/include/crt/common_functions.h:64:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                    ^
/usr/local/cuda-9.0/include/crt/common_functions.h:64:24: note: in definition of macro '__CUDACC_VER__'
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/cuda-9.0/include/crt/common_functions.h:64:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                    ^
/usr/local/cuda-9.0/include/crt/common_functions.h:64:24: note: in definition of macro '__CUDACC_VER__'
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."

然后解压,重命名为eigen3

3.移除旧的Eigen

cd /usr/include
sudo rm -rf eigen3/

4.移动我们下载加压好的Eigen到原来路径

sudo mv path/of/eigen3 /usr/include/

5.检查下载的 Eigen 版本:

 cat /usr/include/eigen3/Eigen/src/Core/util/Macros.h | grep VERSION

我的是这个样子:

EIGEN_WORLD_VERSION 3
EIGEN_MAJOR_VERSION 3
EIGEN_MINOR_VERSION 90

然后可以继续回去重新编译了sudo make install

问题:

测试是否安装成功:

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

如果Failure

WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.
WARNING:root:Debug message: /home/username/pytorch/build/caffe2/python/caffe2_pybind11_state_gpu.so: undefined symbol: _Py_ZeroStruct

CRITICAL:root:Cannot load caffe2.python. Error: /home/username/pytorch/build/caffe2/python/caffe2_pybind11_state.so: undefined symbol: _Py_ZeroStruct

/home/username/pytorch/build/caffe2/python/路径下执行下面命令

sudo ldconfig

再次执行测试

Success

更多问题可以去github上查找:https://github.com/caffe2/caffe2/labels/build

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