-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIDmeasures.m
98 lines (80 loc) · 3.02 KB
/
IDmeasures.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
89
90
91
92
93
94
95
96
% Tracking Performance Measures as described in the paper:
%
% Performance Measures and a Data Set for Multi-Target, Multi-Camera Tracking.
% E. Ristani, F. Solera, R. S. Zou, R. Cucchiara and C. Tomasi.
% ECCV 2016 Workshop on Benchmarking Multi-Target Tracking.
%
% Ergys Ristani
% Duke University 2016
function [measures] = IDmeasures( predictionMat, groundTruthMat, threshold, world )
% Input:
% predictionMat - ID, frame, left, top, width, height, worldX, worldY
% groundTruthMat - ID, frame, left, top, width, height, worldX, worldY
% threshold - Ground plane distance (1m) or intersection_over_union
% world - boolean paramenter determining if the evaluation is
% done in the world ground plane or in the image plane
fprintf('Calculating ID measures\n');
% Convert input trajectories from .top format to cell arrays. Each cell has
% data for one identity.
idsPred = unique(predictionMat(:,1));
idsGT = unique(groundTruthMat(:,1));
ground_truth = cell(length(idsGT),1);% gt_cam = cell(length(idsGT),1);
prediction = cell(length(idsPred),1);% pr_cam = cell(length(idsPred),1);
for i = 1:length(idsGT)
ground_truth{i} = groundTruthMat(groundTruthMat(:,1) == idsGT(i),:);
end
for i = 1:length(idsPred)
prediction{i} = predictionMat(predictionMat(:,1) == idsPred(i),:);
end
% Initialize cost matrix blocks
cost = zeros(length(prediction) + length(ground_truth));
cost( length(ground_truth) + 1:end, 1:length(prediction)) = inf;
cost( 1:length(ground_truth), length(prediction) + 1 : end) = inf;
fp = zeros(size(cost));
fn = zeros(size(cost));
% Compute cost block
for i = 1:length(ground_truth)
for j = 1:length(prediction)
[cost(i,j), fp(i,j), fn(i,j)] = costFunction(ground_truth{i}, prediction{j}, threshold, world);
end
end
% Compute FP block
for i = 1:length(prediction)
cost(i+length(ground_truth),i) = size(prediction{i},1);
fp(i+length(ground_truth),i) = size(prediction{i},1);
end
% Compute FN block
for i = 1:length(ground_truth)
cost(i,i+length(prediction)) = size(ground_truth{i},1);
fn(i,i+length(prediction)) = size(ground_truth{i},1);
end
fprintf('size of cost matrix\n');
size(cost)
% Solve truth-to-result identity matching
[assignment, ~] = assignmentoptimal(cost);
% For visualization
% solutionMatrix = zeros(size(cost));
% for i = 1:length(assignment), solutionMatrix(i,assignment(i)) = 1; end
numGT = sum(cellfun(@(x) size(x,1), ground_truth));
numPRED = sum(cellfun(@(x) size(x,1), prediction));
% Count assignment errors
IDFP = 0;
IDFN = 0;
for i = 1:length(assignment)
IDFP = IDFP + fp(i,assignment(i));
IDFN = IDFN + fn(i,assignment(i));
end
IDTP = numGT - IDFN;
% Sanity check
assert(IDTP == numPRED - IDFP);
IDPrecision = IDTP / (IDTP + IDFP);
IDRecall = IDTP / (IDTP + IDFN);
IDF1 = 2*IDTP/(numGT + numPRED);
measures.IDP = IDPrecision * 100;
measures.IDR = IDRecall * 100;
measures.IDF1 = IDF1 * 100;
measures.numGT = numGT;
measures.numPRED = numPRED;
measures.IDTP = IDTP;
measures.IDFP = IDFP;
measures.IDFN = IDFN;