BVLC官版caffe在win10x64下搭建matlab2016a支持库

1,安装MATLAB2016A,添加环境变量:


 注意添加最后一行,不然vs2015编译caffe的matlab支持库,会报找不到libmx.dll的警告。

 

2,修改caffe-windows\scripts\build_win.cmd,设置:BUILD_MATLAB=1

 

3,运行build_win.cmd后,用vs2015打开caffe-windows\scripts\build\Caffe.sln,编译matlab支持库:

 

 

4,支持库生成在caffe-windows\matlab目录下,但是由于是通过vs2015编译的matlab库支持,需要把文件:

caffe-windows\matlab\+caffe\private\Release\caffe_.mexw64

 

移动到

caffe-windows\matlab\+caffe\private\caffe_.mexw64

 

否则在matlab中就会报:

>> test
未定义函数或变量 'caffe_'。

 

5,第一次运行,在caffe-windows\matlab\demo目录下创建test.m,并把matlab的当前文件夹移动到caffe-windows\matlab\demo:


 

 test.m代码:

im = imread('D:/caffe-windows/examples/images/cat.jpg');
scores = classification_demo(im, 0);
[score, class] = max(scores);
fprintf('The max score: %f. and The class is %d. \n', score, class);
disp(caffe.version())

 

6,可能会出现:

警告: 执行 'caffe.Net' 类析构函数时,捕获到以下错误:
Could not convert handle to pointer due to invalid init_key. The object might have been cleared. 
> In classification_demo (line 59)
  In test (line 2) 

 需要修改:caffe-windows\matlab\+caffe\Net.m,第72行:

将:

    function delete (self)
      if ~isempty(self.hNet_self)
        caffe_('delete_net', self.hNet_self);
      end
    end

 改为:

    function delete (self)
      if self.isvalid
        caffe_('delete_net', self.hNet_self);
      end
    end

 

 

7,使用classification_demo.m作为示例,注意第二个参数,我编译的是CPU版本,如果启用GPU版本,Matlab2016a会崩溃。

function [scores, maxlabel] = classification_demo(im, use_gpu)

 

8,classification_demo.m会自动添加扩展库的路径到环境中,所以必须要在caffe-windows\matlab\demo下使用。

% Add caffe/matlab to your Matlab search PATH in order to use matcaffe
if exist('../+caffe', 'dir')
  addpath('..');
else
  error('Please run this demo from caffe/matlab/demo');
end

 

如果在其它目录,要引入caffe支持库,需要添加设置路径:



 

 

好久没有使用Matlab了,坑了一天。网上在windows下全是微软版caffe。其实这两天安装BVLC版windows的caffe,感觉还好,并不难装,而且也是2~3年前的东西了。

https://github.com/BVLC/caffe/tree/windows

 

似乎现在都没人使用caffe了,反正我入个门,学习嘛。

 

 


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值