深度学习框架Caffe配置:Ubuntu 16.04+CUDA8.0+cuDNN5.1+OpenCV3.1+Anaconda+Octave4.0.3

1.添加软件源,更新系统和软件

      如清华大学源,参见https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

  • sudo gedit /etc/apt/sources.list

  • 添加清华大学软件源

  • sudo apt-get update

  • 使用“软件更新器”更新系统和软件

2.Nvidia驱动

  • sudo add-apt-repository ppa:graphics-drivers/ppa #添加源

  • sudo apt-get update

  • 使用“软件更新器”更新Nvidia驱动,如367(专有)

  • 重启

3.安装CUDA8.0正式版

  • sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb

  • sudo apt-get update

  • sudo apt-get install cuda

  • sudo gedit /etc/profile

    • 添加 export PATH=/usr/local/cuda/bin:$PATH

    • 添加 export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

  • sudo gedit /etc/ld.so.conf.d/cuda.conf

    • 添加/usr/local/cuda/lib64

    • sudo ldconfig

  • 重启

  • 测试是否安装成功\

    • cd /usr/local/cuda/samples/1_Utilities/deviceQuery

    • sudo make #编译该项目

    • ./deviceQuery #若正确,则会显示有效的输出信息

4.安装cuDNN5.1

  • sudo cp ./include/cudnn.h /usr/local/cuda/include/

  • sudo cp ./lib64/lib* /usr/local/cuda/lib64/

  • cd /usr/local/cuda/lib64

  • sudo rm libcudnn.so

  • sudo rm libcudnn.so.5

  • sudo ln -s libcudnn.so.5.1.5 libcudnn.so.5

  • sudo ln -s libcudnn.so.5 libcudnn.so

5.编译安装OpenCV3.1

  • 安装必要的依赖库:

    • sudo apt-get install --assume-yes build-essential cmake cmake-gui checkinstall git libgtk2.0-dev pkg-config python-dev libboost-all-dev  libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip ffmpeg libgtk-3-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev qtbase5-dev yasm
  • 下载OpenCV3.1Unix源码,并解压

  • cd opencv-3.1.0

  • mkdir build

  • cd build

  • cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D  WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" ..

  • make-j8

  • make check -j8

  • sudo make install #安装位置/usr/local

6.安装python相关库(Anaconda务必升级)

  • conda update conda

  • conda install pip

  • python -m pip install --upgrade pip

  • conda update --all

  • cd ./caffe-master/python

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

  • pip install pydot

  • pip install pyzmq tornado jinja2 jsonschema

  • pip install jupyter

7.安装JavaRuntime Environment

  • sudo add-apt-repository ppa:webupd8team/java

  • sudo apt-get update

  • sudo apt-get install oracle-java7-installer

  • sudo apt-get install oracle-java7-set-default

8.编译安装octave4.0.3

  • sudo add-apt-repository ppa:octave/stable

  • sudo apt-get update #用于安装octave依赖

  • 下载octave源码,网址ftp://ftp.gnu.org/gnu/octave/

  • tar zxvf octave-4.0.3.tar.gz

  • cd octave-4.0.3

  • sudo apt-get build-dep octave #安装octave依赖

  • sudo apt-get install libportaudio-dev libqt4-opengl-dev

  • ./configure

  • make -j8

  • make check -j8

  • sudo make install

9.编译安装protobuf

  • 查看pip安装的protobuf版本

    • pip list#pip安装列表

    • 查看protobuf版本,假设为protobuf(3.1.0)

  • 查看是否安装有旧版本的protobuf,若有则需要卸载旧版本

  • 下载相应版本ver3.1protobuf代码

  • tar zxvf protobuf-3.1.0.tar.gz

  • cd protobuf-3.1.0

  • sudo apt-get install autoconf automake libtool curl

  • ./autogen.sh

  • ./configure -prefix=/usr

  • make -j8

  • make check -j8

  • sudo make install

  • sudo ldconfig

10.编译caffe/pycaffe/octave

  • sudo apt-get install -y libleveldb-dev libsnappy-dev libhdf5-serial-dev

  • 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

  • 再次确认protoc版本为3.1.0

    *若不是则需卸载libprotobuf-devprotobuf-compiler,并重新安装protobuf3.1.0

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

cd caffe

cp Makefile.config.example Makefile.config

gedit Makefile.config #详见附录

gedit CmakeLists.txt #打开MATLAB/Octave编译选项

mkdir build

cd build

cmake-gui.. #cmake-gui中配置相应的选项

  • 确认编译方式为Release

  • 确认 libhdf5.so 的位置(文件夹)

  • 确认octave 混合编译器的位置(文件)

  • 点击configure

  • 点击 generate

make all -j8

make test

make runtest -j8

make pycaffe #编译完成后将./caffe/python加入到PYTHONPATH环境变量

make octave #编译完成后配置octave

附件1CaffeMakefile.config文件参考配置选项

##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


#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 ifnecessary)

# Youshould not set this flag if you will be reading LMDBs with any

# possibilityof simultaneous read and write

#ALLOW_LMDB_NOLOCK := 1


#Uncomment if you're using OpenCV 3

OPENCV_VERSION:= 3


#To customize your choice of compiler, uncomment and set thefollowing.

#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

#On Ubuntu 14.04, if cuda tools are installed via

#"sudo apt-get install nvidia-cuda-toolkit" then use thisinstead:

#CUDA_DIR := /usr


#CUDA architecture setting: going with all of them.

#For CUDA < 6.0, comment the *_50 lines for compatibility.

CUDA_ARCH:= -gencode arch=compute_30,code=sm_30 \

-gencodearch=compute_35,code=sm_35 \

-gencodearch=compute_50,code=sm_50 \

-gencodearch=compute_52,code=sm_52 \

-gencodearch=compute_52,code=compute_52


#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 standardsearch 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 := /home/zq/programfiles/MATLAB/R2016b


#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 \

#/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)/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 := $(ANACONDA_HOME)/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 againstPython libs)

WITH_PYTHON_LAYER:= 1


#Whatever else you find you need goes here.

#HDF5_DIRS:=/usr/local/hdf5-1.8.17

INCLUDE_DIRS:= $(PYTHON_INCLUDE) /usr/include /usr/local/include /usr/lib/usr/include/hdf5 /usr/include/hdf5/serial/usr/lib/x86_64-linux-gnu/hdf5/serial/include

LIBRARY_DIRS:= $(PYTHON_LIB) /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/hdf5/serial/lib/usr/lib/x86_64-linux-gnu/hdf5/serial


#If Homebrew is installed at a non standard location (for example yourhome directory) and you use it for general dependencies

#INCLUDE_DIRS += $(shell brew --prefix)/include

#LIBRARY_DIRS += $(shell brew --prefix)/lib


#Uncomment to use `pkg-config` to specify OpenCV library paths.

#(Usually not necessary -- OpenCV libraries are normally installed inone 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 tohttps://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?= @

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