您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么在CentOS系統(tǒng)上安裝機(jī)器學(xué)習(xí)框架Caffe”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
注:系統(tǒng)安裝好后,先確認(rèn)kernel kernel-headers kernel-devel kernel-firmware四個(gè)包的版本要相同
代碼如下:
#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官網(wǎng):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的包再執(zhí)行編譯)
先安裝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在安裝時(shí)會(huì)區(qū)分已存在的版本)(解決libpython2.7.so.1.0辦法:vi /etc/ld.so.conf 添加/usr/local/lib,然后ldconfig)
替換系統(tǒng)中的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 # 得到一個(gè)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的包,再執(zhí)行python編譯,若執(zhí)行該命令的時(shí)候出現(xiàn)紅色cann't remove easy-install.pth的提醒,但目錄下又無此文件,可新建后再次執(zhí)行一遍命令,安裝系統(tǒng)的時(shí)候最好把開發(fā)工具的選項(xiàng)給勾上,出現(xiàn)“Successfully installed pip-6.0.8 setuptools-14.3.1為安裝成功”)
5、安裝cuda-6.5及驅(qū)動(dòng)
代碼如下:
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后會(huì)導(dǎo)致Xorg狂奔,直至系統(tǒng)死機(jī),需要將/etc/inittab中的啟動(dòng)級(jí)別改為3
注,驅(qū)動(dòng)包文件結(jié)構(gòu)不對(duì),導(dǎo)致nvidia_uvm.ko模塊無法編譯,需手動(dòng)解決
代碼如下:
cd /var/lib/dkms/nvidia/346.46
cp -rv /usr/src/nvidia-346.46 build
如果使用yum 方式安裝的使用下載下的驅(qū)動(dòng)包升級(jí)下
代碼如下:
chmod +x NVIDIA-Linux-x86_64-346.72.run
./NVIDIA-Linux-x86_64-346.72.run
重啟后,dkms會(huì)在開機(jī)時(shí)完成nvidia_uvm.ko的編譯
/lib/modules/版本號(hào)/extra/下有兩個(gè)包: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安裝版本不對(duì)
代碼如下:
tar -xf ffmpeg-2.6.1.tar.bz2 -C /usr/src
cd /usr/src/ffmpeg-2.6.1/
./configure --enable-shared #要以共享庫方式配置,否則opencv編譯時(shí)鏈接靜態(tài)庫會(huì)出錯(cuò)
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
配置環(huán)境變量:
代碼如下:
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
運(yùn)行./b2 install命令,默認(rèn)安裝在/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錯(cuò)誤,手動(dòng)建立一個(gè)
mkdir -p /usr/local/man/man1
11、將matlab上傳至服務(wù)器,通過圖形方式安裝
安裝秘鑰12345-67890-12345-67890
安裝完成后導(dǎo)入lic文件,然后替換libmwservices.so到
/usr/local/MATLAB/R2014a/bin/glnxa64/進(jìn)行覆蓋,結(jié)束安裝。
12、解決python依賴
代碼如下:
pip install 'six>=1.3'
easy_install -U distribute
pip2.7 install PIL --allow-external PIL --allow-unverified PIL
解包c(diǎn)affe-master.zip,并將該包移至opt目錄
代碼如下:
cd /opt/caffe-master/python
for i in $(cat requirements.txt); do pip install $i; done #需要多執(zhí)行幾遍
注:會(huì)出現(xiàn)一個(gè)報(bào)錯(cuò),關(guān)于PIL.Image >= 1.1.7,則可使用命令pip install 'PIL' 進(jìn)行安裝
后再次執(zhí)行以上的for循環(huán)語句,需要將python升級(jí)至2.7以上版本(安裝及注意事項(xiàng)下:)
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
執(zhí)行 ldconfig
make all -j12
make –j12 pycaffe
make –j12 matcaffe
make test –j12
make runtest –j12
如果matlab要使用靜態(tài)編譯libprotobuf.a的話,修改Makefile
在MATLAB_CXXFLAGS項(xiàng)上添加-static參數(shù)即可
但使用動(dòng)態(tài)庫的matlab模型可能不可用
若一切沒有問題,至此caffe環(huán)境安裝結(jié)束,待測試。
以下為可選部分
編譯安裝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
繼續(xù)安裝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”,并設(shè)置 “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:將相關(guān)的頭文件,庫文件放到profile中定義的系統(tǒng)路徑里即可,matlab的mex運(yùn)行時(shí)需要加載對(duì)應(yīng)庫
caffe編譯時(shí)也可在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顯卡時(shí),需要在Makefile.config里改如下幾個(gè)地方:
代碼如下:
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手動(dòng)安裝,不需要通過yum,yum安裝版本不對(duì),make runtest會(huì)報(bào)錯(cuò),使用protobuf2.5的版本,安裝方式見上,在編譯caffe前安裝好后再進(jìn)行編譯。
包:咖啡環(huán)境需要上傳的包: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文件夾
“怎么在CentOS系統(tǒng)上安裝機(jī)器學(xué)習(xí)框架Caffe”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。