转载请注明:http://blog.csdn.net/stdcoutzyx/article/details/39722999

在上一个链接中,我配置了cuda,有强大的GPU,自然不能暴殄天物,让资源白白空暇着,所以配置一下卷积神经网络跑一下程序喽。至于卷积神经网络的原理,容后再写。打算先写库的使用方法,再写原理,以行动带动对理论的追求。

话不多说,步入正题。

1. 预说明

关于cuda-convnet,起源于一篇经典论文①,论文中针对ILSVRC-2010的数据进行实验,然后发布了事实上验使用的代码,链接为②。可是,事实往往跟论文是有差距的,链接②中的代码根本不能重现论文中的结果。在下不才,在使用这个链接的库非常久之后才发现的,认为非常坑,希望后来者慎之。

之所以说它坑,首先,论文中提到特性中,multi-GPU和dropout就没有实现,并且也没有给出论文中8层卷积神经网络的配置文件。总之不能直接拿来用,须要自己探索。

尽管如此,但有总比没有好,毕竟这个库实现的卷积神经网络封装的非常好,论文中的大神的贡献非我等小菜所能企及的。给大神点32个赞。

本文仅仅对cuda-convnet和cuda-convnet2的配置进行说明,论文中的作者还发布了其它版本号的库,尚未用到,故且按下不提。

2. Cuda-convnet配置

2.1. 源代码下载

參考链接②,先将源代码下载下来。

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

取出的版本号是562。

2.2. 安装必要的库

然后,安装必须的库,我使用的是ubuntu系统。所以命令为

sudo apt-get install python-dev python-numpy python-magic python-matplotlib libatlas-base-dev

当然,还要确认你安装了cuda,我安装的是cuda6.5,在/usr/local/文件夹下,例如以下所看到的:

$ ls /usr/local
bin cuda cuda-6.5 etc games include lib man sbin share src

2.3. 更改build.sh

进入到刚才下载的cuda-convnet-read-only文件夹,更改build.sh文件里的配置路径。例如以下所看到的:

# 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 # 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 $*

依照官网的教程,配置完build.sh后就能够进行编译了。可是会错误发生,还须要改例如以下几个地方才干够。

2.4. 头文件加入

直接编译会发生找不到cutil_inline.h头文件的错误。分析原因可能是原来有这个头文件,后来这个头文件的功能被实现到其它头文件里去了。

在include子目录下田间cutil_inline.h文件,并输入内容。

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

2.5. MakeFile文件更改

MakeFile第3行,原文例如以下:

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

加入cuda的路径后例如以下:

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

保存之。

2.6. 最后的库链接错误

做完上述修改后,能够编译了,但到最后会发生一个库链接的错误,不用管,直接将那个库凝视掉。

在common-gcc-cuda-4.0.mk文件的332行。直接用#号凝视。

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

至此,就能够完毕cuda-convnet的编译了。

3. Cuda-convnet2配置

顾名思义,这是cuda-convnet的2.0版本号,支持多GPU执行。

3.1. 源代码下载

git clone https://code.google.com/p/cuda-convnet2/

3.2. 必要的库

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

3.3. 配置

我仅仅能说,这个版本号的比上个版本号人性化多了,这个版本号的build.sh直接如此。

# CUDA toolkit installation directory.
export CUDA_INSTALL_PATH=/usr/local/cuda # 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 # You don't have to change these:
export LD_LIBRARY_PATH=$CUDA_INSTALL_PATH/lib64:$LD_LIBRARY_PATH
export CUDA_SDK_PATH=$CUDA_INSTALL_PATH/samples
export PATH=$PATH:$CUDA_INSTALL_PATH/bin

假设是在ubuntu下的话,这样就直接已经基本把路径都配置对了。

3.4. 链接错误

可是直接编译的话还是会遇到错误,例如以下所看到的:

cd ./bin/ && g++  -O3   -DNUMPY_INTERFACE -shared -Wl,-no-undefined -o libutilpy.so src/matrix.o -L/usr/lib/atlas-base -latlas -lcblas -lpython2.7
/usr/bin/ld: cannot find -latlas
/usr/bin/ld: cannot find -lcblas
collect2: error: ld returned 1 exit status

主要是由于atlas库中没有libatlas.so和libctlas.so。查看atlas的文件夹发现结构如此:

:/usr/lib/atlas-base$ ls -l
总用量 4292
drwxr-xr-x 2 root root 4096 9月 22 11:41 atlas
lrwxrwxrwx 1 root root 15 2月 4 2014 libatlas.so.3 -> libatlas.so.3.0
-rw-r--r-- 1 root root 3746968 2月 4 2014 libatlas.so.3.0
lrwxrwxrwx 1 root root 15 2月 4 2014 libcblas.so.3 -> libcblas.so.3.0
-rw-r--r-- 1 root root 135376 2月 4 2014 libcblas.so.3.0
lrwxrwxrwx 1 root root 17 2月 4 2014 libf77blas.so.3 -> libf77blas.so.3.0
-rw-r--r-- 1 root root 131000 2月 4 2014 libf77blas.so.3.0
lrwxrwxrwx 1 root root 22 2月 4 2014 liblapack_atlas.so.3 -> liblapack_atlas.so.3.0
-rw-r--r-- 1 root root 369472 2月 4 2014 liblapack_atlas.so.3.0

加入两个软链接,运行命令:

sudo ln -s libatlas.so.3.0 libatlas.so
sudo ln -s libcblas.so.3.0 libcblas.so

文件夹结构变为如此:

/usr/lib/atlas-base$ ls -l
总用量 4292
drwxr-xr-x 2 root root 4096 9月 22 11:41 atlas
lrwxrwxrwx 1 root root 15 10月 1 22:35 libatlas.so -> libatlas.so.3.0
lrwxrwxrwx 1 root root 15 2月 4 2014 libatlas.so.3 -> libatlas.so.3.0
-rw-r--r-- 1 root root 3746968 2月 4 2014 libatlas.so.3.0
lrwxrwxrwx 1 root root 15 10月 1 22:36 libcblas.so -> libcblas.so.3.0
lrwxrwxrwx 1 root root 15 2月 4 2014 libcblas.so.3 -> libcblas.so.3.0
-rw-r--r-- 1 root root 135376 2月 4 2014 libcblas.so.3.0
lrwxrwxrwx 1 root root 17 2月 4 2014 libf77blas.so.3 -> libf77blas.so.3.0
-rw-r--r-- 1 root root 131000 2月 4 2014 libf77blas.so.3.0
lrwxrwxrwx 1 root root 22 2月 4 2014 liblapack_atlas.so.3 -> liblapack_atlas.so.3.0
-rw-r--r-- 1 root root 369472 2月 4 2014 liblapack_atlas.so.3.0

然后就能够正常编译了。

參考文献

① ImageNet Classification with Deep Convolutional Neural Networks

② https://code.google.com/p/cuda-convnet

③ https://code.google.com/p/cuda-convnet2

Ubuntu14.04配置cuda-convnet的更多相关文章

  1. Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04 配置参考文献 以及 常见编译问题总结

    Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04  配置参考文献 ---- Wang Xiao Warning: Please make sure the cud ...

  2. Caffe+CUDA8.0+CuDNNv5.1+OpenCV3.1+Ubuntu14.04 配置参考文献 以及 常见编译问题总结

    Caffe + CUDA8.0 + CuDNNv5.1 + OpenCV3.1 + Ubuntu14.04  配置参考文献 ---- Wang Xiao  Anhui University  CVPR ...

  3. Ubuntu14.04配置gcc4.4.4+Qt4.8.4交叉编译环境

    安装32位程序运行支持 sudo apt-get install lib32stdc++6 lib32z1 lib32ncurses5 lib32bz2-1.0 可能报错: lib32stdc++6 ...

  4. ubuntu14.04 配置网络

    ubuntu14.04 配置网络的练习 本文参考的资料: https://blog.csdn.net/liu782726344/article/details/52912797. 感谢作者的分享! 打 ...

  5. ubuntu14.04安装cuda

    1 装系统时候注意,另外14.04要好于12.04,自带了无线驱动 ubuntu14.04安装完不要update 2 安装cuda和cudnn http://blog.csdn.net/l297969 ...

  6. ubuntu14.04 安装 CUDA 7.5 / CUDA 8.0

    原文转自:http://blog.csdn.net/masa_fish/article/details/51882183 CUDA7.5和CUDA8.0的安装过程是一毛一样的.所以如果安装CUDA8. ...

  7. Ubuntu14.04配置Mono+Jexus

    总所周知,ASP.NET是微软公司的一项技术,是一个网站服务端开发的一种技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们,就是所谓动态网站开发,它依赖运行于 IIS 之中的程序 .但 ...

  8. ubuntu14.04 配置中文输入法

    ubuntu14.04自带中文输入法,只要配置就可以了. 1.安装中文支持 System Settings -->  Language Support 点击 install/remove lan ...

  9. ubuntu14.04配置中文latex完美环境(texlive+texmaker+lyx)

    Ubuntu下的文档编辑虽然有libreoffice,但对中文和公式的排版始终不如ms office,因此要想写出高质量的文档,只能靠latex了,现在随着xeCjk的开发,中文文档在ubuntu下的 ...

  10. 64位ubuntu14.04配置adb后提示没有那个文件或目录

    1.配置完adb环境变量后在终端输入adb: ameyume@ameyume-HP-450-Notebook-PC:~$ adb /home/ameyume/adt-bundle-linux-x86_ ...

随机推荐

  1. Sftp和ftp 差别、工作原理等(汇总ing)

    Sftp和ftp over ssh2的差别 近期使用SecureFx,涉及了两个不同的安全文件传输协议: -sftp -ftp over SSH2 这两种协议是不同的.sftp是ssh内含的协议,仅仅 ...

  2. html的空格显示距离问题

    一.使用全角空格 全角空格被解释为汉字,所以不会被被解释为HTML分隔符,可以按照实际的空格数显示. 二.使用空格的替代符号 替代符号就是在需要显示空格的地方加入替代符号,这些符号会被浏览器解释为空格 ...

  3. win7 安装vs2010报错 Error code -939523550 for this component is not recognizedHi

    When i try to install VS2010, Its not installing. I'm getting an error.  It just try to install the ...

  4. cobar和tddl分享

    Cobar是阿里巴巴(B2B)部门开发的一种关系型数据的分布式处理系统,它可以在分布式的环境下看上去像传统数据库一样为您提供海量数据服务.那么具体说说我们为什么要用它,或说cobar--能干什么?以下 ...

  5. BZOJ4006 JLOI2015 管道连接(斯坦纳树生成森林)

    4006: [JLOI2015]管道连接 Time Limit: 30 Sec Memory Limit: 128 MB Description 小铭铭最近进入了某情报部门,该部门正在被如何建立安全的 ...

  6. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

  7. libcurl下载文件简易demo

    size_t test_save(void *ptr, size_t size, size_t nmemb, void *stream) { size_t sizes = size * nmemb; ...

  8. Oracle11g R2学习系列 之九 PL/SQL语言

    这是个重头戏,如果精通了PL/SQL,毫不夸张的说明精通了Oracle了.PL/SQL由以下三个部分组成(Definition,Manipulation,Control): DDL:数据定义语言,Cr ...

  9. javascript的prototype原理理解

    prototype是函数的内置属性,每一个function都拥有这样一个属性,在js的面向对象编程上,prototype发挥着强大的作用. 某天,春哥问我你知道prototype的原理吗?我突然懵了, ...

  10. jquery mobile转场时加载js失效

    jquery mobile拦截了所有的http请求,并使用ajax请求取代传统的http.请求发出后,框架会将请求的内容插入到页面中data- role="page"的部分,取代原 ...