CAFFE的matlab接口测试
配置好Caffe运行所需要的环境变量,如何配置参见
下面参考http://blog.****.net/zpp1994/article/details/53142371?locationNum=1&fps=1,记录如何通过caffe带的DEMO,给出一个测试例子。
在matlab中打开classification_demo.m(../caffe/matlab/demo/),自己在该目录下编写一个test.m(test.m为stu-zhang:http://blog.****.net/zpp1994/article/ details/53142371?locationNum=1&fps=1编写)。
- clear
- clc
- im = imread('C:/Caffe/caffe/examples/images/cat.jpg');% read a picture
- [scores, maxlabel] = classification_demo(im, 0);%get the scores; second parameter is 0 meant using CPU only;
- maxlabel;% inspect the lable maxlikehood;
- figure;
- x=[1:1000];
- plot(x,scores);% plot the scores
- axis([1, 1000, -0.1, 0.5]);% range of X and Y axis
- grid on % add grid
- hold on
- plot(maxlabel,max(scores),'r*');
- jieguo=strcat(num2str(maxlabel),',');
- jieguo=strcat(jieguo,num2str(max(scores)));
- text(im2double(maxlabel)+20,im2double(max(scores)),jieguo);
- % [maxv,maxl]=findpeaks(im2double(scores),'minpeakdistance',1);
- % plot(maxl,maxv,'*','color','R'); %??????
- fid = fopen('C:/Caffe/caffe/data/ilsvrc12/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)% display label info in command widnow
- break
- end
- end
- figure;imshow(im);% shou picture
- str=strcat('result of classification:',lin);
- title(str);
运行test.m,结果如下: