centos安装:
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安装
(1)nvidia驱动,cuda8.0,cudnn5.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
(2)ProtoBuffer-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
(3)Boost _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
(4)Gflags-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
(5)Glog -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
(6)OpenBlas-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
(7)HDF5-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
(8)Opencv2.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)
(9)LMDB&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
(10)Snappy-1.1.2
官网下载,http://google.github.io/snappy/
tar snappy-1.1.2.tar.gz
cd snappy-1.1.2
./configure
make&&make install
(11)Python-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
(12)ipython,ipython 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
(14)caffe安装
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
ubuntu 安装
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake git pkg-config libgtk2.0-dev
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install libatlas-base-dev
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
(Python2 general)
sudo apt-get install python-pip
(Python3 general)
sudo apt-get install python3-pip
(Python 2.7 development files)
sudo apt-get install python-dev
sudo apt-get install python-numpy python-scipy
(or, Python 3.5 development files)
sudo apt-get install python3-dev
sudo apt-get install python3-numpy python3-scipy
(OpenCV 2.4)
sudo apt-get install libopencv-dev
(OpenCV 3.1.0)
官网下载源码,https://opencv.org/releases/page/3/
tar -xzvf opencv-3.1.0.tar.gz
cd opencv-3.1.0/
cd ..
mkdir build
cd build
cmake ../opencv-3.1.0 -DWITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr/local
make
make install
ps,如果opecnv报错,Unable to stop the stream: Inappropriate ioctl for device,不能读取视频流,
解决方法,
sudo apt-get install ffmpeg libavcodec-dev libavformat-dev libavdevice-dev
然后重新编译opencv
cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.10.0.2 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so
git clone https://github.com/BVLC/caffe.git
cd cafferoot/python
pip install -r requirements.txt
(python2)
apt-get install python-opencv
pip install protobuf==2.6.1
(python3)
apt-get install python3-opencv
pip install protobuf==3.2.0
pip install protobuf-py3
如果使用opencv3,需要修改Makefile,200行,增加opencv_videoio
ifeq ($(USE_OPENCV), 1)
LIBRARIES += opencv_core opencv_highgui opencv_imgproc
ifeq ($(OPENCV_VERSION), 3)
LIBRARIES += opencv_imgcodecs opencv_videoio
endif
endif
最后,
make all -j8
make pycaffe
export PYTHONPATH=/path/to/caffe-master/python:$PYTHONPATH
Makefile.config,本人配置如下,python3+cpu+opencv3.1.0
## 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
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 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
# 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 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 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
# 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 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/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib64 /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 ?= @