centos7.0 caffe安装详解

来源:互联网 发布:java设置线程优先级 编辑:程序博客网 时间:2024/06/07 01:55

caffe的外部依赖项比较多,主要需要安装以下几部分

(1)nvidia 驱动,cuda8.0,cudnn5.1

(2)ProtoBuffer-2.5.0

(3)Boost _1_59_0

(4)Gflags-2.1.1

(5)Glog -0.3.3

(6)OpenBlas-0.2.20

(7)HDF5-1.8.9

(8)Opencv2.4.12

(9)LMDB&Leveldb

(10)Snappy-1.1.2

(11)Python-2.7.8  or higher

(12)ipython,ipython  notebook安装

(13)matlab2016b安装

(14)caffe安装


1nvidia驱动,cuda8.0cudnn5.1

去官网,http://www.nvidia.cn/Download/index.aspx?lang=cn下载驱动,

去官网,https://developer.nvidia.com/cuda-downloads下载cuda-8.0

去官网,https://developer.nvidia.com/rdp/form/cudnn-download-survey下载cudnn-5.1

yum -y  install  gcc  kernel-devel kernel-headers                  #编译驱动需要

./NVIDIA-Linux-x86_64-384.59.run

./cuda_8.0.61_375.26_linux.run

./cuda_8.0.61.2_linux.run                #更新包

tar-xvf cudnn-8.0-linux-x64-v5.1.tgz

cp  cuda/include/*  /usr/local/cuda-8.0/include/

cp  cuda/lib/* /usr/local/ cuda-8.0/lib

#添加环境变量

vim ~/.bashrc

export CUDA_HOME=/usr/local/cuda-8.0

export PATH=/usr/local/cuda-8.0/bin:$PATH

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib:${LD_LIBRARY_PATH}"

source  ~/.bashrc


2ProtoBuffer-2.5.0

官网下载,https://github.com/google/protobuf/releases/tag/v2.5.0

unzip  protobuf-2.5.0.zip

cd  protobuf-2.5.0

./configure

make  -j8

make  install

3Boost _1_59_0

tar  boost_1_59_0.tar.gz

cd  boost_1_59_0

./bootstrap.sh

./b2

cp  -r boost/  /usr/local/include/

cp  -r stage/lib/*  /usr/local/lib

 

可能出现的boost错误:Unicode/ICU support for Boost.Regex?... not found

解决方法:yum  install  bzip2  bzip2-devel  bzip2-libs  python-devel  -y

 

4Gflags-2.1.1

wget https://github.com/schuhschuh/gflags/archive/master.zip 
unzip  master.zip 
cd  gflags-master 
mkdir  build && cd  build 
export  CXXFLAGS=”-fPIC” && cmake.. && make VERBOSE=1 
make && make  install


5Glog -0.3.3

wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz 
tar  -zxvf  glog-0.3.3.tar.gz 
cd  glog-0.3.3 
./configure 
make  -j8&& make  install


6OpenBlas-0.2.20

这里也可以选择使用MKL(收费,学生可以免费申请),atlas,实际加速效果,MKL>OpenBlas>atlas

下载链接:https://sourceforge.net/projects/openblas/

tar  OpenBLAS-0.2.20.tar.gz

make  -j8

make  prefix=/usr/local/openblas install

vim  ~/.bashrc

加入下面的路径,

export   LD_LIBRARY_PATH="/usr/local/openblas/lib:${LD_LIBRARY_PATH}"

source   ~/.bashrc

 

7HDF5-1.8.9

下载链接:https://support.hdfgroup.org/downloads/index.html

tar  hdf5-1.8.9.tar.gz

cd  hdf5-1.8.9

./configure  --prefix=/usr/local/hdf5/

make  -j8

make  install

vim  ~/.bashrc

exportLD_LIBRARY_PATH="/usr/local/hdf5/lib:${LD_LIBRARY_PATH}"

source  ~/.bashrc

 

8Opencv2.4.12

官网下载,http://opencv.org/

unzip  opencv-2.4.12.zip

cd  opencv-2.4.12

mkdir  build

cd  build

cmake..

make  -j8

make  install

 

 

可能出现的opencv错误:error: ‘NppiGraphcutState’ has not been declared      typedef NppStatus (*init_func_t)(NppiSizeoSize, NppiGraphcutState** ppState, Npp8u* pDeviceMem);

解决方法:

vim opencv-2.4.12/modules/gpu/src/graphcuts.cpp

#if !defined (HAVE_CUDA)|| defined (CUDA_DISABLER)修改为:

#if!defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

 

9LMDB&Leveldb

yum install  lmdb-devel

git clone https://github.com/google/leveldb.git

cd leveldb/

make

cp -r  include/leveldb  /usr/local/include

cp libleveldb.so*  /usr/lcoal/lib

cp  out-shared/libleveldb.so*  /usr/local/lib

 

10Snappy-1.1.2

官网下载,http://google.github.io/snappy/

tar  snappy-1.1.2.tar.gz

cd  snappy-1.1.2

./configure

make&&make  install

 

11Python-2.7.8  or higher

默认centos7自带python2.7.5,如果想安装别的版本或者3.2以上的版本,可以参考下面的操作,个人不建议换,里面牵扯的东西太多。

官网下载https://www.python.org/ftp/python/

tar -xvf  Python-2.7.8.tgz

./configure--prefix=/usr/local/python-2.7.8

make  -j8

make  install

mv  /usr/bin/python  python2.7.5

ln -s  /usr/local/python-2.7.8/bin/python   /usr/bin/python

vim /usr/bin/yum

将第一行#!/usr/bin/python改为 #!/usr/bin/python2.7.5,从而保证yum可以使用

vim /usr/libexec/urlgrabber-ext-down

将第一行#!/usr/bin/python改为 #!/usr/bin/python2.7.5,从而保证yum可以使用

 

保证ibus可以使用

vim  /usr/bin/ibus-setup

将最后一行exec /usr/bin/python改为exec /usr/bin/python2.7.5

 

安装numpy

wget http://jaist.dl.sourceforge.NET/project/numpy/NumPy/1.9.0/numpy-1.9.0.zip

unzip numpy-1.9.0.zip

cd numpy-1.9.0

 Python  setup.py  install

reboot


 

12ipythonipython notebook安装

yum install  zlib-devel  openssl-devel  sqlite-devel

wget https://bootstrap.pypa.io/get-pip.py

python get-pip.py

pip install  ipython

yum install  readline-devel

yum install  patch

pip install  readline

pip install  jupyter

 

测试环境:

python               测试python环境

ipython              测试ipython环境

jupyter  notebook --allow-root            测试notebook环境

 

(13)matlab2016b安装

2026b的安装文件如下,包括2个iso镜像,一个lic用于激活,一个rar文件解压后用于替换安装的库文件

 

mount  -o loop  R2016b_glnxa64_dvd1.iso

cd  /mnt

./install

#等到提示需要挂载第二个镜像的时候,执行下面的

mount  -o loop  R2016b_glnxa64_dvd2.iso

#一路next,安装完成后进行激活

cd  /usr/local/MATLAB/R2016b/bin

./activate_matlab.sh

#选择安装文件下的license_standalone.lic进行激活

在windows下解压license_standalone.lic

cp  /matlab2016-linux/R2016b/bin/glnxa64/*  /usr/local/MATLAB/R2016b/bin/glnxa64/

#环境变量设置

vim  ~/.bashrc

export  PATH=/usr/local/MATLAB/R2016b/bin:$PATH

source  ~/.bashrc

#去掉挂载mnt

umount  /mnt

运行matlab进行测试

matlab

 

14caffe安装

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

cd  caffe-master

修改Makefile.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 if necessary)

#       You should not set this flag if you willbe reading LMDBs with any

#       possibility of simultaneous read andwrite

#ALLOW_LMDB_NOLOCK := 1

 

#Uncomment if you're using OpenCV 3

#OPENCV_VERSION := 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

#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 lines for compatibility.

CUDA_ARCH:=        -gencodearch=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_60,code=sm_60 \

                   -gencode arch=compute_61,code=sm_61

#BLAS choice:

#atlas for ATLAS (default)

#mkl for MKL

#open for OpenBlas

BLAS:= open

#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:= /usr/local/openblas/lib

 

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

#MATLAB_DIR := /Applications/MATLAB_R2012b.app

 

#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/site-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 against Python libs)

WITH_PYTHON_LAYER:= 1

 

#Whatever else you find you need goes here.

INCLUDE_DIRS:= $(PYTHON_INCLUDE) /usr/local/include /usr/local/include/boost /usr/local/hdf5/include/usr/local/openblas/include

LIBRARY_DIRS:= $(PYTHON_LIB) /usr/lib64 /usr/local/lib /usr/lib /usr/local/hdf5/lib

 

#If Homebrew is installed at a non standard location (for example your homedirectory) 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 in one of theabove $LIBRARY_DIRS.)

#USE_PKG_CONFIG := 1

 

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?= @

 


 

安装python的所有依赖项:

pip  install -r  / caffe-master/python/requirements.txt

 

make  all -j8

make  pycaaffe

make  matcaffe



 


原创粉丝点击