[转]CentOS6.5虚拟机安装Caffe大致记录

 CentOS6.5虚拟机安装Caffe大致记录
原文地址:http://blog.csdn.net/thystar/article/details/51567447
 

话说CentOS装caffe也真心是个坑,装了两天,Python因为应用中不用,谢天谢地,这里说下安装过程,不过,不同机器可能遇到的问题不一样。这里参考了一些博客:http://my.oschina.net/speedinghzl/blog/464142?fromerr=PMKemZsc 幸亏OpenCV按照这个上面的装的,不然不知道又有多少坑,还有http://caffe.berkeleyvision.org/install_yum.html官网的文档,依赖库尽量按着这个来。下面说一下完整过程

1. 首先,我是在虚拟机上安装的,虚拟机的安装过程这里不说了。安装完centos6.5后,要看看你的网络配置,这里可以参考:

http://jingyan.baidu.com/article/d5c4b52bc73700da560dc535.html

我是自动获取IP的。配置完成后需要重启服务

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. ifconfig -a  
  2. vi /etc/sysconfig/network-scripts/ifcfg-eth0  

配置动态IP。
通过修改ifcfg-eth0内容配置IP地址;按键盘字母【a】进入其VI编辑模式。
◆将ONBOOT=no改为ONBOOT=yes 激活网卡。
◆将NM_CONTROLLED=yes改为NM_CONTROLLED=no。
修改完成后按【Esc】键退出编辑模式,输入":wq"敲回车保存修改结果。
重启网络服务,查看动态IP配置结果。
输入命令:service network restart (重启网络服务)
输入命令:ifconfig -a (查看网络配置)

我只做到这一步。

2. 安装wget

sudo yum -y install wget

3. 修改yum源,我这里用的是163的源

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. cd /etc/yum.repos.d/  
  2. wget http://mirrors.163.com/.help/CentOS6-Base-163.repo  
  3. mv CentOS-Base.repo CentOS-Base.repo.bak  
  4. mv CentOS6-Base-163.repo CentOS-Base.repo  

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. yum makecache  
  2. yum update  

4. 基本库安装:

sudo yum -y groupinstall "Development Tools"
添加EPEL依赖:
[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm  
这个可以参考:
http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/

一些依赖库:

sudo yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
这里,boost 和opencv版本太低需要手动安装

5. boost安装

wget http://www.mirrorservice.org/sites/dl.sourceforge.net/pub/sourceforge/b/bo/boost/boost/1.55.0/boost_1_55_0.tar.bz2
[html] view plain copy
 
在CODE上查看代码片派生到我的代码片
  1. 源博客中的链接地址一直出错,所以在网上找了上面的地址  
  2. $ tar jxvf  boost_1_55_0.tar.bz2  
  3. $ cd boost_1_55_0  
  4. $ ./bootstrap.sh  
  5. $ ./b2  
  6. $ sudo ./b2 install  


6 opencv安装

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. $ sudo yum -y install cmake pkgconfig gtk2-devel python-devel numpy tbb-devel libpng-devel   
  2. $ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip   
  3. $ unzip opencv-2.4.10.zip   
  4. $ cd opencv-2.4.10   
  5. $ mkdir build   
  6. $ cd build   
  7. $ cmake ../ -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DINSTALL_PYTHON_EXAMPLES=ON   
  8. $ make  
  9. $ sudo make install  

7 其他依赖

sudo yum install gflags-devel glog-devel lmdb-devel
这里面,估计只有lmdb不需要手动装

其他都要重装一遍

一个个来

glog

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. wget https://github.com/google/glog/archive/master.zip  
  2. $ unzip master.zip   
  3. $ cd glog-master   
  4. $ ./configure   
  5. $ make    
  6. $ sudo make install  

gflags 

因为我在编译过程中发现直接安装的gflags报错了, 出现https://github.com/BVLC/caffe/issues/3870 类似的问题,但是上面提出的办法会有其他问题,因此手动下了一个,重新装了一下。

[html] view plain copy
 
在CODE上查看代码片派生到我的代码片
  1. wget https://github.com/schuhschuh/gflags/archive/master.zip   
  2. unzip master.zip  
  3. cd gflags-master  
  4. mkdir build && cd build  
  5. cmake .. && make VERBOSE=1  
  6. make && make install  

还要安装 blas 

sudo yum install atlas-devel


这里需要注意的是,在caffe的Makefile.config中需要加入altas的路径,因为我在这里遇到了路径找不到的错误,配置之后就没有了:

8 编译caffe, 

caffe可以直接用Git下载

make all

make test

在make test过程中,遇到类似

http://superuser.com/questions/171836/what-am-i-doing-wrong-when-a-linux-app-doesnt-find-an-so-file

的问题,最后添加了变量LD_LIBRARY_PATH = /usr/local/lib解决

make runtest

在make runtest中,一般只要出问题都是protobuf没有装,
这也是整死我了,一开始下了个2.5.0的,死活不行,后来换了2.6.0的OK了,真心不懂。
[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. wget https://github.com/google/protobuf/releases/download/v2.6.0/protobuf-2.6.0.zip  
  2. ./configure --prefix=/usr/local/protobuf  
  3. make   
  4. make check  
  5. make install  
添加路径:
[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. export PATH=$PATH:/usr/local/protobuf/bin  
  2. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib  
可能有些jar编译的错误,不用管
make clean后重新编译caffe, 居然通过了,当场泪崩。

参考资料:

http://my.oschina.NET/speedinghzl/blog/464142?fromerr=PMKemZsc

http://caffe.berkeleyvision.org/install_yum.html

https://github.com/google/protobuf/issues/51

原文地址:https://www.cnblogs.com/Crysaty/p/6282347.html