Matconvnet安装

  本文主要介绍Linux下Matconvnet的安装注意事项。

  最近帮老师校验一份超分的代码,用到了matconvnet深度学习工具包。代码里面使用的是Matconvnet-1.0-beta20版本, Matlab版本为2017。

在编译过程中遇到了个坑,先记录一下~

       先说一下大家下载这种工具包最好是去官网下载,起初我下载的是CSDN中有人分享的包,结果报错了~~~提示说-ljpeg找不到,然而是按照官网装好了libjpeg包的。

紧接着在后面运行程序时,就出bug了

        还在网上找了好多博客看,最后还是老老实实在官网重新下了Matconvnet-1.0-beta20的工具包。真是被自己蠢哭~

       Matconvnet工具包下载地址: http://www.vlfeat.org/matconvnet/download/ (根据需要选择不同版本的工具包,我下载的是Matconvnet-1.0-beta20版本)

  首先,按照Matconvnet官网的安装过程来。(http://www.vlfeat.org/matconvnet/install/)安装需要的gcc,CUDA等

将下载的Matconvnet解压到指定目录。然后对其进行编译,先进行CPU版本的编译。在Matlab中打开Matconvnet工具包,使得当前目录窗口显示Matconvnet文件夹里面的子目录。

然后在命令行输入 

>>> mex -setup
>>> mex -setup C++
>>> addpath matlab
>>> vl_compilenn

由此完成CPU 下matconvnet的编译。

        接着进行GPU下的编译。

vl_compilenn('enableGpu', true, 'cudaRoot', '/usr/local/CUDA-8.0', 'cudaMethod', 'nvcc')

然后就报错了~~~主要有以下两个问题,主要参考 http://www.mamicode.com/info-detail-2225605.html 这篇博客中的解决方法得以解决。

  

  这个是因为cuda 8 之后不支持compute_20 了,最低也是compute_30了。 所以需要将vl_compilenn.m中的以下代码进行修改

opts.defCudaArch = [...
‘-gencode=arch=compute_20,code=\"sm_20,compute_20\" ‘...
‘-gencode=arch=compute_30,code=\"sm_30,compute_30\"‘];

我用的是服务器Tesla k40m, 此处修改成

opts.defCudaArch = [...
‘-gencode=arch=compute_30,code=\"sm_30,compute_30\" ‘...
‘-gencode=arch=compute_50,code=\"sm_50,compute_50\"‘];

同时还需要将 matconvnet/matlab/src/config/mex_CUDA_glnxa64.xml 里对应的地方也进行修改 

NVCCFLAGS="-D_FORCE_INLINES -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS"

修改为:

NVCCFLAGS="-D_FORCE_INLINES -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_50,code=\"sm_50,compute_50\" $NVCC_FLAGS"

  这个的原因是CUDA6.0 后定义了atomicAdd 所以会出现重复定义的错误。 一共有两个文件里存在这个重复定义的问题,分别在

  pooling_gpu.cu, line 163
  (commented out atomicadd)

  bilinearsampler_gpu.cu, line 25
  (commented out atomicadd)

       这个问题的解决方式是在这两个文件里定义如下的宏

#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600
#else
<... place here your own pre-pascal atomicAdd definition ...>
#endif

将如上的定义复制到如上文件里的头部, 将文件里定义的atomicadd function 剪切放在<... place here your own pre-pascal atomicAdd definition ...> 中。比如:

   另外 https://www.cnblogs.com/wangxiaocvpr/p/5385961.html 博客中第29点提到解决该问题的方法是Matconvnet版本较老,换一个较新版本。该方法试过,也是可行的。

        最后,对编译好的Matconvnet进行测试。

>>> run matlab/vl_setupnn
>>> vl_testnn

以及测试GPU下的是否正确

>>> vl_testnn('gpu', true)

 

大功告成,编译成功啦~

posted @ 2018-04-01 15:40  有梦放飞  Views(7315)  Comments(0Edit  收藏  举报