参考文章https://blog.csdn.net/xuzhongxiong/article/details/52717285
安装依赖库
sudo add-apt-repository universe
sudo apt-get update -y
sudo apt-get install cmake -y
# General Dependencies
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev \
libhdf5-serial-dev protobuf-compiler -y
sudo apt-get install --no-install-recommends libboost-all-dev -y
# BLAS
sudo apt-get install libatlas-base-dev -y
# Remaining Dependencies
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev -y
sudo apt-get install python-dev python-numpy –y
sudo apt-get install -y python-pip
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy
编译 Caffe,cd到要安装caffe的位置
(1)将终端cd到要安装caffe的位置。
(2)从github上获取caffe:
git clone https://github.com/BVLC/caffe.git
注意:若没有安装Git,需要先安装Git:
sudo apt-get install git
(3)因为make指令只能make
Makefile.config文件,而Makefile.config.example是caffe给出的makefile例子,因此,首先将Makefile.config.example的内容复制到Makefile.config:
sudo cp Makefile.config.example Makefile.config
(4)打开并修改配置文件:
sudogedit Makefile.config#打开Makefile.config文件
根据个人情况修改文件:
a.若使用cudnn,则
将#USE_CUDNN := 1修改成: USE_CUDNN :=1
b.若使用的opencv版本是3的,则
将#OPENCV_VERSION := 3 修改为: OPENCV_VERSION :=3
c.若要使用python来编写layer,则
将#WITH_PYTHON_LAYER := 1 修改为 WITH_PYTHON_LAYER :=1
d.重要的一项 :
将# Whatever else you find you need goes here.下面的
INCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/includeLIBRARY_DIRS:=$(PYTHON_LIB) /usr/local/lib /usr/lib 修改为: INCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serialLIBRARY_DIRS:=$(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/hdf5/serial
这是因为ubuntu16.04的文件包含位置发生了变化,尤其是需要用到的hdf5的位置,所以需要更改这一路径.
(5)修改makefile文件
打开makefile文件,做如下修改:
将:NVCCFLAGS+=-ccbin=$(CXX)-Xcompiler-fPIC$(COMMON_FLAGS)替换为:NVCCFLAGS+=-D_FORCE_INLINES-ccbin=$(CXX)-Xcompiler-fPIC$(COMMON_FLAGS)
(6)编辑/usr/local/cuda/include/host_config.h
将其中的第115行注释掉:
将#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!改为//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
(7)#注意自己CUDA的版本号!
sudocp/usr/local/cuda-8.0/lib64/libcudart.so.8.0/usr/local/lib/libcudart.so.8.0&& sudo ldconfig
sudocp/usr/local/cuda-8.0/lib64/libcublas.so.8.0/usr/local/lib/libcublas.so.8.0&& sudo ldconfig
sudocp/usr/local/cuda-8.0/lib64/libcurand.so.8.0/usr/local/lib/libcurand.so.8.0&& sudo ldconfig
(7)编译
sudo make all -j8根据自己电脑配置决定
sudo make runtest
sudo make pycaffe