sudo apt-get update&&sudo apt-get upgrade
nvidia-smi #確認輸出了有效信息,如
date +-----------------------------------------------------------------------------+ | NVIDIA-SMI XXX.XXX Driver Version: XXX.XXX | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 1070 Off | 00000000:01:00.0 On | N/A | | 0% 31C P8 11W / 230W | 201MiB / 8110MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 997 G /usr/lib/xorg/Xorg 136MiB | | 0 1839 G compiz 59MiB | | 0 2358 G /usr/lib/firefox/firefox 3MiB | +-----------------------------------------------------------------------------+
sudo apt-get install --no-install-recommends libboost-all-dev -y sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libopenblas-dev liblapack-dev libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev -y
sudo sh ./cuda_[9.X_XXX]_linux.run --no-opengl-libs #本體,非opengl這個參數很是重要,刪掉就等着開機循環登陸吧 sudo sh ./cuda_[9.X.Y]_linux.run #[--no-opengl-libs] #補丁, 能夠裝,必要性視補丁具體內容決定,修復bug和error的確定要裝
其中,第一項顯卡驅動不須要裝(由於前一步已經裝過了,若是前一步兩種方法都安裝不了NVIDIA驅動的話,再考慮裝cuda這裏自帶的驅動),第二項cuda組件必須裝,第三項cuda示例能夠安裝html
sudo gedit ~/.bashrc
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc
-----------------------------------------------------------python
終端裏cd進cuda示例linux
cd [NVIDIA_CUDA_SAMPLES]/1_Utilities/deviceQueryDrv
sudo make
./deviceQueryDrv #確認輸出了有效的顯卡信息,並記下顯卡算力「CUDA Capability Major/Minor version number:」,編譯框架時會用上
----------------------------------------------------------- git
#複製文件到系統環境
sudo cp [CUDNN]/cuda/include/cudnn.h /usr/local/cuda/include/ sudo cp [CUDNN]/cuda/lib64/lib* /usr/local/cuda/lib64/
#重建軟鏈接
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.[主版本號]
sudo ln -s libcudnn.so.[全版本號] libcudnn.so.[主版本號]
sudo ln -s libcudnn.so.[主版本號] libcudnn.so
#使連接在環境中生效
sudo ldconfig
-----------------------------------------------------------github
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
解壓opencvubuntu
cd [opencv]/build make #這行不建議加-j4,曾出現過由於依賴次序問題引起的編譯錯誤 sudo make install -j4
添加引用變量瀏覽器
sudo gedit /etc/ld.so.conf.d/opencv.conf
文件內寫入bash
/usr/local/lib/x86_64-linux-gnu #(也可能沒有最後這段文件夾路徑,取決於libopencv_XXX.so文件具體在哪)
sudo ldconfig
-----------------------------------------------------------app
-----------------------------------------------------------安裝依賴項框架
sudo apt-get install --no-install-recommends libboost-all-dev sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libopenblas-dev liblapack-dev libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev git cmake build-essential -y
獲取caffe,在但願放置caffe的目錄內:
git clone https://github.com/BVLC/caffe.git
複製caffe/MakeFile.config.example爲MakeFile.config
USE_CUDNN := 1 USE_OPENCV := 1 # Whatever else you find you need goes here. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/include/opencv /usr/local/include/opencv2 /usr/include/hdf5/serial LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial /usr/local/lib/x86_64-linux-gnu
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \ #-gencode arch=compute_20,code=sm_21 \
...
只保留和顯卡算力匹配的幾行,其餘的全註釋掉(顯卡算力詳見[NVIDIA_CUDA_SAMPLES]/1_Utilities/deviceQueryDrv/deviceQueryDrv,在這個文件夾內make以後./deviceQueryDrv運行)
ifeq ($(USE_OPENCV), 1) #( 注意把空格換回製表符) #LIBRARIES += opencv_core opencv_highgui opencv_imgproc #ifeq ($(OPENCV_VERSION), 3) #LIBRARIES += opencv_imgcodecs #endif LIBRARIES += opencv_world endif
make all -j4
#增長引用變量
sudo gedit /etc/ld.so.conf.d/caffe.conf
內容爲:
/usr/local/cuda/lib64
回到終端內:
sudo make install #刷新連接 sudo ldconfig
cd [caffe] sudo sh data/mnist/get_mnist.sh sudo sh examples/mnist/create_mnist.sh sudo sh examples/mnist/train_lenet.sh
不報錯就是安裝成功