1. 程式人生 > >CAFFE的matlab介面測試

CAFFE的matlab介面測試

  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);