centos 6.5安装caffe(cpu模式)

前端之家收集整理的这篇文章主要介绍了centos 6.5安装caffe(cpu模式)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

caffe安装的命令比较简单,但是安装过程坑比较多。

1.首先先鉴定机器是什么显卡:

@H_502_5@$ lspci |grep VGA 0b:00.0 VGA compatible controller: Matrox Electronics Systems Ltd. G200eR2

机器悲剧的没有NVIDIA 的显卡。

2.安装依赖库

@H_502_5@$sudo yum install atlas-devel protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel gflags-devel glog-devel lmdb-devel

这些都是必须的,至于作用不一一解释,有兴趣的可以一一查找,其中lmdb是caffe中使用的数据库,是键/值对嵌入式数据库管理系统编程库的一种。
上述基本都能直接找到,若找不到,请直接下载安装包编译安装。

3.安装cuda

wget http://developer.download.nvidia.com/compute/cuda/repos/rhel6/x86_64/cuda-repo-rhel6-6.5-14.x86_64.rpm
rpm -ivh cuda-repo-rhel6-6.5-14.x86_64.rpm
yum install cuda-6-5

4.安装boost

如果上面通过yum安装了boost-devel,需要按照如下步骤确认版本是否正确。

  1. 用rpm -qa boost 查看CentOS是否已有boost,如果有会显示版本,我的自带版本是1.44.1,版本太低,
  2. 如果自带低版本boost,卸载它,yum remove boost 或者 rpm -e boost (很奇怪,有时第一条命令可以,有时第二条命令可以),再用rpm -qa boost不会输出任何信息,说明卸载成功.

通过源码安装boost

@H_502_5@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 ./b2 install

4.安装opencv

如果上面通过yum安装opencv-devel失败,可以使用如下方式安装。

Caffe作者默认你已经配置好了OpenCV环境,文档里没有说这一步。好在有人已经写好了配置OpenCV的脚本,https://github.com/jayrambhia/Install-OpenCV,直接拿来用。

@H_502_5@git clone https://github.com/jayrambhia/Install-OpenCV cd Install-OpenCV/RedHat sudo ./opencv_latest.sh

如果脚本运行失败,则详细阅读RetHat/opencv_install.sh的代码,然后手工敲入命令进行安装。

@H_502_5@mkdir OpenCV cd OpenCV wget -O opencv-2.4.7.tar.gz http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.7/opencv-2.4.7.tar.gz/download tar -zxf opencv-2.4.7.tar.gz cd opencv-2.4.7 sed -i '/string(MD5/d' cmake/cl2cpp.cmake mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. make -j 4 sudo make install sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' sudo ldconfig

5.安装pip

@H_502_5@curl -O https://bootstrap.pypa.io/get-pip.py # 得到一个get-pip.py python get-pip.py

6.安装protobuf:

如果上面通过yum安装protobuf-devel失败,可以使用如下方式安装。

@H_502_5@tar -xvf protobuf-2.5.0.tar.gz cd protobuf-2.5.0 ./configure make make check make install export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

继续安装protobuf的python模块(如果不用python,可跳过这一步)

@H_502_5@cd ./python python setup.py build python setup.py test python setup.py install

7.编译安装caffe其他依赖包

如果上面通过yum安装gflags-devel glog-devel lmdb-devel失败,可以使用如下方式安装。

7.1 glog

https://github.com/google/glog/releases下载glog-0.3.3的源码。然后用下面的步骤安装:

@H_502_5@tar zxvf glog-0.3.3.tar.gz cd glog-0.3.3 ./configure make && make install

7.2 gflags

@H_502_5@wget https://github.com/schuhschuh/gflags/archive/master.zip unzip gflags-master.zip cd gflags-master mkdir build && cd build export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1 make && make install

7.3 lmdb

@H_502_5@git clone git://gitorIoUs.org/mdb/mdb.git tar –xf lmdb.tar cd mdb/libraries/liblmdb make && make install #若提示man1错误,手动建立一个 mkdir -p /usr/local/man/man1

8.安装caffe数学库(ATLAS,MKL,OpenBLAS)

这也是caffe的坑之一(关系到后面的配置文件),linux一般来说自带了atlas,你可以选择不安装,或者说可以安装英特尔提供的数学库MKL(链接),这是收费产品,为什么要安装呢,据说可以加速。
这边我没有选择atlas,因为配置没配置好,编译总报错。网上没找到原因,直接选择了OpenBLAS。可以使用如下命令安装:

8.1 安装依赖

@H_502_5@wget http://sourceforge.net/projects/slurm-roll/files/addons/6.1.1/rpms/pb-binutils224-2.24-1.x86_64.rpm sudo yum localinstall pb-binutils224-2.24-1.x86_64.rpm

8.2 安装openblas

@H_502_5@git clone https://github.com/xianyi/OpenBLAS.git cd OpenBLAS make sudo make install

9.安装caffe

9.1 下载源码

@H_502_5@git clone https://github.com/BVLC/caffe.git cd caffe

9.2 解决python依赖

@H_502_5@pip install 'six>=1.3' easy_install -U distribute pip install PIL --allow-external PIL --allow-unverified PIL @H_502_5@cd caffe/python for i in $(cat requirements.txt); do pip install $i; done

9.3 修改配置文件

@H_502_5@cp Makefile.config.example Makefile.config vim Makefile.config

主要修改如下几项:

@H_502_5@cpu_ONLY := 1 CUDA_DIR := /usr/local/cuda BLAS := open PYTHON_INCLUDE := /usr/local/include/python2.7/ \ /usr/local/lib/python2.7/site-packages/numpy/core/include/

注意:python include要设置成你自己的python include路径。要不然会提示一堆boost_python错误

9.4 编译

@H_502_5@make all

如果出现问题:

@H_502_5@fatal error: caffe/proto/caffe.pb.h: No such file or directory #include "caffe/proto/caffe.pb.h"

使用如下方式解决

@H_502_5@# 先进入你caffe源码的根目录,然后执行 protoc src/caffe/proto/caffe.proto --cpp_out=. mkdir include/caffe/proto mv src/caffe/proto/caffe.pb.h include/caffe/proto

10.运行mnist例子

切换到源码根目录:

@H_502_5@cd caffe

下载数据:

@H_502_5@/data/mnist/get_mnist.sh examples/mnist/create_mnist.sh

切换到cpu模式:
修改lenet_solver.prototxt文件最后一行,将GPU改为cpu

@H_502_5@vim examples/mnist/lenet_solver.prototxt

开始训练:

@H_502_5@examples/mnist/train_lenet.sh

正常的话,会有类似如下输出

@H_502_5@I1011 20:15:45.343098 46351 caffe.cpp:210] Use cpu. I1011 20:15:45.343608 46351 solver.cpp:48] Initializing solver from parameters: .... I1011 20:33:19.357574 46351 sgd_solver.cpp:106] Iteration 9900,lr = 0.00596843 I1011 20:33:28.817215 46351 solver.cpp:454] Snapshotting to binary proto file examples/mnist/lenet_iter_10000.caffemodel I1011 20:33:28.833461 46351 sgd_solver.cpp:273] Snapshotting solver state to binary proto file examples/mnist/lenet_iter_10000.solverstate I1011 20:33:28.879218 46351 solver.cpp:317] Iteration 10000,loss = 0.00138363 I1011 20:33:28.879259 46351 solver.cpp:337] Iteration 10000,Testing net (#0) I1011 20:33:34.642091 46351 solver.cpp:404] Test net output #0: accuracy = 0.9913 I1011 20:33:34.642338 46351 solver.cpp:404] Test net output #1: loss = 0.0289887 (* 1 = 0.0289887 loss) I1011 20:33:34.642355 46351 solver.cpp:322] Optimization Done. I1011 20:33:34.642367 46351 caffe.cpp:254] Optimization Done.

其他一些可能遇到的错误
http://coldmooon.github.io/2015/07/09/caffe/

参考文章
http://www.ttlsa.com/linux/install-caffe-on-centos6-5/
http://blog.csdn.net/forest_world/article/details/51371560
http://xinghao.me/2015/12/11/2015-12-11-caffe-hdf5/
https://github.com/BVLC/caffe/issues/1463
http://cn.soulmachine.me/2014-04-03-caffe-installation/
https://www.hongweipeng.com/index.php/archives/459/
http://www.lai18.com/content/7964440.html
https://github.com/hqli/caffe_install/tree/master/centos/cpu
http://www.jb51.cc/article/p-hvcsxsvx-bho.html
http://www.cnblogs.com/taopanpan/p/4263951.html

原文链接:https://www.f2er.com/centos/380413.html

猜你在找的CentOS相关文章