深度學習:Ubuntu16.04+雙TitanX+CUDA8.0+CUDNN5.1+Caffe

本文基于深度學習基礎平臺環(huán)境,搭建深度學習基礎平臺請參考深度學習:Ubuntu16.04+雙TitanX+CUDA8.0+CUDNN5.1

安裝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文件夾內(nèi),使用root執(zhí)行依賴項的檢查與安裝:
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 出現(xiàn)錯誤 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  -數(shù)字6為并行編譯進程數(shù)目,一般設置為CPU物理核心數(shù),可以使用 $(nproc) 來替換或echo $(nproc) 來查看CPU物理核心數(shù)
make test -j6
make runtest -j6
make pycaffe  -此時應該已經(jīng)編譯完成,再次執(zhí)行以確認

如果出現(xiàn)

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/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容