首先安装依赖项:
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
make all -j12 #开启12个线程编译
make test -j12
make runtest -j12
1.使用opencv3时,遇到libcaffe.so对videoCapture未引用,一大堆在LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_hl hdf5后面加上opencv_...之类的库,其实需要将Makefile.config中的OPENCVVERSIOIN:=3前的#号去掉。这句话大概在文件第20行左右。
当然了,如果你用的是opencv2 就没有这个必要。
2.hdf5 文件问题
将Makefile.config中的
大概在文件90行左右。
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
替换为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/i386-linux-gnu/hdf5/serial /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
一般都会有效。
3.//home/idc/anaconda2/lib/libpng16.so.16: undefined reference to `inflateValidate@ZLIB_1.2.9'之类的问题
网上很多的解决方案为:在Makefile.config增加
LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda2/lib
注意anaconda的版本要对应
关于zlib,其实是要安装的,网上的方法大多不行
首先下载对应的zlib版本 https://sourceforge.net/projects/libpng/files/zlib/1.2.9/zlib-1.2.9.tar.gz/download
tar zxf zlib-1.2.9.tar.gz
cd zlib-1.2.9
sudo -s
./configure; make; make install
cd /lib/x86_64-linux-gnu
ln -s -f /usr/local/lib/libz.so.1.2.9/lib libz.so.1
4哈哈
4.编译Matlab接口
首先要在Makefile.config中指定Matlab的路径
去掉MATLAB_DIR前面的这句话大概在文件第60行左右。
MATLAB_DIR := /usr/local/MATLAB/R2014a
然后使用命令 make matcaffe 进行编译,过程中如果gcc版本不正确可以忽略。
可能出现的问题为:
Makefile:517: recipe for target 'matlab/+caffe/private/caffe_.mexa64' failed
make: *** [matlab/+caffe/private/caffe_.mexa64] Error 255
按照网上的解决方案:在Makefile文件中加入,注意是Makefile文件不是Makefile.config文件!
CXXFLAGS += -std=c++11
然后,make clean
make all -j12 后面的-j 是开启多少个线程,建议写上数字,否则机器可能会卡死。
重新编译,大多情况下都可以解决。
使用 make mattest 测试
可能出现
'/home/shiyanshi/DaiHailong/caffe-master/matlab/+caffe/private/caffe_.mexa64':
libprotobuf.so.15: cannot open shared object file: No such file or directory 问题
首先在计算机全局搜索对应的文件,我的是在/home/shiyanshi/anaconda2/lib文件夹下,然后建立共享链接
sudo cp /home/shiyanshi/anaconda2/lib/libprotobuf.so.15 /usr/lib/x86_64-linux-gnu
sudo ldconfig #使更改生效
5.编译python接口
make pycaffe -j12
即可
让后,将pycaffe加到python的路径中,如下所示
sudo gedit ~/.bashrc
在下面加入如下:export PYTHONPATH="/home/shiyanshi/DaiHailong/caffe-master/python":$PYTHONPATH
使改动生效
source ~/.bashrc
6.还有库缺失的问题,安装caffe之前一定要按照官网将所需依赖项装好,ubuntu 17以后,继续apt-get install 命令即可安装,大大简化了安装流程。还有好多其他的问题,未完待续。。。
fatal error: google/protobuf/arena.h: 没有那个文件或目录
protobuf版本不兼容,降低或升高protobuf版本
https://github.com/google/protobuf/releases/tag/v2.5.0
到github中下载对应版本安装,我遇到的是protobuf 是2.6,降到2.5解决了问题
安装protobuf
cd protobuf-2.5.0
./configure
make
make check
make installsudo ldconfig
fatal error: pyconfig.h: 没有那个文件或目录
解决方案
export CPLUS_INCLUDE_PATH=/usr/include/python2.7
matlab caffe遇到的问题
最后将我的Makefile.config 文件粘在这里,我使用的环境为cuda8,cudnn6,未使用cudnn编译,opencv为3.4.1,python为anaconda2,matlab为 r2014a
## 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 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 lines after *_35 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_61,code=sm_61
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
# BLAS := atlas
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 := /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/R2014a
# 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)/anaconda2
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
#LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/i386-linux-gnu/hdf5/serial /usr/lib/x86_64-linux-gnu /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
# 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
LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda2/lib
# 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 ?= @