• [转]centos 6.5安装caffe


    centos 6.5安装caffe

    原文地址:http://blog.csdn.net/wqzghost/article/details/47447377
     

    总结:在安装protobuf,hdf5等的时候指定了安装路径,这导致在11、12两个步骤中要配置编译选项及链接库的位置,这些软件默认应该是安装在/usr/local下的,如果这个推断是正确的,那么只需要编译caffe之前在/etc/ld.so.conf中添加如下内容: 
    /usr/local/lib 
    /usr/local/lib64

    一、服务器配置

    操作系统:centos 6.5 
    GPU:

    [root@localhost ~]# lspci | grep -i nvidia
    02:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20c] (rev a1)
    04:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20c] (rev a1)
    83:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20c] (rev a1)
    84:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20c] (rev a1)
    • 1
    • 2
    • 3
    • 4
    • 5
    • 1
    • 2
    • 3
    • 4
    • 5

    注意:这里使用的是命令行版的centos,如果是图形界面,需要另外配置。

    二、安装过程1

    在安装之前,建议建立一个文件件,将涉及到的安装包放入其内,便于管理:

    $ mkdir caffe
    $ cd caffe
    • 1
    • 2
    • 1
    • 2

    另外,记得更新一下系统:

    $ yum update -y
    • 1
    • 1

    1.安装cuda

    nvidia官网提供了yum源,因此只需安装yum源,便可轻松安装cuda,省去编译的复杂过程。需要注意的是一定要根据直接的操作系统选择合适的版本,详情点这里

    $ yum install epel-release
    $ wget http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-7.0-28.x86_64.rpm 
    $ rpm -iv cuda-repo-rhel7-7.0-28.x86_64.rpm
    $ yum search cuda
    $ yum install cuda
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    2.安装opencv

    $ yum install opencv-devel
    # 配置 OpenCV 环境
    $ git clone https://github.com/jayrambhia/Install-OpenCV 
    $ cd Install-OpenCV/RedHat 
    $ ./opencv_latest.sh
    • 1
    • 2
    • 3
    • 4
    • 5
    • 1
    • 2
    • 3
    • 4
    • 5

    在一些资料上看到这样的安装过程,有两个问题:(1)是否需要执行yum install OpenCV-devel,根据Install-OpenCV/RedHat/opencv_install.sh文件,应该是不需要的,有勇气的同学可以试一下!(2)执行./opencv_latest.sh后发现安装不成功,原因可能是centos一些软件版本过低造成的。没办法选择手动安装,记得参考Install-OpenCV/RedHat/opencv_install.sh2

    $ yum -y groupinstall "Development Tools"
    $ yum -y install wget unzip opencv opencv-devel gtk2-devel cmake
    $ wget -O opencv-2.4.9.tar.gz 
    $ http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.tar.gz/download
    $ tar -zxf opencv-2.4.9.tar.gz
    $ cd opencv-2.4.9
    $ mkdir build
    $ cd build
    $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..
    $ make -j8
    $ make install
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    cmake需要指定GPU架构3 :-D CUDA_GENERATION=Kepler,否则报错:Unsupported gpu architecture ‘compute_11’

    安装的过程可能没那么顺利,经常会遇到各种错误。例如生成lib/libopencv_highgui.so.2.4.9找不到png_set_longjmp_fn,可以这样解决:

    #google之后发现这个函数定义在libpng中
    #查看libopencv_highgui.so.2.4.9引用了哪个libpng
    $ ldd lib/libopencv_highgui.so.2.4.9 | grep libpng
    #查看该lipng中是否定义了png_set_longjmp_fn,注意根据自己的环境替换掉/usr/lib64/libpng12.so.0.49.0
    $ readelf -s /usr/lib64/libpng12.so.0.49.0 | grep png_set_longjmp_fn
    #没有任何输出,说明没有定义,则需要安装更新的版本
    $ wget http://github.com/glennrp/libpng-releases/raw/master/libpng-1.5.23.tar.xz
    $ tar -xvf libpng-1.5.23.tar.xz
    $ cd libpng-1.5.23
    $ make install
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    安装后发现仍然找不到,这是因为链接时查找路径的问题4:

    $ cd /usr/local/lib
    $ cp -d libpng15.a libpng15.la libpng15.so* libpng.a libpng.* /usr/lib64
    • 1
    • 2
    • 1
    • 2

    另外可能遇到的问题是编译过程中提示:

    opencv-2.4.9/modules/gpu/src/nvidia/core/NCVPixelOperations.hpp(51): error: a storage class is not allowed in an explicit specialization
    • 1
    • 1

    解决方法是下载NCVPixelOperations.hpp,替换原来的文件重新编译即可5.

    3.安装atlas、snappy、boost

    $ yum install atlas-devel snappy-devel boost-devel
    • 1
    • 1

    4.安装protobuf

    $ cd ~/caffe 
    $ tar –xvf protobuf-2.5.0.tar.gz 
    $ cd protobuf-2.5.0 
    $ ./configure --prefix=/opt/protobuf
    $ make 
    $ make install
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    5.安装leveldb

    $ cd ~/caffe 
    $ tar –xvf leveldb-1.7.0.tar.gz 
    $ cd leveldb-1.7.0 
    $ make
    $ cp libleveldb* /usr/lib/
    $ cp –r include/leveldb /usr/local/include
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    6.安装hdf5

    $ cd ~/caffe 
    $ tar –xvf hdf5-1.8.8.tar.bz2 
    $ cd hdf5-1.8.8 
    $ ./configure --prefix=/opt/hdf5
    $ make 
    $ make install
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    7.安装glog

    $ cd ~/caffe 
    $ tar –xvf glog-0.3.3.tar.gz 
    $ cd glog-0.3.3 
    $ ./configure 
    $ make
    $ make install
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    8.安装gflags

    $ cd ~/caffe 
    $ unzip master.zip 
    $ cd gflags-master 
    $ mkdir build
    $ cd build 
    $ export CXXFLAGS=”-fPIC” 
    $ cmake .. 
    $ make
    $ make install
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    9.安装lmdb

    $ wget https://codeload.github.com/LMDB/lmdb/tar.gz/LMDB_0.9.15
    $ tar -xvf LMDB_0.9.15.tar.gz
    $ make
    $ make install
    • 1
    • 2
    • 3
    • 4
    • 1
    • 2
    • 3
    • 4

    10.将 /opt/protobuf/bin 加入到 PATH

    echo 'export PATH=$PATH:/opt/protobuf/bin' >> ~/.bashrc
    • 1
    • 1

    11.安装caffe

    $ cd ~/caffe 
    $ unzip caffe-master.zip 
    $ cd caffe-master 
    $ cp Makefile.config.example Makefile.config
    $ vi Makefile
    # 修改内容为: 
    #   COMMON_FLAGS 加上 –I/opt/protobuf/include –I/opt/hdf5/include 
    #   LDFLAGS 加上 –L/opt/protobuf/lib –L/opt/hdf5/lib    
    #   LIBRARIES += boost_thread 改为 LIBRARIES += boost_thread-mt
    $ vi Makefile.config
    # 修改内容为:
    #   LIBRARY_DIRS 加上 /usr/lib64/atlas
    $ make all
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    12. 配置运行环境

    $ vi /etc/ld.so.conf.d/caffe.conf
    # 增加内容
    #   /usr/local/cuda/lib64
    #   /opt/protobuf/lib
    #   /opt/hdf5/lib
    #   /usr/local/lib                    
    $  ldconfig
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    13. 运行

    $ reboot
    $ sh data/mnist/get_mnist.sh 
    $ sh examples/mnist/create_mnist.sh 
    $ vi examples/mnist/lenet_solver.prototxt
    # 修改 ~/caffe/caffe-master/examples/mnist/lenet_solver.prototxt 文件设定运行 CPU 版本或者 GPU 版本。
    # 修改最后一行: solver_mode: CPU 或者 solver_mode: GPU
    $ time sh examples/mnist/train_lenet.sh
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    参考文献

  • 相关阅读:
    防止死锁的加锁机制
    python线程threading.Timer源码解读
    python语言线程标准库threading.local源码解读
    栈和队列的总结
    如何根据入栈序列判断可能的出栈序列
    使用 Air 热编译 Gin 项目
    【Golang设计模式】7.外观模式
    Go中的数据类型、指针、new和make
    【Golang设计模式】6.模板方法模式
    【Golang设计模式】5.原型模式
  • 原文地址:https://www.cnblogs.com/Crysaty/p/6272994.html
Copyright © 2020-2023  润新知