1. 程式人生 > >【深度學習】Caffe2安裝 ubuntu16.04

【深度學習】Caffe2安裝 ubuntu16.04

1.介紹

一個輕量級的深度學習框架,商用專案上面貌似用的比較多,廢話不多說,看看怎麼裝

2.安裝

應為官網流程很詳細,直接給出官網連結,針對一些有問題的地方給予補充(算了,我還是寫一下)。我使用的平臺式Ubuntu 16.04,CUDA ,CUDNN,OPENCV都已經裝好

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的版本太低了

這裡寫圖片描述

#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