CentOS7下安裝caffe(包括ffmpeg\boost\opencv)

由於有項目想採用深度學習,而caffe是深度學習框架中比較理想的一款,而且跨平臺,以及能夠採用python/matlab的方式進行調用等優點,因此想在服務器上安裝,下面就開始了血淚史。。。java

服務器是阿里雲的centos7.3,安裝caffe,須要安裝ffmpeg,boost,opencv等等。本文依照ffmpeg3.3.2 版,boost爲1.64版,opencv爲2.4.13.2,caffe的版本爲最新版爲例來講。python

本文主要採用自行編譯安裝各大軟件。linux

首先安裝一些依賴包c++

1 yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel SDL* yasm* python-devel nasm* cmake* git ncurses* *freetype2*

須要提一下,若是未來要採用python調用caffe的話,必須將numpy提早裝好,最新的版本爲1.13.2, ipython安裝5.0版本(python2.7下)git

安裝Numpy 1.13.2 以及ipythongithub

1 pip install numpy
2 pip install pandas 
3 pip install ipython==5.0

ok,裝好就能夠往下繼續安裝其餘的的包了,先安裝ffmpegweb

一、安裝x264編碼器sql

    由於最新版的x264進行編譯的時候要求asm的版本較高,此處分享連接centos

1 mkdir build
2 cd build
3 wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20120718-2245-stable.tar.bz2
4 tar -jxf x264-snapshot-20120718-2245-stable.tar.bz25 cd x264-snapshot-20120718-2245-stable/
6 ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/ffmpeg/bin" --enable-static --enable-shared --enable-pic
7 make 
8 make install

 二、安裝x265編碼器api

1 cd build
2 git clone https://github.com/videolan/x265.git
3 cd x265/build/linux
4 cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/usr/local/ffmpeg/" -DENABLE_SHARED:bool=off ../../source
5 make
6 make install

三、安裝libfdk_acc

1 git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
2 cd fdk-aac
3 autoreconf -fiv
4 ./configure --prefix="/usr/local/ffmpeg" --enable-shared --enable-static --with-pic5 make
6 make install

四、安裝libmp3lame

1 wget http://iweb.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
2 tar zxf lame-3.99.5.tar.gz
3 cd lame-3.99.5
4 ./configure --prefix="/usr/local/ffmpeg" --bindir="/usr/local/bin" --enable-shared --enable-nasm --enable-static --with-pic
5 make
6 make install

五、安裝libopus

1 git clone git://git.opus-codec.org/opus.git
2 cd opus
3 ./autogen.sh
4 ./configure --prefix="/usr/local/ffmpeg" --enable-shared --enable-static --with-pic 5 make 6 make install

六、安裝libogg庫

1 curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
2 tar xzvf libogg-1.3.2.tar.gz
3 cd libogg-1.3.2
4 ./configure --prefix="/usr/local/ffmpeg" --enable-shared --enable-static --with-pic
5 make
6 make install

七、安裝libvorbis庫

1 curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
2 tar xzvf libvorbis-1.3.4.tar.gz
3 cd libvorbis-1.3.4
4 LDFLAGS="-L/usr/local/ffmpeg/lib" 
5 CPPFLAGS="-I/usr/local/ffmpeg/include"
6  ./configure --prefix="/usr/local/ffmpeg" --with-ogg="/usr/local/ffmpeg" --enable-shared --enable-static --with-pic
7 make
8 make install

八、安裝libvps庫

1 git clone --depth 1 http://git.chromium.org/webm/libvpx.git
2 cd libvpx
3 ./configure --prefix="/usr/local/ffmpeg" --enable-examples --enable-shared --enable-static --enable-pic
4 make
5 make install

九、編譯安裝ffmpeg

此處我才用的是2.8.12的代碼,須要編輯ffplay.c,加上頭文件<SDL/SDL_version.h>

修改 /etc/ld.so.conf 添加/usr/local/ffmpeg/lib

1 git clone --depth 1 git://source.ffmpeg.org/ffmpeg
2 cd ffmpeg
3 export PKG_CONFIG_PATH=/usr/local/ffmpeg/lib/pkgconfig/:/usr/lib64/pkgconfig/:/usr/share/pkgconfig/$PKG_CONFIG_PATH 
4 ./configure --prefix="/usr/local/ffmpeg" --extra-cflags="-I/usr/local/ffmpeg/include" --extra-ldflags="-L/usr/local/ffmpeg/lib" --bindir="/usr/local/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-avresample --enable-pic --enable-static --enable-shared
5 make
6 make install

 十、編譯安裝boost

1 wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.gz
2 tar -zxf  boost_1_64_0.tar.gz
3 cd boost_1_64_0
4 ./boostrap.sh
5 ./b2 install

 十一、再次安裝一些依賴包

1 yum install a52dec* giflib* imlib* lame* libICE* libXdmcp* *dc1394* *raw1394* *avc1394* *raw1394*
2 yum groupinstall "Development Tools" 
3 yum install openssl* sqlite* gtk* *java* gstreamer* *v4l* gmp* gimp*  *java* libpng*

十二、安裝opencv2.4.13.2

 1 ln -s /usr/include/libv4l1-videodev.h   /usr/include/linux/videodev.h
 2 echo "/usr/local/ffmpeg/lib" >> /etc/ld.so.conf
 3 ldconfig
 4 export C_INCLUDE_PATH=/usr/local/ffmpeg/include/:/usr/include/:$C_INCLUDE_PATH
 5 export CPLUS_INCLUDE_PATH=/usr/local/ffmpeg/include/:/usr/include/:$CPLUS_INCLUDE_PATH
 6 export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib/:/usr/loca/lib/:/usr/lib/:$LD_LIBRARY_PATH
 7 wget https://github.com/opencv/opencv/archive/2.4.13.2.zip
 8 unzip 2.4.13.2.zip
 9 cd opencv-2.4.13.2/
10 mkdir build
11 cmake –D CMAKE_BUILD_TYPE=RELEASE–D CMAKE_INSTALL_PREFIX=./build/ ../opencv-2.4.13.2
12 make
13 make install

 1三、再次安裝依賴包

 1 yum install protobuf* leveldb* snappy* hdf5* lmdb* libunwind*
 2 wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/google-glog/glog-0.3.3.tar.gz
 3 tar -zxf glog-0.3.3.tar.gz
 4 cd glog-0.3.3/
 5 ./configure --enable-static --enable-shared --with-pic
 6 make 
 7 make install
 8 wget https://github.com/schuhschuh/gflags/archive/master.zip
 9 unzip master.zip
10 cd gflags-master/
11 mkdir build && cd build
12 export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
13 make

1四、安裝BLAS,CBLAS,OpenBLAS

 1 wget http://www.netlib.org/blas/blas-3.7.1.tgz
 2 tar -zxf blas-3.7.1.tgz
 3 cd BLAS-3.7.1/
 4 gfortran -c  -O3   *.f 
 5 ar rv libblas.a      *.o
 6 wget http://www.netlib.org/blas/blast-forum/cblas.tgz
 7 tar -zxf cblas.tgz
 8 cd CBLAS/
 9 cp Makefile.LINUX Makefile.in
10 cp ../BLAS-3.7.1/libblas.a testing/
11 cp lib/cblas_LINUX.a /usr/local/lib/libcblas.a
12 cp testing/libblas.a /usr/local/lib/libblas.a
13 cp include/cblas.h /usr/local/include/
14 wget http://github.com/xianyi/OpenBLAS/archive/v0.2.19.tar.gz
15 tar -zxf v0.2.19.tar.gz
16 cd OpenBLAS-0.2.19/
17 make
18 make PREFIX=/usr/local install
19 git clone https://github.com/BVLC/caffe.git
20 cd caffe
21 cp Makefile.config.example Makefile.config

1五、編輯Makefile.config

8 CPU_ONLY := 1

28 # CUDA_DIR := /usr/local/cuda
29 # On Ubuntu 14.04, if cuda tools are installed via
30 # "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
31 # CUDA_DIR := /usr
32 
33 # CUDA architecture setting: going with all of them.
34 # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
35 # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
36 #CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
37 #               -gencode arch=compute_20,code=sm_21 \
38 #               -gencode arch=compute_30,code=sm_30 \
39 #               -gencode arch=compute_35,code=sm_35 \
40 #               -gencode arch=compute_50,code=sm_50 \
41 #               -gencode arch=compute_52,code=sm_52 \
42 #               -gencode arch=compute_60,code=sm_60 \
43 #               -gencode arch=compute_61,code=sm_61 \
44 #               -gencode arch=compute_61,code=compute_61

50 BLAS := open
51 # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
52 # Leave commented to accept the defaults for your choice of BLAS
53 # (which should work)!
54 BLAS_INCLUDE := /usr/local/include
55 BLAS_LIB := /usr/local/lib

1六、安裝caffe

 1 cd python
 2 for req in $(cat requirements.txt); do pip install $req; done
 3 cd ..
 4 make all
 5 make test
 6 make runtest
 7 make pycaffe
 8 cp -r python/caffe/ /usr/lib64/python2.7/site-packages/
 9 echo "/root/build/caffe/.build_release/lib" >> /etc/ld.so.conf
10 pip uninstall numpy
11 wget https://pypi.python.org/packages/1a/5c/57c6920bf4a1b1c11645b625e5483d778cedb3823ba21a017112730f0a12/numpy-1.11.0.tar.gz#md5=bc56fb9fc2895aa4961802ffbdb31d0b
12 tar -zxf  numpy-1.11.0.tar.gz
13 cd numpy-1.11.0
14 python setup.py build
15 python setup.py install
相關文章
相關標籤/搜索