安装依赖
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev
sudo apt-get install 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
解压
wget https://github.com/BVLC/caffe
tar -vxzf 1.0.tar.gz
复制makefile.conf文件
sudo gedit Makefile.config
将第5行注释去掉
USE_CUDNN := 1
将第21行注释
OPENCV_VERSION := 3
将第37和38行删除(cuda8.0后不再支持),也就是删
除-gencode arch=compute_20,code=sm_20 \和-gencode arch=compute_25,code=sm_25 \两个配置。
# 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_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
修改第51行
BLAS := open
修改python路径信息
# 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/python3.5 \
/usr/lib/python3/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/dist-packages/numpy/core/include
将# 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/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/hdf5/serial
若要使用python来编写layer,则去掉下面注释
#WITH_PYTHON_LAYER := 1 >>>> WITH_PYTHON_LAYER := 1
修改Makefile文件
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
425行替换成
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial
181行替换成
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
修改boost
208行
PYTHON_LIBRARIES := boost_python3 python3.5m
cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.10.1.0 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so
sudo ln -s libboost_python-py36.so libboost_python3.so
sudo ln -s libboost_python-py36.a libboost_python3.a
编译
sudo make all –j16
sudo make test –j16
sudo make runtest –j16
编译pycaffe
在caffe根目录的python文件夹下,有一个requirements.txt的清单文件,上面列出了需要的依赖库,按照这个清单安装
cd ./python for req in $(cat requirements.txt); do pip3 install $req; done
安装完成以后,再次回到caffe根目录执行
sudo pip3 install -r python/requirements.txt
编译pycaffe接口
sudo make pycaffe -j16
配置环境变量,以便python调用
sudo gedit ~/.bashrc
caffe python 路径
export PYTHONPATH=/home/ai/caffe/python:$PYTHONPATH
source ~/.bashrc
测试
python
>>> import caffe
错误1
NesterovSolverTest/3.TestNesterovLeastSquaresUpdateLROneHundredth
F1229 12:46:22.315335 5058 math_functions.cu:42] Check failed: status == CUBLAS_STATUS_SUCCESS (13 vs. 0) CUBLAS_STATUS_EXECUTION_FAILED
sudo rm -rf .nv/