CAFFE安裝 CentOS無GPU


 前記

由於是在一台用了很久的機器上安裝caffe,過程比較復雜,網上說再干凈的機器上裝比較簡單。如果能有干凈的機器,就不用再過這么多坑了,希望大家好運!介紹這里就不說了,直接進入正題:

Caffe 主頁  http://caffe.berkeleyvision.org/

github主頁 https://github.com/BVLC/caffe

機器配置: 

[root@cdh-nn-182 build]# 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:    RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 6.3 (Santiago)
Release:    6.3

gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)

Python 2.7.10 

 python已安裝numpy,沒有GPU

Prerequisites
  • CUDA is required for GPU mode.
    • library version 7.0 and the latest driver version are recommended, but 6.* is fine too
    • 5.5, and 5.0 are compatible but considered legacy
  • BLAS via ATLAS, MKL, or OpenBLAS.
  • Boost >= 1.55
  • OpenCV >= 2.4 including 3.0
  • protobufgloggflags
  • IO libraries hdf5leveldbsnappylmdb

Pycaffe and Matcaffe interfaces have their own natural needs.

  • For Python Caffe: Python 2.7 or Python 3.3+numpy (>= 1.7), boost-provided boost.python
  • For MATLAB Caffe: MATLAB with the mex compiler.

1.  安裝各種依賴包

yum install -y gcc gcc-c++ gtk+-devel libjpeg-devel libtiff-devel jasper-devel libpng-devel zlib-devel cmake
yum install git gtk2-devel pkgconfig numpy python python-pip python-devel gstreamer-plugins-base-devel libv4l ffmpeg-devel mplayer mencoder flvtool2
yum install libdc1394 libdc1394-devel.x86_64
yum install gtk*

2. python包安裝

下載Caffe源碼,按照./caffe/caffe-master/python/requirements.txt 安裝所需要的包,用pip安裝比較方便,不行就自己下載手動安裝,沒什么問題。

3. 安裝protobufgloggflags

先從比較簡單的來:

 

4. 安裝CUDA

 從nvidia網站上下載最新的CUDA7.5,按自己的操作系統進行選擇,這里選擇下載cuda_7.5.18_linux.run,直接運行:

./cuda_6.5.14_linux_64.run

運行后會出現選擇安裝的項目,選擇不安裝驅動,否則會出錯(driver installation is unable to locate the kernel source),也就是第一個選項No

5. 安裝OpenBLAS

 ATLAS, MKL, or OpenBLAS都可以安裝,以前用過OpenBLAS,這次就還裝他吧

下載OpenBLAS源碼,安裝也很簡單,make && make install即可,更多請參考 OpenBLAS編譯和安裝簡介

6. 安裝OpenCV

 OpenCV裝起來比較麻煩,中間遇到了很多問題,參考安裝文檔,也可以參考網上很多人給的 自動安裝配置腳本,由於我安裝時出了很多問題,所以基本是自己手動裝的。

首先將自己的CMake升級到最新版本,yum默認裝的默認不行,只能手動升級了,否則在CMake階段就會出現各種警告什么的。

下載OpenCV-3.0.0

unzip opencv-3.0.0.zip
cd opencv-3.0.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

##如果不出問題
make -j 32
sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

下面說說我在make的時候碰到的問題:

Q1:已經安裝了ffmpeg,出現錯誤AVCodecID未聲明

cap_ffmpeg_impl.hpp:1556:83:錯誤:使用枚舉‘AVCodecID’前沒有給出聲明

A1: 解決的方法是,添加make參數 -D WITH_FFMPEG=OFF,參考

 

Q2:出現parallel_for_pthreads undefined reference 錯誤,貌似是只有在CentOs中才會出現的

A2: 需要更改modules/core/src/parallel.cpp文件,參考1參考2,我這里只按照參考2給了parallel.cpp文件

 

Q3: 出現undefined reference to `jpeg_default_qtables'

../../../lib/libopencv_imgcodecs.so.3.0.0: undefined reference to `jpeg_default_qtables'

A3:安裝,jpegsrc.v9a.tar.gz, 參考1參考2參考3

tar -xzvf jpegsrc.v9.tar.gz
cd jpeg-9
./configure
make libdir=/usr/lib64
make libdir=/usr/lib64 install

 

Q4:編譯已完成,但是還是有問題:

[100%] Linking CXX shared library ../../lib/cv2.so
/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value
collect2: ld 返回 1
make[2]: *** [lib/cv2.so] 錯誤 1
make[1]: *** [modules/python2/CMakeFiles/opencv_python2.dir/all] 錯誤 2
make: *** [all] 錯誤 2

A4:重新編譯安裝python,configure時添加--enable-shared,參考

./configure --enable-shared
make
make install

 重新安裝完以后可能會出現,執行python時error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory,解決方法是:

 vi /etc/ld.so.conf 
 #如果是非root權限帳號登錄,使用 sudo vi /etc/ld.so.conf 
 #添加上python2.7的lib庫地址,如我的/usr/local/Python2.7/lib,保存文件

/sbin/ldconfig

 

7. 安裝Caffe

如果以上安裝沒有什么問題,這一不應該不會出錯

unzip caffe-master.zip
cd caffe-master
cp Makefile.config.example Makefile.config

vim Makefile.config 
# 按照實際情況修改配置 CPU_ONLY :
= 1 BLAS := open

make all

8. 運行MINIST例子

參考

cd $CAFFE_ROOT
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh

vim ./examples/mnist/lenet_solver.prototxt

solver_mode: CPU
./examples/mnist/train_lenet.sh

 就可以運行了

 

I0916 17:43:44.016604 63362 solver.cpp:571] Iteration 9900, lr = 0.00596843
I0916 17:44:05.355252 63362 solver.cpp:449] Snapshotting to binary proto file examples/mnist/lenet_iter_10000.caffemodel
I0916 17:44:05.371235 63362 solver.cpp:734] Snapshotting solver state to binary proto fileexamples/mnist/lenet_iter_10000.solverstate
I0916 17:44:05.464294 63362 solver.cpp:326] Iteration 10000, loss = 0.00184362
I0916 17:44:05.464337 63362 solver.cpp:346] Iteration 10000, Testing net (#0)
I0916 17:44:11.869861 63362 solver.cpp:414]     Test net output #0: accuracy = 0.9907
I0916 17:44:11.869920 63362 solver.cpp:414]     Test net output #1: loss = 0.0280591 (* 1 = 0.0280591 loss)
I0916 17:44:11.869931 63362 solver.cpp:331] Optimization Done.
I0916 17:44:11.869940 63362 caffe.cpp:214] Optimization Done.

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM