天天看點

Ubuntu 14.04安裝convnetUbuntu 14.04安裝convnet

Ubuntu 14.04安裝convnet

前一段時間由于畢設需要用到

cNNs

,是以在Ubuntu上安裝了convnet(需翻牆)和caffe,現在将網上的幾篇教程進行整理,友善以後查閱。一開始我安裝的是convnet2(需翻牆),但是在訓練時有錯誤,電腦環境是GTX 750,檢視項目首頁的評論時發現以下原因:

Comment by neuroc..,@gmail.com, Oct 21, 2014To: [email protected]

As you can see from our previous comment (the one just above the one about GENCODE flags), we have the same error as you do in nvmatrix.cu:1473

We have since then determined that it is a BUG from NVIDIA. It seems that texture objects do not work as they should with GPUs of compute capability (cc) higher than 3.5 (both our GTX 750 and your GTX 750 Ti are cc 5.0).

We have reported the BUG through Nvidia developper environment and they have confirmed it is indeed a BUG (they reproduced it). So we just have to wait till they solve it.

We will comment here if there are any further developments (when they solve the bug for example)

是以不得不安裝

convnet

。如果需要

dropout

,可以去這裡。

convnet配置

安裝nvidia顯示卡驅動

  1. 先去官網下載下傳最新版的驅動。
  2. 如果以前安裝過驅動,需要先移除
    sudo apt-get remove nvidia* && sudo apt-get autoremove
               
  3. 然後執行
    gksudo gedit /etc/modprobe.d/blacklist-nouveau.conf
               
  4. 在檔案末尾添加
    blacklist nouveau
    blacklist lbm-nouveau
    options nouveau modeset=0
    alias nouveau off
    alias lbm-nouveau off
               
  5. 重新開機電腦,在登陸界面(假設需要密碼登陸),按

    Ctrl+Alt+F1

    進去字元界面,用自己的使用者名和密碼登入。
  6. 用下列指令關閉diaplay manager和X server
    sudo stop lightdm
               
    如果你沒有使用lightdm,可能要用其他的指令。
  7. 然後運作安裝程式
    sudo sh NVIDIA-Linux-x86_64.....run
               
  8. 安裝好以後重新開機,輸入下面的指令儲存設定
    sudo nvidia-xconfig
               

安裝必要的庫

sudo apt-get install python-dev python-numpy python-scipy python-magic python-matplotlib libatlas-base-dev libjpeg-dev libopencv-dev git
           

下載下傳源碼

svn checkout http://cuda-convnet.googlecode.com/svn/trunk/ cuda-convnet-read-only
           

安裝CUDA

這裡通過添加軟體源進行安裝,下載下傳deb包,如果你的ubuntu版本不是14.04可以前往這裡找到對應版本的deb包。例如我們這裡是cuda-repo-ubuntu1404_6.5-14_amd64.deb

。在deb包所在的檔案夾執行如下指令:

sudp dpkg -i cuda-repo-ubuntu1404_6.5-14_amd64.deb
sudo apt-get update
sudo apt-get install cuda
           

安裝好以後應該在/usr/local目錄下看到cuda-6.5的檔案夾。

在/etc/profile添加環境變量:

PATH=/usr/local/cuda-6.5/bin:$PATH
export PATH
           

儲存好以後,執行下列指令:

source /etc/profile
           

在/etc/ld.so.conf.d/加入檔案cuda.conf,檔案的内容為:

/usr/local/cuda-6.5/lib64
           

接着執行下面的指令:

sudo ldconfig
           

安裝CUDA SAMPLE

安裝依賴包:

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa-dev
           

編譯sample檔案夾:

cd /usr/local/cuda-6.5/samples
sudo make
           

編譯完成後,進入samples/bin/x86_64/linux/release,運作:

sudo ./deviceQuery
           

出現類似下面的資訊就說明驅動及顯示卡安裝成功。

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 670"
  CUDA Driver Version / Runtime Version          6.5 / 6.5
  CUDA Capability Major/Minor version number:    3.0
  Total amount of global memory:                 4095 MBytes (4294246400 bytes)
  ( 7) Multiprocessors, (192) CUDA Cores/MP:     1344 CUDA Cores
  GPU Clock rate:                                1098 MHz (1.10 GHz)
  Memory Clock rate:                             3105 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 524288 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Bus ID / PCI location ID:           1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 6.5, CUDA Runtime Version = 6.5, NumDevs = 1, Device0 = GeForce GTX 670
Result = PASS
           

更改build.sh

進入下載下傳的convnet的源碼的檔案夾cuda-convnet-read-only,更改build.sh檔案中的配置路徑。

#!/bin/sh

# Fill in these environment variables.
# I have tested this code with CUDA 4.0, 4.1, and 4.2. 
# Only use Fermi-generation cards. Older cards won't work.

# If you're not sure what these paths should be, 
# you can use the find command to try to locate them.
# For example, NUMPY_INCLUDE_PATH contains the file
# arrayobject.h. So you can search for it like this:
# 
# find /usr -name arrayobject.h
# 
# (it'll almost certainly be under /usr)

# CUDA toolkit installation directory.
export CUDA_INSTALL_PATH=/usr/local/cuda

# CUDA SDK installation directory.
export CUDA_SDK_PATH=/usr/local/cuda-6.5/samples/common/inc #/home/spoon/NVIDIA_GPU_Computing_SDK

# Python include directory. This should contain the file Python.h, among others.
export PYTHON_INCLUDE_PATH=/usr/include/python2.7

# Numpy include directory. This should contain the file arrayobject.h, among others.
export NUMPY_INCLUDE_PATH=/usr/lib/python2.7/dist-packages/numpy/core/include/numpy  
# ATLAS library directory. This should contain the file libcblas.so, among others.
export ATLAS_LIB_PATH=/usr/lib/atlas-base

make $*
           

添加頭檔案

在convnet源碼檔案夾中的include檔案夾添加頭檔案cutil_inline.h,并在頭檔案中加入下面的内容:

#include "helper_cuda.h" 
    #define cutilCheckMsg(a) getLastCudaError(a) 
    #define cutGetMaxGflopsDeviceId() gpuGetMaxGflopsDeviceId() 
    #define MIN(a,b) (a) < (b) ? (a) : (b) 
           

Makefile檔案更改

将Makefile檔案中将下面的代碼:

INCLUDES :=  -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I./include -I./include/common -I./include/cudaconv2 -I./include/nvmatrix  
           

更改為:

INCLUDES :=  -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I$(CUDA_SDK_PATH) -I./include -I./include/common -I./include/cudaconv2 -I./include/nvmatrix  
           

運作build.sh

sudo sh build.sh
           

最後會發生一個庫連結的錯誤,直接将那個庫注釋掉就行了。

在common-gcc-cuda-4.0.mk檔案的332行,直接用#注釋:

# LIB += -lcutil_$(LIB_ARCH) $(LIBSUFFIX) -lshrutil_$(LIB_ARCH) $(LIBSUFFIX)  
           

如果在

./bin/linux/release/路徑下生成_ConvNet.so,即表明配置成功。

參考資料:

http://blog.itpub.net/16582684/viewspace-1254584

http://blog.csdn.net/shaoxiaohu1/article/details/20569769

http://www.linuxidc.com/Linux/2014-10/107500.htm

http://www.cnblogs.com/platero/p/3993877.html