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编写)。

  1. clear
  2. clc  


  3. im = imread('C:/Caffe/caffe/examples/images/cat.jpg');% read a picture 


  4. [scores, maxlabel] = classification_demo(im, 0);%get the scores; second parameter is 0 meant using CPU only; 
  5. maxlabel;% inspect the lable maxlikehood; 
  6. figure;
  7. x=[1:1000];
  8. plot(x,scores);% plot the scores
  9. axis([1, 1000, -0.1, 0.5]);% range of X and Y axis
  10. grid on % add grid
  11. hold on
  12. plot(maxlabel,max(scores),'r*');
  13. jieguo=strcat(num2str(maxlabel),',');
  14. jieguo=strcat(jieguo,num2str(max(scores)));
  15. text(im2double(maxlabel)+20,im2double(max(scores)),jieguo);
  16. % [maxv,maxl]=findpeaks(im2double(scores),'minpeakdistance',1);
  17. % plot(maxl,maxv,'*','color','R');    %??????


  18. fid = fopen('C:/Caffe/caffe/data/ilsvrc12/synset_words.txt', 'r');  
  19. i=0;  
  20. while ~feof(fid)  
  21.     i=i+1;  
  22.     lin = fgetl(fid);  


  23.     lin = strtrim(lin);  
  24.     if(i==maxlabel)  
  25.         fprintf('the label of %d is %s\n',i,lin)% display label info in command widnow 
  26.         break  
  27.     end  
  28. end  
  29. figure;imshow(im);% shou picture
  30. str=strcat('result of classification:',lin);
  31. title(str);


运行test.m,结果如下: 

CAFFE的matlab接口测试