Deep Learning 學習總結(一)—— Caffe Ubuntu14.04 CUDA 6.5 配置

Caffe (Convolution Architecture For Feature Extraction)做爲深度學習CNN一個很是火的框架,對於初學者來講,搭建Linux下的Caffe平臺是學習深度學習關鍵的一步,其過程也比較繁瑣,回想起當初折騰的那幾天,遂總結一下Ubuntu14.04的配置過程,方便之後新手能在此少走彎路。python

1. 安裝build-essentialslinux

安裝開發所須要的一些基本包git

   1: sudo apt-get install build-essential

2. 安裝NVIDIA驅動github

輸入下列命令添加驅動源shell

   1: sudo add-apt-repository ppa:xorg-edgers/ppa
   2: sudo apt-get update

安裝340版本驅動(具體版本取決於電腦顯卡的型號,詳細可到NVIDIA官網查看)ubuntu

   1: sudo apt-get install nvidia-340

安裝完成後,繼續安裝下列包bash

   1: sudo apt-get install nvidia-340-uvm

安裝驅動完畢,reboot.app

3. 安裝CUDA 6.5框架

CUDA的Deb包安裝較爲簡單,按照官網流程,事先安裝必要的庫學習

   1: sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

3.1 安裝CUDA

而後經過如下命令獲取Ubuntu 14.04 CUDA相關的repository package

   1: $ sudo dpkg -i cuda-repo-ubuntu1404_6.5-14_amd64.deb 
   2: $ sudo apt-get update

而後開始安裝CUDA Toolkit

   1: $ sudo apt-get install cuda

此時須要下載較長時間,網速較慢的中途能夠出去吃個飯~

3.2 環境配置

CUDA安裝完畢後,須要對.bashrc加入一下命令來配置環境

   
   
   
   
   1: export CUDA_HOME=/usr/local/cuda-6.5 
   2: export LD_LIBRARY_PATH=${CUDA_HOME}/lib64 
 
   
   
   
   
   1: PATH=${CUDA_HOME}/bin:${PATH} 
   2: export PATH

3.3 安裝CUDA SAMPLE

經過複製SDK samples 到主目錄下,完成整個編譯過程

   1: $ cuda-install-samples-6.5.sh  ~ 
   2: $ cd ~/NVIDIA_CUDA-6.5_Samples 
   3: $ make

若是以上過程都成功後,能夠經過運行bin/x86_64/linux/release 下的deviceQuery來驗證一下。若是出現如下信息,則說明驅動以及顯卡安裝成功


   
   
   
   
   1: ./deviceQuery Starting...
   2:  
   3:  CUDA Device Query (Runtime API) version (CUDART static linking)
   4:  
   5: Detected 1 CUDA Capable device(s)
   6:  
   7: Device 0: "GeForce GTX 670"
   8:   CUDA Driver Version / Runtime Version          6.5 / 6.5
   9:   CUDA Capability Major/Minor version number:    3.0
  10:   Total amount of global memory:                 4095 MBytes (4294246400 bytes)
  11:   ( 7) Multiprocessors, (192) CUDA Cores/MP:     1344 CUDA Cores
  12:   GPU Clock rate:                                1098 MHz (1.10 GHz)
  13:   Memory Clock rate:                             3105 Mhz
  14:   Memory Bus Width:                              256-bit
  15:   L2 Cache Size:                                 524288 bytes
  16:   Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  17:   Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  18:   Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  19:   Total amount of constant memory:               65536 bytes
  20:   Total amount of shared memory per block:       49152 bytes
  21:   Total number of registers available per block: 65536
  22:   Warp size:                                     32
  23:   Maximum number of threads per multiprocessor:  2048
  24:   Maximum number of threads per block:           1024
  25:   Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  26:   Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  27:   Maximum memory pitch:                          2147483647 bytes
  28:   Texture alignment:                             512 bytes
  29:   Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  30:   Run time limit on kernels:                     Yes
  31:   Integrated GPU sharing Host Memory:            No
  32:   Support host page-locked memory mapping:       Yes
  33:   Alignment requirement for Surfaces:            Yes
  34:   Device has ECC support:                        Disabled
  35:   Device supports Unified Addressing (UVA):      Yes
  36:   Device PCI Bus ID / PCI location ID:           1 / 0
  37:   Compute Mode:
  38:      < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
  39:  
  40: deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 6.5, CUDA Runtime Version = 6.5, NumDevs = 1, Device0 = GeForce GTX 670
  41: Result = PASS

4. 安裝BLAS

Caffe的BLAS能夠有三種選擇,分別爲atlas、mkl以及openBLAS。對於mkl能夠到intel官網下載,解壓完成後又一個install_GUI.sh文件,執行該文件會出現圖形安裝界面,根聽說明一步一步執行便可。

也可對openBLAS源碼進行編譯,不過須要gcc以及gfortran等相關編譯器。我的認爲比較便捷的是atlas,在Caffe官網上有相關的介紹,對於Ubuntu,經過如下命令能夠下載atlas

   1: sudo apt-get install libatlas-base-dev

5. 安裝OpenCV

OpenCV庫安裝能夠經過網上寫好的腳本進行下載:https://github.com/jayrambhia/Install-OpenCV

解壓文檔後,進入Ubuntu/2.4 給全部的shell腳本加上可執行權限

   1: chmod +x *.sh

而後執行 opencv2_4_9.sh 安裝最新版本,注意,OpenCV 2.4.9不支持gcc-4.9以上的編譯器!!

 

6. 安裝其餘dependencies

對於Ubuntu 14.04,執行如下命令下載其餘相關依賴庫文件

   1: sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev
   2: sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

7. 安裝python以及Matlab

首先安裝pip和python –dev

   1: sudo apt-get install python-dev python-pip

以及caffe python wrapper所須要的額外包

   1: sudo pip install -r /path/to/caffe/python/requirements.txt

Matlab接口須要額外安裝Matlab程序

 

Last shot --- 編譯Caffe

完成全部的環境配置,終於能夠編譯caffe了,經過官網下載caffe源碼,進入根目錄caffe-master,首先複製一份makefile

   1: cp Makefile.config.example Makefile.config

而後修改裏面的內容,主要有:

CPU_ONLY   是否採用cpu模式,不然選擇CUDNN(這裏的CUDNN須要在NVIDIA-CUDNN下載,還有經過email註冊申請才能經過審覈)

BLAS:=atlas(也能夠是open或者mkl)

DEBUG  若是須要debug模式

MATLAB_DIR 若是須要採用matlab 接口

完成配置後,能夠進行編譯了

   1: make all -j4
   2: make test
   3: make runtest

最後若是都能正常,證實caffe裏面全部的例子程序均可以運行了,放心都跑CIFAR、MNIST以及ImageNet吧~~

相關文章
相關標籤/搜索