-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathEvalVOCInstSeg.m
88 lines (76 loc) · 2.46 KB
/
EvalVOCInstSeg.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function AP = EvalVOCInstSeg(InstSegRes, GTInst, EvalCLassID, Threhold)
% InstSegRes = struct; [NumImgs X NumClass]
% InstSegRes = struct; [NumImgs X 1]
% first compute all overlaps
overlaps=cell(numel(GTInst),length(EvalCLassID));
gt = cell(numel(GTInst), 1);
Scores = cell(numel(GTInst),length(EvalCLassID));
for i=1:numel(GTInst)
GTClass = GTInst(i).InstClass;
GTInstSegMap = GTInst(i).InstSegMap;
for j = 1:numel(EvalCLassID)
PredInstSegMap = InstSegRes(i,j).InstSegMap;
PredInstScores = InstSegRes(i,j).Scores;
if ~isempty(PredInstSegMap)
overlaps{i,j} = GetOverlap(PredInstSegMap, GTInstSegMap);
Scores{i,j} = PredInstScores;
else
overlaps{i,j} = [];
Scores{i,j} = [];
end
end
gt{i}=GTClass;
end
% now run the evaluation. This is relatively fast once overlaps are precomputed
% ap_vol=zeros(9,numel(EvalCLassID));
AP = zeros(numel(EvalCLassID), length(Threhold));
for j=1:numel(EvalCLassID)
for t = 1:length(Threhold)
AP(j,t) = EvalInstSegAP(gt, Scores(:, EvalCLassID(j)), overlaps(:, EvalCLassID(j)), gt, EvalCLassID(j), Threhold(t));
% ap_vol(t,j)=outputs(t,j).PR.ap;
% fprintf('Evaluated threshold:%f for category:%d\n', 0.1*t, EvalCLassID(j));
end
end
end
function [Overlap, NumInsts] = GetOverlap(PredInstSegMap, GTInstSegMap)
if isempty(PredInstSegMap)
Overlap = [];
NumInsts = 0;
return
end
GTInstsSize = size(GTInstSegMap);
if iscell(GTInstSegMap)
InstFun = @(Index)CellFun(GTInstSegMap,Index);
NumInsts = max(GTInstsSize);
else
if length(GTInstsSize) == 2
NumInsts = 1;
else
NumInsts = GTInstsSize(3);
end
InstFun = @(Index)ThreeDMatFun(GTInstSegMap,Index);
end
NumProposals = size(PredInstSegMap, 3);
Overlap = zeros(NumInsts, NumProposals);
for i = 1:NumProposals
Proposal = PredInstSegMap(:,:,i);
for j = 1:NumInsts
TempProposal = Proposal;
TempGTInst = InstFun(j);
Ignore = TempGTInst == 255;
TempProposal(Ignore) = [];
TempGTInst(Ignore) = [];
TempGTInst = logical(TempGTInst);
Overlap(j,i) = sum(TempProposal & TempGTInst) / sum(TempProposal | TempGTInst);
end
end
end
function InstMask = CellFun(InstList, Index)
InstMask = InstList{Index};
end
function InstMask = ThreeDMatFun(InstList, Index)
InstMask = InstList(:,:,Index);
end
function InstMask = OneDMatFun(InstList, Index)
InstMask = InstList == Index;
end