LINUX 编译 caffe

Ubuntu16.04 + cuda9.0 + cudnn7 于服务器上配置,参考前请对照自身需要。

安装依赖包

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
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

创建Makefile.config文件

cp Makefile.config.example Makefile.config

修改Makefile.config

1.第一步

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.因为是cuda9,所以把
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
改为
CUDA_ARCH = -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

2.第二步

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/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

否则会报错:

/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
Makefile:582: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1

3.NUMPY用pip安装

编译pycaffe报错

make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp: 10 : 31 : fatal error : numpy/arrayobject.h: No such file or directory
compilation terminated.
Makefile: 518 : recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1

用pip安装numpy

sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy

之后,把

PYTHON_INCLUDE = /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include

修改为

PYTHON_INCLUDE = /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include \
/usr/local/lib/python2.7/dist -packages/numpy/core/include

修改Makefile文件

将NVCCFLAGS += -ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)

改为NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

将LIBRARIES += glog gflags protobuf boost_system boost_filesystem m

改为LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

编译

make all -j8
make test -j8
make runtest -j8
make pycaffe
make matcaffe

 

你可能感兴趣的:(LINUX 编译 caffe)