-
Notifications
You must be signed in to change notification settings - Fork 2
/
EvalResult.m
53 lines (42 loc) · 1.44 KB
/
EvalResult.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
function [Precision, Recall, EER, PrecEER] = ...
EvalResult(SalImgList, MaskList)
SalImages = gpuArray(cell2mat(SalImgList));
Masks = gpuArray(cell2mat(MaskList));
[Precision, Recall] = EvalPRFast(SalImages, Masks, []);
[~,idx] = min(abs(Precision - Recall));
EER = Recall(idx);
PrecEER = Precision(idx);
end
function [precision, recall, threshold] = EvalPRFast(smapImg, gtImg, threshold)
smapImg = smapImg(:);
gtImg = logical(gtImg(:));
if nargin == 2 || isempty(threshold)
num_thresh = 1000;
qvals = (1:(num_thresh-1))/num_thresh;
threshold = [min(smapImg) quantile(smapImg,qvals)];
end
gtPxlNum = sum(gtImg(:));
try
targetHist = histc(smapImg(gtImg), threshold);
catch
threshold = sort(threshold, 'ascend');
targetHist = histc(smapImg(gtImg), threshold);
end
nontargetHist = histc(smapImg(~gtImg), threshold);
targetHist = flipud(targetHist);
nontargetHist = flipud(nontargetHist);
targetHist = cumsum( targetHist );
nontargetHist = cumsum( nontargetHist );
precision = targetHist ./ (targetHist + nontargetHist);
if any(isnan(precision))
warning('there exists NAN in precision, this is because of your saliency map do not have a full range specified by cutThreshes\n');
end
recall = targetHist / gtPxlNum;
recall(recall==Inf) = 1;
recall(isnan(recall)) = 1;
precision(precision==Inf) = 1;
precision(isnan(precision)) = 1;
precision = gather(precision);
recall = gather(recall);
threshold = gather(threshold);
end