前不久,在一台新机器上安装了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,再次编译。当作到这一步时,你的小脸上是否出现了笑容。