1. 首页 > 服务器运维

centos6.5 下安装caffe

注:系统安装好后,先确认kernel kernel-headers kernel-devel kernel-firmware四个包的版本要相同

#rpm -qa |grep kernel

注: 先修改yum配置文件 /etc/yum.conf 修改 keepcache=1

1. 安装库

yum -y install epel-release.noarch
(wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm)
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -K rpmforge-release-0.5.3-1.el6.rf.*.rpm
rpm -ivh rpmforge-release-0.5.3-1.el6.rf.*.rpm rpmforge-releaser的安装方法

2、JDK安装

tar –xf jdk-7u25-linux-x64.tar.gz && mv jdk1.7.0_25/ jdk1.7 mv jdk1.7/ /opt
vim /etc/profile
export JAVA_HOME=/opt/jdk1.7
export JAVA_BIN=/opt/jdk1.7/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
source /etc/profile

3、编译安装python2.7(centOS6上用的是python2.6)

python官网:https://www.python.org/downloads/release/python-279/
替换python要在安装boost依赖之前

# wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz

编译安装python2.7(必须先安装zlib与openssl的包再执行编译)

先安装gcc zlib openssl 等包

tar -xvf Python-2.7.9.tgz -C /usr/src
cd /usr/src/Python-2.7.9
./configure --enable-shared
make -j12
make altinstall

(altinstall在安装时会区分已存在的版本)(解决libpython2.7.so.1.0办法:vi /etc/ld.so.conf 添加/usr/local/lib,然后ldconfig)

替换系统中的python

ls -l `which python python2 python2.6`
rm /usr/bin/python
ln -s -f /usr/local/bin/python2.7 /usr/bin/python

保持yum可用性

vim /usr/bin/yum
#!/usr/bin/python 改为 #!/usr/bin/python2.6

4、安装pip

curl -O https://bootstrap.pypa.io/get-pip.py # 得到一个get-pip.py
python get-pip.py
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-7.1.0 setuptools-18.0.1 wheel-0.24.0

(必须先安装openssl-devel与zlib的包,再执行python编译,若执行该命令的时候出现红色cann't remove easy-install.pth的提醒,但目录下又无此文件,可新建后再次执行一遍命令,安装系统的时候最好把开发工具的选项给勾上,出现“Successfully installed pip-6.0.8 setuptools-14.3.1为安装成功”)

5、安装cuda-6.5及驱动

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

GTX 660显卡装cuda后会导致Xorg狂奔,直至系统死机,需要将/etc/inittab中的启动级别改为3
注,驱动包文件结构不对,导致nvidia_uvm.ko模块无法编译,需手动解决

cd /var/lib/dkms/nvidia/346.46
cp -rv /usr/src/nvidia-346.46 build

如果使用yum 方式安装的使用下载下的驱动包升级下

chmod +x NVIDIA-Linux-x86_64-346.72.run
./NVIDIA-Linux-x86_64-346.72.run

重启后,dkms会在开机时完成nvidia_uvm.ko的编译

/lib/modules/版本号/extra/下有两个包:nvidia.ko nvidia_uvm.ko

lsmod|grep nvidia
vi /etc/rc.local #编辑该文件
modprobe nvidia_uvm #添加该条

5.1 run包安装方式

chmod +x cuda_6.5.19_linux_64.run
./ cuda_6.5.19_linux_64.run

 

6、安装blas

yum -y install blas.x86_64 blas-devel.x86_64 \
atlas.x86_64 atlas-devel.x86_64 atlas-sse3.x86_64 atlas-sse3-devel.x86_64

7、安装opencv

yum -y install ant.x86_64 gcc.x86_64 gcc-c++.x86_64 cmake.x86_64 git.x86_64 pkgconfig.x86_64 gtk2.x86_64 gtk2-devel.x86_64 libdc1394.x86_64 libdc1394-devel.x86_64 libjpeg-turbo.x86_64 libjpeg-turbo-devel.x86_64 libpng.x86_64 libpng-devel.x86_64 libtiff.x86_64 libtiff-devel.x86_64 jasper.x86_64 jasper-libs.x86_64 jasper-devel.x86_64 yasm.x86_64 yasm-devel.x86_64
pip install numpy

安装ffmpeg: #此包不需要通过yum安装,yum安装版本不对

tar -xf ffmpeg-2.6.1.tar.bz2 -C /usr/src
cd /usr/src/ffmpeg-2.6.1/
./configure --enable-shared #要以共享库方式配置,否则opencv编译时链接静态库会出错
make -j12 && make install
unzip opencv-2.4.9
cd opencv-2.4.9
mkdir release && cd release

修改源文件NCVPixelOperations.hpp,
文件替换到opencv路径下的modules/gpu/src/nvidia/core/NCVPixelOperations.hpp
配置环境变量:

vim /etc/profile.d/custom.sh 配置完成source /etc/profile.d/custom.sh
#!/bin/bash
export PATH=/usr/local/MATLAB/R2014a/bin:/usr/local/cuda-6.5/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/boost-1.55.0/lib:/usr/local/cuda-6.5/lib64:/opt/caffe-master/build/lib:/usr/lib64/atlas
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/boost-1.55.0/lib:/usr/local/cuda-6.5/lib64:/opt/caffe-master/build/lib:/usr/lib64/atlas
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/boost-1.55.0/include:/usr/local/cuda-6.5/include:/opt/caffe-master/build/src:/opt/caffe-master/include
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/boost-1.55.0/include:/usr/local/cuda-6.5/include:/opt/caffe-master/build/src:/opt/caffe-master/include
export PYTHONPATH=$PYTHONPATH:/opt/caffe-master/python
export HISTTIMEFORMAT="%F %T "
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make –j12
make install

8、安装boost-1.55(1.56不兼容)

yum -y install libicu.x86_64 libicu-devel.x86_64 bzip2-libs.x86_64 bzip2-devel.x86_64
tar –xf boost_1_55_0.tar.gz && cd boost_1_55_0
./bootstrap.sh
./b2
./b2 install

运行./b2 install命令,默认安装在/usr/local/lib目录下,头文件在/usr/local/include/boost目录下

9、安装caffe其他依赖:

yum -y install snappy.x86_64 snappy-devel.x86_64 hdf5.x86_64 hdf5-devel.x86_64 epel-release leveldb.x86_64 leveldb-devel.x86_64 libgfortran.x86_64
------ 编译安装protobuf-2.5.0 protobuf-2.5.0
------ tar -xvf protobuf-2.5.0.tar.gz
------ cd /usr/src/protobuf-2.5.0
./configure
make
make check
make install
------ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

10、编译安装caffe其他依赖包

glog
wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
tar zxvf glog-0.3.3.tar.gz
cd glog-0.3.3
./configure
make && make install
gflags
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
lmdb
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

11、将matlab上传至服务器,通过图形方式安装

安装秘钥12345-67890-12345-67890
安装完成后导入lic文件,然后替换libmwservices.so到
/usr/local/MATLAB/R2014a/bin/glnxa64/进行覆盖,结束安装。

12、解决python依赖

pip install 'six>=1.3'
easy_install -U distribute
pip2.7 install PIL --allow-external PIL --allow-unverified PIL

解包caffe-master.zip,并将该包移至opt目录

cd /opt/caffe-master/python
for i in $(cat requirements.txt); do pip install $i; done #需要多执行几遍

注:会出现一个报错,关于PIL.Image >= 1.1.7,则可使用命令pip install 'PIL' 进行安装
后再次执行以上的for循环语句,需要将python升级至2.7以上版本(安装及注意事项下:)

caffe

 

13、安装caffe

修改caffe-master/Makefile.config文件,增加如下几句

cp /opt/caffe-master/Makefile.config.example Makefile.config
vim Makefile.config
MATLAB_DIR := /usr/local/MATLAB/R2014a/
BLAS := atlas
BLAS_LIB := /usr/lib64/atlas
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/site-packages/numpy/core/include \
/usr/local/include/python2.7
执行 ldconfig
make all -j12
make –j12 pycaffe
make –j12 matcaffe
make test –j12
make runtest –j12

如果matlab要使用静态编译libprotobuf.a的话,修改Makefile
在MATLAB_CXXFLAGS项上添加-static参数即可
但使用动态库的matlab模型可能不可用

若一切没有问题,至此caffe环境安装结束,待测试。

以下为可选部分

编译安装protobuf-2.5.0 protobuf-2.5.0

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

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

#cd ./python 
#python setup.py build 
#python setup.py test 
#python setup.py install

安装cudnn
LINUX

cd <installpath>
export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
Add <installpath> to your build and link process by adding -I<installpath> to your compile line and -L<installpath> -lcudnn to your link line.
==========================

a. 编辑确保Makefile.config,启用GPU “# CPU_ONLY := 1”,并设置 “USE_CUDNN := 1”。

b. 安装cuDNN

tar -xzvf cudnn-6.5-linux-R1.tgz
cd cudnn-6.5-linux-R1
cp lib* /usr/local/cuda-6.5/lib64/
cp cudnn.h /usr/local/cuda-6.5/include/
cd /usr/local/cuda-6.5/lib64/
rm -rf libcudnn.so libcudnn.so.6.5
chmod u=rwx,g=rx,o=rx libcudnn.so.6.5.18
ln -s libcudnn.so.6.5.18 libcudnn.so.6.5
ln -s libcudnn.so.6.5 libcudnn.so
ldconfig

注1:将相关的头文件,库文件放到profile中定义的系统路径里即可,matlab的mex运行时需要加载对应库

caffe编译时也可在Makefile.config中修改,添加cuDNN的路径/cache/INSTALL_cuDNN/cudnn-6.5-linux-R1

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /cache/INSTALL_cuDNN/cudnn-6.5-linux-R1

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /cache/INSTALL_cuDNN/cudnn-6.5-linux-R1

注2:在使用tesla-c2050显卡时,需要在Makefile.config里改如下几个地方:

PYTHON_LIB := /usr/lib64 #原为PYTHON_LIB := /usr/lib
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib64 /usr/lib64 #原为如下:
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

注3:protobuf手动安装,不需要通过yum,yum安装版本不对,make runtest会报错,使用protobuf2.5的版本,安装方式见上,在编译caffe前安装好后再进行编译。

包:咖啡环境需要上传的包:gflags-master.zip、opencv-2.4.9.zip、boost_1_55_0.tar.gz、caffe-master.zip、glog-0.3.3.tar.gz、protobuf-2.5.0.tar.gz、cuda-repo-rhel6-6.5-14.x86_64.rpm、jdk-7u25-linux-x64.tar.gz、lmdb.tar、Python-2.7.9.tgz、 ffmpeg-2.6.1.tar.bz2、
rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm、NVIDIA-Linux-x86_64-346.72.run、
NCVPixelOperations.hpp、matlab文件夹

 

作者:峥叔、小葱 (运维生存时间③群),感谢两位投稿!

本文由主机测评网发布,不代表主机测评网立场,转载联系作者并注明出处:https://zhuji.jb51.net/yunwei/8102.html

联系我们

在线咨询:点击这里给我发消息

微信号:

工作日:8:30-17:30,节假日休息