1. 程式人生 > >Ubunt16.04安裝CUDA cuDNN OpenCV Caffe完整教程

Ubunt16.04安裝CUDA cuDNN OpenCV Caffe完整教程

一、 安裝CUDA

版本
cuda_8.0.61_375.26_linux.run

安裝過程

前期準備

1、確認有Nvidia的GPU

$ lspci | grep -i nvidia

2、確認你的GPU是否是CUDA-caplable
可以在這裡檢視

3、為當前核安裝kernel headers和development packages

$ sudo apt-get install linux-headers-$(uname -r)

4、使用以下命令檢視Nouveau驅動是否被載入了
* 注意: * Ubuntu系統剛剛安裝完成後,預設使用Nouveau驅動,不要進行附加驅動安裝,否則後面安裝CUDA會出現問題

$ lsmod | grep nouveau
# 如果打印出一些資訊,說明Nouveau被載入了,正常情況下會打印出一些關於nouveau的資訊

6、將Nouveau驅動加入禁用黑名單

# 建立nouveau黑名單
$vim /etc/modprobe.d/blacklist-nouveau.conf

在blacklist-nouveau.conf中新增如下內容

blacklist nouveau
options nouveau modeset=0

之後執行如下命令

# Regenerate the kernel initramfs
$ sudo update-initramfs -u

開始安裝

重新啟動系統後,按 Ctrl+Alt+F1 進入文字模式
1、關閉X service (必須先關閉,否則無法安裝Nvidia Graphic Driver)

$ sudo /etc/init.d/lightdm stop

2、為cuda_8.0.61_375.26_linux.run增加可執行許可權

Chmod +x cuda_8.0.61_375.26_linux.run

3、執行安裝

$ sudo ./cuda_8.0.61_375.26_linux.run

4、安裝過程中的選項選擇

除了opengl選項需要選擇no之外,其它一律選yes、default

5、重啟桌面服務

$ sudo service lightdm start

6、重新登入系統,新增CUDA環境變數

$ vim ~/.bashrc # 編輯

新增如下內容

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda-8.0
export PATH=/usr/local/cuda-8.0/bin:$PATH

使配置立即生效

$ source ~/.bashrc #配置立即生效

7、檢視CUDA是否安裝成功
使用如下命令檢視

$ nvcc -V

至此,CUDA已安裝完成!

二、安裝cuDN

版本 問題
cudnn-8.0-linux-x64-v5.0-ga.tgz 發現tensorflow最新版不支援cudnn5.0,需要安裝5.1版本
cudnn-8.0-linux-x64-v5.1.tgz 需要安裝5.1版本才能支援tensorflow

1、解壓
$ tar -zxvf cudnn-8.0-linux-x64-v5.0-ga.tgz

$ tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz

解壓完成會在當前目錄出現cuda的目錄
2、複製cudnn相關檔案到相關目錄

$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include/  
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/  
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h  
$ sudo chmod a+r /usr/local/cuda/lib64/libcudnn* 

至此,cudnn配置安裝完成!

三、安裝OpenCV

參考這裡

OpenCV 3.1 Installation Guide on Ubuntu 16.04

1、In Ubuntu 16.04, install the dependencies first and then build the OpenCV 3.1 from source.

$ sudo apt-get install --assume-yes build-essential cmake git
$ sudo apt-get install --assume-yes build-essential pkg-config unzip ffmpeg qtbase5-dev python-dev python3-dev python-numpy python3-numpy
$ sudo apt-get install --assume-yes libopencv-dev libgtk-3-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev
$ sudo apt-get install --assume-yes libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
$ sudo apt-get install --assume-yes libv4l-dev libtbb-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev
$ sudo apt-get install --assume-yes libvorbis-dev libxvidcore-dev v4l-utils

2、從github上下載最新的OpenCV程式碼
不要下載.zip包
Download the latest source archive for OpenCV 3.1 from https://github.com/opencv/opencv. (Do not download it from http://opencv.org/downloads.html, because the official OpenCV 3.1 does not support CUDA 8.0.)
進入opencv目錄,並執行以下命令

$ mkdir build
$ cd build/
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
$ make -j8
$ sudo make install
$ sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
$ sudo ldconfig
$ sudo apt-get update

下面就是泡杯茶,等待編譯完成,時間可能有點長…

使用opencv

opencv/build/lib/cv2.so複製到~/anaconda2/lib目錄下
運氣好的話,直接在python中可以import cv2就可以使用了
運氣不好的話,比如我第二次在遠端伺服器上安裝,遇到了如下錯誤

Traceback (most recent call last):
  File "train.py", line 5, in <module>
    import cv2
ImportError: /home/zwx/anaconda2/bin/../lib/libgomp.so.1: version `GOMP_4.0' not found (required by /usr/lib/x86_64-linux-gnu/libsoxr.so.0)

解決辦法如下:

It’s just caused of Anaconda’s gcc libs was compiled by gcc4.xx. by the system owned gcc version is gcc5.xx…
I’ve hacked this problem with copy
libgomp.so.1.0.0, libquadmath.so.0.0.0, libstdc++.so.6.0.21 these files from :
/usr/lib/x86_64-linux-gnu/
to :
/yourAnacondaPath/anaconda2/pkgs/libgcc-4.8.5-2/lib
/yourAnacondaPath/anaconda2/lib
and then create the links; it works for me

就是把 /usr/lib/x86_64-linux-gnu/目錄下的libgomp.so.1.0.0libquadmath.so.0.0.0, libstdc++.so.6.0.21檔案拷貝到/yourAnacondaPath/anaconda2/pkgs/libgcc-4.8.5-2/lib/yourAnacondaPath/anaconda2/lib

四、安裝Caffe

Ubuntu 16.04 Installation Guide

The following guide includes the how-to instructions for the installation of BVLC/Caffe on Ubuntu 16.04 with Cuda Toolkit 8.0, CUDNN 5.1 library and OpenCV version 2 or 3. (A small record remains from the previous tutorial for Ubuntu 15.10 with the Cuda Toolkit 7.5, but that part will not be updated any further.) This guide also covers the KUbuntu distribution and the related distributions.

1、首先執行以下命令,安裝所需依賴

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install -y build-essential cmake git pkg-config

sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler

sudo apt-get install -y libatlas-base-dev 

sudo apt-get install -y --no-install-recommends libboost-all-dev

sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev

# (Python general)
sudo apt-get install -y python-pip

# (Python 2.7 development files)
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy

# (or, Python 3.5 development files)
sudo apt-get install -y python3-dev
sudo apt-get install -y python3-numpy python3-scipy

# (OpenCV 2.4)
sudo apt-get install -y libopencv-dev

(or, OpenCV 3.1 - see the instructions below)

2、從github上下載caffe

$ git clone https://github.com/BVLC/caffe

3、複製 Makefile.config.example 為 Makefile.config,命令如下:

$ cp Makefile.config.example Makefile.config

4、配置Makefile.config檔案
我的配置如下,注意!需要根據自己的環境來進行配置,不能照抄!
我的python用的是Anaconda,需要自己到官網上下載安裝,所一配置檔案中的Python路勁核相關配置需要改成anaconda的路徑。

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1 # 使用CUDNN

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#   You should not set this flag if you will be reading LMDBs with any
#   possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3 # 如果你安裝的OpenCV 且版本為3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda-8.0 # 這裡要改為cuda-8.0,原來是cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
        -gencode arch=compute_20,code=sm_21 \
        -gencode arch=compute_30,code=sm_30 \
        -gencode arch=compute_35,code=sm_35 \
        -gencode arch=compute_50,code=sm_50 \
        -gencode arch=compute_52,code=sm_52 \
        -gencode arch=compute_60,code=sm_60 \
        -gencode arch=compute_61,code=sm_61 \
        -gencode arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app
MATLAB_DIR := /usr/local/MATLAB/R2014a # 這是我的matlab安裝路徑

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
# PYTHON_INCLUDE := /usr/include/python2.7 \ # 這裡是系統自帶Python,我用的是Anaconda,所以這裡註釋掉
        /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(HOME)/anaconda2 # Anaconda安裝路徑
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ # 取消這裡的註釋
        $(ANACONDA_HOME)/include/python2.7 \
        $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/lib # 註釋掉預設的PYTHON_LIB
PYTHON_LIB := $(ANACONDA_HOME)/lib # 開啟Anaconda的PYTHON_LIB

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
# 可以去掉註釋
# WITH_PYTHON_LAYER := 1 

# Whatever else you find you need goes here.
# 這裡添加了/usr/include/hdf5/serial
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
# 這裡添加了 /usr/lib/x86_64-linux-gnu/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial 
# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @

5、開始編譯caffe
由於我用make方式編譯出現了問題,而用cmake方式編譯成功,所以提供我的cmake方式編譯方法

  • 5.1、進入caffe目錄

(按照官方教程,需要先進入~/caffe/python目錄下執行以下命令來安裝python介面所需的庫)

Python
The main requirements are numpy and boost.python (provided by boost). pandas is useful too and needed for some examples.
You can install the dependencies with

$ for req in $(cat requirements.txt); do pip install $req; done

接下來就可以編譯caffe了

$ cd ~/caffe #你的caffe根目錄
$ mkdir build
$ cd build
$ cmake ..
$ make all -j8 # 這裡要看你的cpu有多少核,比如說我的cpu有4核,但我用-j8或-j12也沒問題
$ make install
$ make test
$ make runtest -j8

你會看到如下過程(不完全)

[email protected]:~/caffe/build$ make runtest -j8
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--   system
--   thread
--   filesystem
--   chrono
--   date_time
--   atomic
-- Found gflags  (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libgflags.so)
-- Found glog    (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libglog.so)
-- Found PROTOBUF Compiler: /usr/bin/protoc
-- Found lmdb    (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/liblmdb.so)
-- Found LevelDB (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libleveldb.so)
-- Found Snappy  (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libsnappy.so)
-- CUDA detected: 8.0
-- Found cuDNN: ver. 5.0.5 found (include: /usr/local/cuda-8.0/include, library: /usr/local/cuda-8.0/lib64/libcudnn.so)
-- Added CUDA NVCC flags for: sm_61
-- OpenCV found (/usr/local/share/OpenCV)
-- Found Atlas (include: /usr/include library: /usr/lib/libatlas.so lapack: /usr/lib/liblapack.so
-- NumPy ver. 1.11.3 found (include: /home/leo/anaconda2/lib/python2.7/site-packages/numpy/core/include)
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--   python
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
-- 
-- ******************* Caffe Configuration Summary *******************
-- General:
--   Version           :   1.0.0
--   Git               :   1.0-11-g91b0928
--   System            :   Linux
--   C++ compiler      :   /usr/bin/c++
--   Release CXX flags :   -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Debug CXX flags   :   -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Build type        :   Release
-- 
--   BUILD_SHARED_LIBS :   ON
--   BUILD_python      :   ON
--   BUILD_matlab      :   OFF
--   BUILD_docs        :   ON
--   CPU_ONLY          :   OFF
--   USE_OPENCV        :   ON
--   USE_LEVELDB       :   ON
--   USE_LMDB          :   ON
--   USE_NCCL          :   OFF
--   ALLOW_LMDB_NOLOCK :   OFF
-- 
-- Dependencies:
--   BLAS              :   Yes (Atlas)
--   Boost             :   Yes (ver. 1.58)
--   glog              :   Yes
--   gflags            :   Yes
--   protobuf          :   Yes (ver. 2.6.1)
--   lmdb              :   Yes (ver. 0.9.17)
--   LevelDB           :   Yes (ver. 1.18)
--   Snappy            :   Yes (ver. 1.1.3)
--   OpenCV            :   Yes (ver. 3.2.0)
--   CUDA              :   Yes (ver. 8.0)
-- 
-- NVIDIA CUDA:
--   Target GPU(s)     :   Auto
--   GPU arch(s)       :   sm_61
--   cuDNN             :   Yes (ver. 5.0.5)
-- 
-- Python:
--   Interpreter       :   /home/leo/anaconda2/bin/python2.7 (ver. 2.7.13)
--   Libraries         :   /home/leo/anaconda2/lib/libpython2.7.so (ver 2.7.13)
--   NumPy             :   /home/leo/anaconda2/lib/python2.7/site-packages/numpy/core/include (ver 1.11.3)
-- 
-- Documentaion:
--   Doxygen           :   No
--   config_file       :   
-- 
-- Install:
--   Install path      :   /home/leo/caffe/build/install
-- 
-- Configuring done

接著我們來編譯caffe的python介面

$ make pycaffe

過程如下:

leo@xiaobai:~/caffe/build$ make pycaffe
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--   system
--   thread
--   filesystem
--   chrono
--   date_time
--   atomic
-- Found gflags  (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libgflags.so)
-- Found glog    (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libglog.so)
-- Found PROTOBUF Compiler: /usr/bin/protoc
-- Found lmdb    (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/liblmdb.so)
-- Found LevelDB (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libleveldb.so)
-- Found Snappy  (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libsnappy.so)
-- CUDA detected: 8.0
-- Found cuDNN: ver. 5.0.5 found (include: /usr/local/cuda-8.0/include, library: /usr/local/cuda-8.0/lib64/libcudnn.so)
-- Added CUDA NVCC flags for: sm_61
-- OpenCV found (/usr/local/share/OpenCV)
-- Found Atlas (include: /usr/include library: /usr/lib/libatlas.so lapack: /usr/lib/liblapack.so
-- NumPy ver. 1.11.3 found (include: /home/leo/anaconda2/lib/python2.7/site-packages/numpy/core/include)
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--   python
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
-- 
-- ******************* Caffe Configuration Summary *******************
-- General:
--   Version           :   1.0.0
--   Git               :   1.0-11-g91b0928
--   System            :   Linux
--   C++ compiler      :   /usr/bin/c++
--   Release CXX flags :   -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Debug CXX flags   :   -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Build type        :   Release
-- 
--   BUILD_SHARED_LIBS :   ON
--   BUILD_python      :   ON
--   BUILD_matlab      :   OFF
--   BUILD_docs        :   ON
--   CPU_ONLY          :   OFF
--   USE_OPENCV        :   ON
--   USE_LEVELDB       :   ON
--   USE_LMDB          :   ON
--   USE_NCCL          :   OFF
--   ALLOW_LMDB_NOLOCK :   OFF
-- 
-- Dependencies:
--   BLAS              :   Yes (Atlas)
--   Boost             :   Yes (ver. 1.58)
--   glog              :   Yes
--   gflags            :   Yes
--   protobuf          :   Yes (ver. 2.6.1)
--   lmdb              :   Yes (ver. 0.9.17)
--   LevelDB           :   Yes (ver. 1.18)
--   Snappy            :   Yes (ver. 1.1.3)
--   OpenCV            :   Yes (ver. 3.2.0)
--   CUDA              :   Yes (ver. 8.0)
-- 
-- NVIDIA CUDA:
--   Target GPU(s)     :   Auto
--   GPU arch(s)       :   sm_61
--   cuDNN             :   Yes (ver. 5.0.5)
-- 
-- Python:
--   Interpreter       :   /home/leo/anaconda2/bin/python2.7 (ver. 2.7.13)
--   Libraries         :   /home/leo/anaconda2/lib/libpython2.7.so (ver 2.7.13)
--   NumPy             :   /home/leo/anaconda2/lib/python2.7/site-packages/numpy/core/include (ver 1.11.3)
-- 
-- Documentaion:
--   Doxygen           :   No
--   config_file       :   
-- 
-- Install:
--   Install path      :   /home/leo/caffe/build/install
-- 
-- Configuring done
CMake Warning (dev) in src/caffe/CMakeLists.txt:
  Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
  interface.  Run "cmake --help-policy CMP0022" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Target "caffe" has an INTERFACE_LINK_LIBRARIES property which differs from
  its LINK_INTERFACE_LIBRARIES properties.

  INTERFACE_LINK_LIBRARIES:

    caffeproto;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_thread.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_chrono.so;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;/usr/lib/x86_64-linux-gnu/libboost_atomic.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libglog.so;/usr/lib/x86_64-linux-gnu/libgflags.so;$<$<NOT:$<CONFIG:DEBUG>>:/usr/lib/x86_64-linux-gnu/libprotobuf.so>;$<$<CONFIG:DEBUG>:/usr/lib/x86_64-linux-gnu/libprotobuf.so>;-lpthread;/home/leo/anaconda2/lib/libhdf5_hl.so;/home/leo/anaconda2/lib/libhdf5.so;/home/leo/anaconda2/lib/libhdf5_hl.so;/home/leo/anaconda2/lib/libhdf5.so;/usr/lib/x86_64-linux-gnu/librt.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/home/leo/anaconda2/lib/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so;/home/leo/anaconda2/lib/libhdf5_hl.so;/home/leo/anaconda2/lib/libhdf5.so;/home/leo/anaconda2/lib/libhdf5_hl.so;/home/leo/anaconda2/lib/libhdf5.so;/usr/lib/x86_64-linux-gnu/librt.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/home/leo/anaconda2/lib/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so;/usr/lib/x86_64-linux-gnu/liblmdb.so;/usr/lib/x86_64-linux-gnu/libleveldb.so;/usr/local/cuda-8.0/lib64/libcudart.so;/usr/local/cuda-8.0/lib64/libcurand.so;/usr/local/cuda-8.0/lib64/libcublas.so;/usr/local/cuda-8.0/lib64/libcudnn.so;opencv_core;opencv_highgui;opencv_imgproc;opencv_imgcodecs;/usr/lib/liblapack.so;/usr/lib/libcblas.so;/usr/lib/libatlas.so;/usr/lib/x86_64-linux-gnu/libboost_python.so

  LINK_INTERFACE_LIBRARIES:

    caffeproto;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_thread.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_chrono.so;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;/usr/lib/x86_64-linux-gnu/libboost_atomic.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libglog.so;/usr/lib/x86_64-linux-gnu/libgflags.so;/usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread;/home/leo/anaconda2/lib/libhdf5_hl.so;/home/leo/anaconda2/lib/libhdf5.so;/home/leo/anaconda2/lib/libhdf5_hl.so;/home/leo/anaconda2/lib/libhdf5.so;/usr/lib/x86_64-linux-gnu/librt.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/home/leo/anaconda2/lib/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so;/home/leo/anaconda2/lib/libhdf5_hl.so;/home/leo/anaconda2/lib/libhdf5.so;/home/leo/anaconda2/lib/libhdf5_hl.so;/home/leo/anaconda2/lib/libhdf5.so;/usr/lib/x86_64-linux-gnu/librt.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/home/leo/anaconda2/lib/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so;/usr/lib/x86_64-linux-gnu/liblmdb.so;/usr/lib/x86_64-linux-gnu/libleveldb.so;/usr/local/cuda-8.0/lib64/libcudart.so;/usr/local/cuda-8.0/lib64/libcurand.so;/usr/local/cuda-8.0/lib64/libcublas.so;/usr/local/cuda-8.0/lib64/libcudnn.so;opencv_core;opencv_highgui;opencv_imgproc;opencv_imgcodecs;/usr/lib/liblapack.so;/usr/lib/libcblas.so;/usr/lib/libatlas.so;/usr/lib/x86_64-linux-gnu/libboost_python.so

This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /home/leo/caffe/build
[  1%] Built target caffeproto
[ 98%] Built target caffe
[100%] Linking CXX shared library ../lib/_caffe.so
Creating symlink /home/leo/caffe/python/caffe/_caffe.so -> /home/leo/caffe/build/lib/_caffe.so
[100%] Built target pycaffe

至此,caffe安裝完成!

**注意**caffe安裝完成後,並不能直接在python環境下匯入caffe模組,像這樣:

[email protected]:~$ python
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import caffe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named caffe
>>> 

需要自己在程式碼中新增~/caffe/python/路徑到環境變數,像這樣:

>>> caffe_root='/home/leo/caffe/'
>>> import os,sys
>>> os.chdir(caffe_root)
>>> sys.path.insert(0,caffe_root+'python')
>>> import caffe
>>> 

或者

To import the caffe Python module after completing the installation, add the module directory to your $PYTHONPATH by `export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH` or the like. You should not import the module in the caffe/python/caffe directory!

編譯matlab介面

請直接看這裡,成功的編譯了matcaffe介面
我遇到了一個錯誤,(原因可能是因為我使用的zsh bash,不是系統自帶的bash,所以會遇到如下錯誤),在此做一個記錄
這裡寫圖片描述
我的解決方案如下:
~/.bashrc~/.zshrc(我使用的是這個)中新增如下語句

export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6

# 以下兩條語句一般在cuda和anaconda安裝完之後自動新增,自己檢查以下是否存在
export LD_LIBRARY_PATH="/usr/local/cuda/lib64":$LD_LIBRARY_PATH
export LD_LIBRARY_PATH="/home/leo/anaconda2/lib":$LD_LIBRARY_PATH

以下是我看到的其他教程,沒有編譯成功,這裡做個記錄。

由於我的ub