Windows玩转Caffe(四): 配置Matlab接口之可视化初探
来源:互联网 发布:webgis python 编辑:程序博客网 时间:2024/05/16 12:26
欲练此功,必先自攻《Windows玩转Caffe(一):Win10+VS2013+Caffe配置详解【附:多图】》http://blog.csdn.net/u012958854/article/details/78123610
1. 下载Matlab,并安装
本人安装的Matlab2015b,下载地址:http://jingyan.baidu.com/article/eae07827a466a31fed548563.html
2. 修改配置,编译matcaffe
打开CommonSettings.props,编辑要点:
<!-- NOTE: If Matlab support is enabled, MatlabDir (below) needs to be
set to the root of your Matlab installation. -->
<MatlabSupport>true</MatlabSupport>
<PropertyGroup Condition="'$(MatlabSupport)'=='true'">
<MatlabDir>D:\Program Files\MATLAB\R2015b</MatlabDir>
<LibraryPath>$(MatlabDir)\extern\lib\win64\microsoft;$(LibraryPath)</LibraryPath>
<IncludePath>$(MatlabDir)\extern\include;$(MatlabDir)\toolbox\distcomp\gpu\extern\include;$(IncludePath)</IncludePath>
</PropertyGroup>
(详见http://blog.csdn.net/u012958854/article/details/78123610)
编译matcaffe工程,在caffe-master\Build\x64\Release下将生成matcaffe文件夹。
3. 修改classification_demo.m
打开caffe-master\matlab\democlassification_demo.m文件,编辑要点:
% Add caffe/matlab to you Matlab search PATH to use matcaffe
if exist('../+caffe', 'dir')
addpath('../../Build/x64/Release/matcaffe');
else
error('Please run this demo from caffe/matlab/demo');
end
上面红色字体的路径很眼熟吧,即上步刚生成的,此处相对路径写法而已。
4. 打开Matlab,运行指令
前提,把Matlab当前文件夹设置为caffe-master\matlab\demo目录。
4.1 加载测试图片并显示
>> im =imread('../../examples/images/cat.jpg');%读取图片cat.jpg
>>figure;imshow(im);%显示图片
4.2 调用分类demo,查看最大标签
>>[scores, maxlabel] = classification_demo(im, 1);%获取得分第二个参数0为CPU,1为GPU
时间已过 0.022875 秒。
时间已过 0.190251 秒。
Cleared 0solvers and 1 stand-alone nets
>>maxlabel %查看最大标签
maxlabel =
282
4.3 画出分类得分,即可视化
>>figure;plot(scores);%画出得分情况
axis([0, 1000,0, 0.5]);%坐标轴范围
grid on %显示网格
4.4 根据最大标签解析出图片类别
>> fid =fopen('../../models/bvlc_reference_caffenet/synset_words.txt', 'r');
i=0;
while~feof(fid)
i=i+1;
lin = fgetl(fid);
lin = strtrim(lin);
if(i==maxlabel)
fprintf('the label of %d is%s\n',i,lin)
break
end
end
the label of 282is n02123045 tabby, tabby cat
分类结果tabby,tabby cat正确,至此可视化初探基本完成。
上述四步命令可以写成一个.m文件:
clear clc im = imread('../../examples/images/cat.jpg');%读取图片cat.jpgfigure;imshow(im);%显示图片 [scores, maxlabel] = classification_demo(im, 1);%获取得分第二个参数0为CPU,1为GPU maxlabel %查看最大标签 //y: fprintf('maxlabel = %d\n', maxlabel);figure;plot(scores);%画出得分情况 axis([0, 1000, 0, 0.5]);%坐标轴范围 grid on %显示网格 fid = fopen('../../models/bvlc_reference_caffenet/synset_words.txt', 'r'); i=0; while ~feof(fid) i=i+1; lin = fgetl(fid); lin = strtrim(lin); if(i==maxlabel) fprintf('the label of %d is %s\n',i,lin) break end end
运行结果:
ps: 标签文件synset_words.txt在我的上传资源中有下载,不知为何资源分不能选择0,起步2,5,8,。。。
- Windows玩转Caffe(四): 配置Matlab接口之可视化初探
- caffe for windows的matlab接口(四):权重和特征图可视化的一个例子
- 【caffe-Windows】微软官方caffe之 matlab接口配置
- 【caffe-Windows】微软官方caffe之 matlab接口配置
- 【caffe-windows】 caffe-master 之 matlab接口配置
- 【caffe-Windows】微软官方caffe之 matlab接口配置
- 【caffe-Windows】微软官方caffe之 matlab接口cpu配置
- 【caffe-Windows】win caffe之 matlab接口配置
- caffe-windows matlab 接口配置
- windows caffe matlab 可视化
- Windows玩转Caffe(五): mnist模型可视化探知,Matlab绘制其Accuracy和Loss曲线
- 深度学习Caffe实战笔记(10)Windows Caffe使用MATLAB接口提取和可视化特征
- caffe matlab接口特征可视化
- 【caffe-windows】 caffe-master 之 卷积核可视化(利用matlab)
- caffe-windows配置python和matlab接口
- Windows下为Caffe配置matlab接口
- windows caffe(仅CPU) 配置matlab接口
- caffe for windows的matlab接口(三):权重和特征图的可视化
- C/C++宏定义中的#和##
- codefirces 420e(强连通分量)
- pyQt5-控件2
- MIT18.06线性代数课程笔记10:column space、row space、null space、left null space
- 深蓝的大修&现代化改装(二):树状数组
- Windows玩转Caffe(四): 配置Matlab接口之可视化初探
- DevExpress控件XtraTreeList的使用心得
- 【nginx】nginx反向代理请求响应报文大数据量时的json报文返回不完整
- hadoop编程(2)-准备编程和本地测试环境
- (四)spring配置bean的作用域
- Maya2016中MStatus中的改变
- Cg语言中文说明文档(四)
- Docker私有仓库镜像上传下载
- Log日志小结