win10+GPU+MATLAB+MatConvNet配置

本文参考http://www.vlfeat.org/matconvnet/install/https://github.com/peiyunh/tinyhttp://blog.csdn.net/wd1603926823/article/details/52370278

@article{hu2016finding,
  title={Finding Tiny Faces},
  author={Hu, Peiyun and Ramanan, Deva},
  journal={arXiv preprint arXiv:1612.04402},
  year={2016}
}

1、首先根据自己的英伟达型号去官网下载对应的英伟达驱动

我的是gtx1050,计算能力是6.1,在默认路径下安装。

2、根据自己安装的matlab版本,下载最新的对应cuda


一定要下载对应matlab版本的cuda,一开始我安装最新cuda8.0出错了,我的matlab是R2016a,重新安装了最新的cuda7.5,安装在默认路径下。

3、配置VS2013+cuda7.5

具体参考http://blog.csdn.NET/listening5/article/details/50240147

4、安装matconvnet

我用来做人脸检测,所以这里配置了Finding Tiny Faces

(1)首先下载tiny

git clone git@github.com:MarleyLee/tiny.git
(2)CPU编译  两个命令: 

mex -setup 
vl_compilenn 
编译完之后会多了一个mex文件夹,在matlab文件夹下面




编译完之后应该有除了cudnn64_4.dll外的mexw64文件,可以看出,这些文件主要是vl_conv,vl_imreadjpeg等。这些文件是由cuda C写的,并不是由MATLAB语言写的,格式是 xx.cu。然后通过mex将这些.cu文件编译成可以由MATLAB调用的函数,也就是说mexw64就相当于MATLAB的函数文件xx.m一样了。你可以看看MATLAB下面的vl_nnconv.m,可以看到文件里面全部都是注释,这样的话,调用时咋运行的啊。原来要先编译,编译好了多了mex文件,调用时是调用mexw64文件啊。这里的cudnn64_4.dll是后面用gpu编译时用到的。

(3)GPU编译

增加cudnn,cudnn是专门针对深度学习的一个加速框架。 

下载对应cuda版本的cudnn,建一个local文件夹,然后把cudnn放进去,再复制到matconvnet目录下。
将自己下载的local文件夹下的cudnn文件夹下的\cuda\include下的cudnn.h复制粘贴到你所装的CUDA根目录下的\include下(网上有说,对应的lib和bin文件夹中的文件也要这样做)。
把bin下的cudnn64_4.dll再复制到mex的文件夹下。
cd matconvnet/;
>> addpath matlab/; 
>> vl_compilenn('enableImreadJpeg', true, 'enableGpu', true, 'cudaRoot', [cuda_dir],...
                'cudaMethod', 'nvcc', 'enableCudnn', true, 'cudnnRoot', [cudnn_dir]);
我按照自己的目录改后是这样:vl_compilenn('enableGpu',true,'cudaRoot','C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5' ,'nvcc','enableCudnn',true,'cudnnRoot','.local\cudnn-v6');
出错,说不支持计算能力61,在这里卡了两天。计算能力要设定为10的倍根据自己的机器计算能力设定最接近的10的倍数,我的是61,应该设定60,但是报错,这里我设定50,如图  arch_code = '50';

 
  
运行 vl_compilenn('enableGpu',true,'cudaRoot','C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5','nvcc','enableCudnn','true','cudnnRoot','.local\cudnn-v6');

依然报错

此处下的解决方案仅供尝试,主要是不用cudnn加速编译,或者是指定路径编译,万一有效呢!

Assuming that there is only a single copy of the CUDA toolkit installed in your system and that it matches MATLAB's version, compile the library with:

> vl_compilenn('enableGpu', true)

If you have multiple versions of the CUDA toolkit, or if the script cannot find the toolkit for any reason, specify the path to the CUDA toolkit explicitly. For example, on macOS this may look like:

> vl_compilenn('enableGpu', true, 'cudaRoot', 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5')

MatConvNet can be compiled to use a more recent version of the CUDA toolkit than the one officially supported by MATLAB. While this may cause unforeseen issues (although none is known so far), it is necessary to use recent libraries such as cuDNN.

Compiling with a newer version of CUDA requires using the cudaMethod,nvcc option. For example, on macOS this may look like:

> vl_compilenn('enableGpu', true, ...
               'cudaRoot', 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5', ...
               'cudaMethod', 'nvcc')

Use vl_compilenn with the cudnnEnable,true option to compile the library; do not forget to use cudaMethod,nvcc as, at it is likely, the CUDA toolkit version is newer than MATLAB's CUDA toolkit. For example, on macOS this may look like:

> vl_compilenn('enableGpu', true, ...
               'cudaRoot', 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5', ...
               'cudaMethod', 'nvcc', ...
               'enableCudnn', true, ...
               'cudnnRoot', 'local/cudnn-rc4') ;

Using MATLAB 2016a, CUDA 7.5, and cuDNN v6:

> vl_compilenn('enableGpu', true, ...
               'cudaMethod', 'nvcc', ...
               'cudaRoot', '/opt/local/cuda-7.5', ...
               'enableCudnn', true, ...
               'cudnnRoot', 'local/cudnn-v6') ;

自己对应上面的vl_compilenn合理设置参数,然后可以成功编译。


如果无效,报错如下:

nnconv_cudnn.cu出现问题,不要改源文件,文件没问题,也不建议参考网上改什么类似temp环境变量,改来改去错误越来越多,这里我猜想是cudnn出现了问题,我尝试下载了cuda7.5-cudnn-v5.1代替原先的cuda7.5-cudnn-v6,然后成功的编译。可以发现这是对应cudnn版本不匹配问题,可以发现配置环境,发现匹配的版本是多么重要!!!

(4)运行测试

vl_testnn('gpu', true);  % vl_testnn('gpu', false) for cpu-only 

(5)Compile our MEX function in MATLAB:

>> cd utils/;
>> compile_mex; 
(6)Demo

 bboxes = tiny_face_detector('data/demo/selfie.jpg', './selfie.png', 0.5, 0.1, 1)
运行成功,说明配置成功。




  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值