天天看点

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