前不久,在一臺新機器上安裝了caffe,用於深度學習。其實本人小白一個,在安裝caffe的過程當中走了不少彎路。在遇到問題時,還好有google,能夠得帶、哦一些解答。可是悲劇的是,有一些問題還真是搜不到答案。好比:php
NVCC src/caffe/layers/relu_layer.cu src/caffe/layers/prelu_layer.cu(58): error: a host function call cannot be configured detected during instantiation of "void caffe::PReLULayer::Forward_gpu(const std::vectorcaffe::Blob<Dtype *, std::allocatorcaffe::Blob<Dtype *>> &, const std::vectorcaffe::Blob<Dtype *, std::allocatorcaffe::Blob<Dtype *>> &) [with Dtype=float]" (127): here
當時google一下這個報錯,居然有人和我遇到了一樣的錯誤。簡直開心得不行不行的,但這並無什麼卵用,由於沒有人解答。 固然後來我解決了這個問題,由於以前大部分caffe所依賴的庫都是我手動編譯的,頗有可能問題出在這點上。但具體爲何會有這樣的問題我也不太清楚,其中涉及到各個庫的版本兼容問題,不行,頭疼。望大神指點。html
說了這麼多廢話,也該開始步入正題了。安裝caffe能夠分紅兩步走。python
這樣方便咱們在出現錯誤時可以快速定位問題,解決問題。linux
在寫這一小節前有必要,交代一下linux系統的基本信息。git
$ lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.5 (Final) Release: 6.5 Codename: Final $ uname -r 2.6.32-431.el6.x86_64
安裝caffe的大蝦們,確定已經閱讀過RHEL / Fedora / CentOS Installation章節。github
sudo yum -y groupinstall "Development Tools"
sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
bootstrap
而後就能夠愉快的安裝庫了。vim
sudo yum install protobuf-devel leveldb-devel snappy-devel hdf5-devel
centos
用rpm -qa boost
查看CentOS是否已有boost, 若是有會顯示版本,個人自帶版本是1.44.1, 版本過低,bash
$ wget -O boost_1_55_0.tar.bz2 http://downloads.sourceforge.net/project/boost/boost/1.55.0/boost_1_55_0.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F1.55.0%2F&ts=1385953406&use_mirror=softlayer-ams $ tar jxvf boost_1_55_0.tar.bz2 $ cd boost_1_55_0 $ ./bootstrap.sh $ ./b2 $ sudo ./b2 install
$ sudo yum -y install cmake pkgconfig gtk2-devel python-devel numpy tbb-devel libpng-devel $ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip $ unzip opencv-2.4.10.zip $ cd opencv-2.4.10 $ mkdir build $ cd build $ cmake ../ -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DINSTALL_PYTHON_EXAMPLES=ON $ make -j 2 $ sudo make install
上來就敲下面的命令 sudo yum install gflags-devel glog-devel lmdb-devel
,發現glog-devel找不到。這個時候只能上Github上下一個glog.zip。
$ unzip glog-master.zip $ cd glog-master $ ./configure $ make -j4 $ sudo make install
sudo yum install atlas-devel
$ cp Makefile.config.example Makefile.config # Adjust Makefile.config (for example, if using Anaconda Python) $ make all $ make test $ make runtest
- For cuDNN acceleration, you should uncomment the USE_CUDNN := 1 switch in Makefile.config.
- For CPU-only Caffe, uncomment CPU_ONLY := 1 in Makefile.config.
若無心外caffe.so應該就會誕生了。若make runtest
過程當中,若出現關於protobuf相關的錯誤,應該卸載protobuf-devel,手動下載protobuf源碼,手動編譯。
$ wget -O protobuf.zip https://github.com/google/protobuf/archive/master.zip $ unzip protobuf.zip $ cd protobuf-master $ ./autogen.sh $ make && make check $ sudo make install
這一階段,咱們又分紅兩步走。:( 受不了,真當咱們是小白呀<-_->
$ lspci -nn | grep VGA
blacklist nouveau
$ sudo yum install kernel-devel-2.6.32-431.29.2.el6.x86_64.rpm kernel-devel-2.6.32-431.29.2.el6.x86_64.rpm
而後你就能夠在**/usr/src/kernels/下找到源碼了。還需一步,安裝dkms**,讓它幫助咱們編譯安裝驅動模塊。
$ yum install dkms $ sudo cp -r /usr/src/kernels/2.6.32-431.29.2.el6.x86_64/ /usr/src/kernels/2.6.32-431.el6.x86_64/
$ mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak $ dracut /boot/initramfs-$(uname -r).img $(uname -r)
#vim /etc/inittab
將最後一行「id:5:initdefault:」修改爲「id:3:initdefault:」(不包含引號)。等安裝驅動文件下載完成以後$ reboot
$ chmod +x NVIDIA-Linux-XXXX.run $ ./NVIDIA-Linux-XXXX.run
在一番贊成,肯定以後,驅動就安裝好了。修改**/etc/inittab**,改回圖形界面。
$ reboot
安裝成功,登錄後在系統- 首選項裏能夠看到NVIDIA X Server Settings菜單,能夠查看基本信息及進行一些設置。
$ chmod +x cuda_6.5_XXXX.run $ ./cuda_6.5_XXXX.run
跳過第一項的驅動安裝,後面要麼yes要麼默認就能夠了。注意最後將
/usr/local/cuda/bin加入PATH
/usr/local/cuda/lib64加入**/etc/ld.so.conf**
安裝
而後就是回安裝caffe的流程上了。註釋 CPU_ONLY := 1,再次編譯。當作到這一步時,你的小臉上是否出現了笑容。