CAFFE的matlab介面測試
阿新 • • 發佈:2019-01-07
- 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);