1.安装依赖包
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
sudo apt-get install git cmake build-essential
2 配置环境变量
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
3 安装caffe
git clone https://github.com/BVLC/caffe.git
sudo cp Makefile.config.example Makefile.config
修改 Makefile.config 文件内容:
以下是需要修改的地方
#USE_CUDNN := 1
修改成:
USE_CUDNN := 1
#OPENCV_VERSION := 3(如果用opencv3)
修改为:
OPENCV_VERSION := 3
anaconda3 环境 python=3.6/3.5 其他不用做任何修改
PYTHON_LIBRARIES := boost_python-py35 python3.5m
这行需要,否则跑caffe程序会报如下错:
ImportError: /home/zhex/caffe/python/caffe/_caffe.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
原因是在: /usr/lib/x86_64-linux-gnu/./libboost_python-py35.so.1.58.0 这个文件的存在 ,
python版本要和这里对应,所以选择python=3.5
注释掉原来的PYTHON_INCLUDE,使用ANACONDA的配置,
注意文件的ANACONDA_HOME := $(HOME)/anaconda3
注释掉# PYTHON_INCLUDE := /usr/include/python2.7
/usr/lib/python2.7/dist-packages/numpy/core/include
启用
ANACONDA_HOME := $(HOME)/.conda/envs/caffe
PYTHON_INCLUDE := $(ANACONDA_HOME)/include
(ANACONDA_HOME)/include/python3.6m
(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include
注释 PYTHON_LIB := /usr/lib
启用PYTHON_LIB := $(ANACONDA_HOME)/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
修改Makefile文件
把
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 -j12
编译成功后测试
sudo make runtest -j12
为使用python环境则需要完成下一步
make pycaffe
测试报错:
recipe for target ‘runtest’ failed
解决办法
Check failed: error == cudaSuccess (38 vs. 0) no CUDA-capable device is detected
原因:是cudn、cudnn出错了,
进入 samples/bin/x86_64/linux/release,
./deviceQuery(运行deviceQuery),可以测试
解决方法:
重装cuda、cudnn
参考:
https://github.com/BVLC/caffe/issues/3109
cd caffe 执行sudo make pycaffe -j12(没有报错)
ModuleNotFoundError: No module named ‘caffe’
配置 .zshrc文件 export PATH=$PATH:/home/zhex/caffe/python 然后source .zshrc
大功告成