-
Notifications
You must be signed in to change notification settings - Fork 8
/
calc_ap.m
30 lines (25 loc) · 872 Bytes
/
calc_ap.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Caculates AP score
% input -
% score_test: output confidences from the classifier. Values greater than
% 0.0 are considered positive detections.
% test_labels: the ground truth labels. 1 is positive and -1 is negative
% label.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ ap ] = calc_ap( score_test, test_labels)
[~,sort_inds] = sort(score_test, 'descend');
tp = (test_labels > 0.999 & test_labels < 1.001);
fp = (test_labels > -1.001 & test_labels < -0.9999);
npos = numel(find(test_labels > 0.999 & test_labels < 1.001));
tp = tp(sort_inds);
fp = fp(sort_inds);
fp=cumsum(fp);
tp=cumsum(tp);
rec=tp/npos;
prec=tp./(fp+tp);
ap=VOCap(rec,prec);
if(isnan(ap))
ap = 0.0;
end
end