1菩掏,安裝NVIDIA 顯卡
根據(jù)自己的顯卡驅(qū)動(dòng) 選擇對應(yīng)的版本(我的NVIDIA-Linux-x86_64-384.69.run)
官網(wǎng)下載地址:www.nvidia.cn/Download/index.aspx
安裝步驟:
cd ~/Downloads
chmod +x? NVIDIA-Linux-x86_64-384.69.run
sudo service lightdm stop
ctrl+alt+f1進(jìn)入字符界面
sudo ./NVIDIA-Linux-x86_64-384.69.run -no-opengl-files -no-x-check -no-nouveau-check
安裝好之后 sudo rm /etc/X11/xorg.conf?? ~/.Xauthority (防止linux登陸界面無限循環(huán)或者分辨率不對)
sudo service lightdm start
回到桌面
輸入nvidia-smi 輸出如下:則安裝成功
2.安裝CUDA8.0
1.下載完之后:sudo sh cuda_8.0.27_linux.run
sudo gedit /etc/profile
打開“profile”文件魂角,在末尾處添加(注意不要有空格,不然會(huì)報(bào)錯(cuò)):
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
2.重啟電腦:
sudo reboot
3,測試
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
輸出是GPU的信息說明安裝成功
3患蹂,安裝cudnn6.0
下載完成之后解壓到指定目錄
tar -zxvf cudnn-8.0-linux-x64-v6.0.tgz -C ../cudnn/
把下載好的cudnn.h文件和lib文件分別拷貝到cuda對應(yīng)的路徑下面。
sudo cp ~/cudnn/cuda/include/cudnn.h? /usr/local/cuda/include
sudo cp ~/cudnn/cuda/lib64/lib*?? /usr/local/cuda/lib64/
做個(gè)鏈接 不然后面caffe make test 會(huì)報(bào)鏈接共享庫錯(cuò)誤的問題
ln -sf ~/cudnn/cuda/lib64/libcudnn.so.6 /usr/local/cuda/lib64/
4砸紊,opencv(包含contrib模塊)編譯安裝 (直接建一個(gè)shell文件運(yùn)行即可完成自動(dòng)編譯安裝)
cd$HOME
sudo apt-get install -y \
libglew-dev \
libtiff5-dev \
zlib1g-dev \
libjpeg-dev \
libpng12-dev \
libjasper-dev \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libpostproc-dev \
libswscale-dev \
libeigen3-dev \
libtbb-dev \
libgtk2.0-dev \
cmake \
pkg-config
#Python 2.7
sudo apt-get install -y python-dev python-numpy python-py python-pytest -y
#GStreamer support
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout -b v3.2.0 3.2.0
#This is for the test data
cd$HOME
git clone https://github.com/opencv/opencv_extra.git
cd opencv_extra
git checkout -b v3.2.0 3.2.0
cd$HOME/opencv
mkdir build
cd build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_PNG=OFF \
-DBUILD_TIFF=OFF \
-DBUILD_TBB=OFF \
-DBUILD_JPEG=OFF \
-DBUILD_JASPER=OFF \
-DBUILD_ZLIB=OFF \
-DBUILD_EXAMPLES=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_python2=ON \
-DBUILD_opencv_python3=OFF \
-DENABLE_PRECOMPILED_HEADERS=OFF \
-DWITH_OPENCL=OFF \
-DWITH_OPENMP=OFF \
-DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=ON \
-DWITH_GSTREAMER_0_10=OFF \
-DWITH_CUDA=ON \
-DWITH_GTK=ON \
-DWITH_VTK=OFF \
-DWITH_TBB=ON \
-DWITH_1394=OFF \
-DWITH_OPENEXR=OFF \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \
-DCUDA_ARCH_BIN=6.2 \
-DCUDA_ARCH_PTX=""\
-DINSTALL_C_EXAMPLES=ON \
-DINSTALL_TESTS=ON \
-DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \
../
#Consider using all 6 cores; $ sudo nvpmodel -m 2 or $ sudo nvpmodel -m 0
make -j4
編譯可能遇到的問題:cudalegacy/src/graphcuts.cpp:120:54: error: ‘NppiGraphcutState’ has not been declared:
解決方案:需要修改一處源碼:
在graphcuts.cpp中將
#if?!defined?(HAVE_CUDA)?||?defined?(CUDA_DISABLER)
改為
#if?!defined?(HAVE_CUDA)?||?defined?(CUDA_DISABLER)?||?(CUDART_VERSION?>=?8000)
5,編譯安裝caffe
(1)將終端cd到要安裝caffe的位置传于。
(2)從github上獲取caffe:
git clone https://github.com/BVLC/caffe.git
(3)因?yàn)閙ake指令只能make
Makefile.config文件,而Makefile.config.example是caffe給出的makefile例子醉顽,因此沼溜,首先將Makefile.config.example的內(nèi)容復(fù)制到Makefile.config:
sudo? cp? Makefile.config.example? Makefile.config
(4)打開并修改配置文件:
sudo gedit Makefile.config #打開Makefile.config文件
根據(jù)個(gè)人情況修改文件:
a.若使用cudnn,則
將#USE_CUDNN := 1修改成: USE_CUDNN :=1
b.若使用的opencv版本是3的游添,則
將#OPENCV_VERSION := 3修改為: OPENCV_VERSION :=3
c.若要使用python來編寫layer系草,則
將#WITH_PYTHON_LAYER := 1修改為 WITH_PYTHON_LAYER :=1
d.重要的一項(xiàng):
將# Whatever else you find you need goes here.下面的
INCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/includeLIBRARY_DIRS:=$(PYTHON_LIB) /usr/local/lib /usr/lib 修改為: INCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serialLIBRARY_DIRS:=$(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/hdf5/serial
這是因?yàn)閡buntu16.04的文件包含位置發(fā)生了變化,尤其是需要用到的hdf5的位置唆涝,所以需要更改這一路徑.
(5)修改makefile文件
打開makefile文件找都,做如下修改:
將:NVCCFLAGS+= -ccbin=$(CXX) -Xcompiler -fPIC$(COMMON_FLAGS)替換為:NVCCFLAGS+=-D_FORCE_INLINES?? ?? -ccbin=$(CXX)? -Xcompiler? -fPIC$(COMMON_FLAGS)
(6)編輯/usr/local/cuda/include/host_config.h
將其中的第115行注釋掉:
將#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!改為//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
(7)編譯
make? all? -j8? #-j根據(jù)自己電腦配置決定