-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVOCevalcls.m
60 lines (50 loc) · 1.22 KB
/
VOCevalcls.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function [rec,prec,ap] = VOCevalcls(VOCopts,id,cls,draw)
% load test set
[gtids,gt]=textread(sprintf(VOCopts.clsimgsetpath,cls,VOCopts.testset),'%s %d');
% load results
[ids,confidence]=textread(sprintf(VOCopts.clsrespath,id,cls),'%s %f');
% map results to ground truth images
out=ones(size(gt))*-inf;
tic;
for i=1:length(ids)
% display progress
if toc>1
fprintf('%s: pr: %d/%d\n',cls,i,length(ids));
drawnow;
tic;
end
% find ground truth image
j=strmatch(ids{i},gtids,'exact');
if isempty(j)
error('unrecognized image "%s"',ids{i});
elseif length(j)>1
error('multiple image "%s"',ids{i});
else
out(j)=confidence(i);
end
end
% compute precision/recall
[so,si]=sort(-out);
tp=gt(si)>0;
fp=gt(si)<0;
fp=cumsum(fp);
tp=cumsum(tp);
rec=tp/sum(gt>0);
prec=tp./(fp+tp);
% compute average precision
ap=0;
for t=0:0.1:1
p=max(prec(rec>=t));
if isempty(p)
p=0;
end
ap=ap+p/11;
end
if draw
% plot precision/recall
plot(rec,prec,'-');
grid;
xlabel 'recall'
ylabel 'precision'
title(sprintf('class: %s, subset: %s, AP = %.3f',cls,VOCopts.testset,ap));
end