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

因为有项目想采用深度学习,而caffe是深度学习框架中比较理想的一款,并且跨平台,以及可以采用python/matlab的方式进行调用等优势,所以想在服务器上安装,下面就开始了血泪史。。。

服务器是阿里云的centos7.3,安装caffe,需要安装ffmpeg,boost,opencv等等。本文依照ffmpeg3.3.2 版,boost为1.64版,opencv为2.4.13.2,caffe的版本为最新版为例来说。

本文主要采用自行编译安装各大软件。

首先安装一些依赖包

 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下)

安装Numpy 1.13.2 以及ipython

 pip install numpy
pip install pandas
pip install ipython==5.0

ok,装好就可以往下继续安装其他的的包了,先安装ffmpeg

1、安装x264编码器

因为最新版的x264进行编译的时候要求asm的版本较高,此处分享链接

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

2、安装x265编码器

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

3、安装libfdk_acc

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

4、安装libmp3lame

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

5、安装libopus

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

6、安装libogg库

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

7、安装libvorbis库

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

8、安装libvps库

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

9、编译安装ffmpeg

此处我才用的是2.8.12的代码,需要编辑ffplay.c,加上头文件<SDL/SDL_version.h>

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

 git clone --depth  git://source.ffmpeg.org/ffmpeg
cd ffmpeg
export PKG_CONFIG_PATH=/usr/local/ffmpeg/lib/pkgconfig/:/usr/lib64/pkgconfig/:/usr/share/pkgconfig/$PKG_CONFIG_PATH
./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
make
make install

10、编译安装boost

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

11、再次安装一些依赖包

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

12、安装opencv2.4.13.2

 ln -s /usr/include/libv4l1-videodev.h   /usr/include/linux/videodev.h
echo "/usr/local/ffmpeg/lib" >> /etc/ld.so.conf
ldconfig
export C_INCLUDE_PATH=/usr/local/ffmpeg/include/:/usr/include/:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/ffmpeg/include/:/usr/include/:$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib/:/usr/loca/lib/:/usr/lib/:$LD_LIBRARY_PATH
wget https://github.com/opencv/opencv/archive/2.4.13.2.zip
unzip 2.4.13.2.zip
cd opencv-2.4.13.2/
mkdir build
cmake –D CMAKE_BUILD_TYPE=RELEASE–D CMAKE_INSTALL_PREFIX=./build/ ../opencv-2.4.13.2
make
make install

13、再次安装依赖包

 yum install protobuf* leveldb* snappy* hdf5* lmdb* libunwind*
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/google-glog/glog-0.3.3.tar.gz
tar -zxf glog-0.3..tar.gz
cd glog-0.3./
./configure --enable-static --enable-shared --with-pic
make
make install
wget https://github.com/schuhschuh/gflags/archive/master.zip
unzip master.zip
cd gflags-master/
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=
make

14、安装BLAS,CBLAS,OpenBLAS

 wget http://www.netlib.org/blas/blas-3.7.1.tgz
tar -zxf blas-3.7..tgz
cd BLAS-3.7./
gfortran -c -O3 *.f
ar rv libblas.a *.o
wget http://www.netlib.org/blas/blast-forum/cblas.tgz
tar -zxf cblas.tgz
cd CBLAS/
cp Makefile.LINUX Makefile.in
cp ../BLAS-3.7./libblas.a testing/
cp lib/cblas_LINUX.a /usr/local/lib/libcblas.a
cp testing/libblas.a /usr/local/lib/libblas.a
cp include/cblas.h /usr/local/include/
wget http://github.com/xianyi/OpenBLAS/archive/v0.2.19.tar.gz
tar -zxf v0.2.19.tar.gz
cd OpenBLAS-0.2./
make
make PREFIX=/usr/local install
git clone https://github.com/BVLC/caffe.git
cd caffe
cp Makefile.config.example Makefile.config

15、编辑Makefile.config

 CPU_ONLY := 

 # CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr # CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
#CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
# -gencode arch=compute_20,code=sm_21 \
# -gencode arch=compute_30,code=sm_30 \
# -gencode arch=compute_35,code=sm_35 \
# -gencode arch=compute_50,code=sm_50 \
# -gencode arch=compute_52,code=sm_52 \
# -gencode arch=compute_60,code=sm_60 \
# -gencode arch=compute_61,code=sm_61 \
# -gencode arch=compute_61,code=compute_61 BLAS := open
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
BLAS_INCLUDE := /usr/local/include
BLAS_LIB := /usr/local/lib

16、安装caffe

 cd python
for req in $(cat requirements.txt); do pip install $req; done
cd ..
make all
make test
make runtest
make pycaffe
cp -r python/caffe/ /usr/lib64/python2./site-packages/
echo "/root/build/caffe/.build_release/lib" >> /etc/ld.so.conf
pip uninstall numpy
wget https://pypi.python.org/packages/1a/5c/57c6920bf4a1b1c11645b625e5483d778cedb3823ba21a017112730f0a12/numpy-1.11.0.tar.gz#md5=bc56fb9fc2895aa4961802ffbdb31d0b
tar -zxf numpy-1.11..tar.gz
cd numpy-1.11.
python setup.py build
python setup.py install

 

上一篇:s4-6 二层交换


下一篇:Faster rcnn代码理解(4)