`

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了,反正我入个门,学习嘛。

 

 


 

  • 大小: 10.4 KB
  • 大小: 167.6 KB
  • 大小: 67 KB
  • 大小: 41.6 KB
  • 大小: 61.4 KB
  • 大小: 82.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics