本文基于深度学习基础平台环境,搭建深度学习基础平台请参考深度学习:Ubuntu16.04+双TitanX+CUDA8.0+CUDNN5.1。
安装Caffe
- 下载caffe安装包
https://github.com/BVLC/caffe - 安装库及各种依赖
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev
# (Python general)
sudo apt-get install -y python-pip
# (Python 2.7 development files)
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy
- 在
caffe-master/python
文件夹内,使用root执行依赖项的检查与安装:
sudo su
cd caffe-master/python
for req in $(cat requirements.txt); do pip install $req; done
- hdf5库
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
- 修改Makfile.config
USE_CUDNN := 1 (可选)
USE_OPENCV := 1 (可选)
OPENCV_VERSION := 3 (如果打开了USE_OPENCV,而且opencv版本为3时)
PYTHON_INCLUDE := /usr/include/python2.7 /usr/lib/python2.7/dist-packages/numpy/core/include
WITH_PYTHON_LAYER := 1
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/local/share/OpenCV/3rdparty/lib
- 修改Makfile
将下面这一行:
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
替换为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
当使用opencv3 出现错误 imread,imencode,imdecode
或者 VideoCapture
时,编辑Makefile
:
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system boost_filesystem hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio
- 编译
make all -j6 -数字6为并行编译进程数目,一般设置为CPU物理核心数,可以使用 $(nproc) 来替换或echo $(nproc) 来查看CPU物理核心数
make test -j6
make runtest -j6
make pycaffe -此时应该已经编译完成,再次执行以确认
如果出现
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
则删除Makefile.config
中的:
-gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
参考
https://github.com/BVLC/caffe/wiki/GeForce-GTX-1080,---CUDA-8.0,---Ubuntu-16.04,---Caffe
https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide
https://github.com/BVLC/caffe/wiki/OpenCV-3.1-Installation-Guide-on-Ubuntu-16.04
http://gwang-cv.github.io/2016/10/21/Ubuntu16.04+Titan%20X+CUDA8.0+cudnn5/
网友评论