-
Notifications
You must be signed in to change notification settings - Fork 1
/
evaluation.py
151 lines (122 loc) · 3.81 KB
/
evaluation.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import motmetrics as mm
import numpy as np
import os
from absl import app, flags, logging
from absl.flags import FLAGS
"""
python evaluation.py \
--gt_file_path ./resources/gt/T-ara_gt.txt \
--pred_file_path ./resources/gt/T-ara_pred.txt
python evaluation.py \
--gt_file_path ./resources/gt/GirlsAloud_gt.txt \
--pred_file_path ./resources/gt/GirlsAloud_pred.txt
python evaluation.py \
--gt_file_path ./resources/gt/Darling_gt.txt \
--pred_file_path ./resources/gt/Darling_pred.txt
python evaluation.py \
--gt_file_path ./resources/gt/Westlife_gt.txt \
--pred_file_path ./resources/gt/Westlife_pred.txt
python evaluation.py \
--gt_file_path ./resources/gt/BrunoMars_gt.txt \
--pred_file_path ./resources/gt/BrunoMars_pred.txt
python evaluation.py \
--gt_file_path ./resources/gt/HelloBubble_gt.txt \
--pred_file_path ./resources/gt/HelloBubble_pred.txt
python evaluation.py \
--gt_file_path ./resources/gt/Apink_gt.txt \
--pred_file_path ./resources/gt/Apink_pred.txt
"""
flags.DEFINE_string('gt_file_path', './resources/gt/T-ara_gt.txt', 'path to gt txt')
flags.DEFINE_string('pred_file_path', './resources/gt/T-ara_pred.txt', 'path to predicted txt')
def main(args):
# home = os.getcwd()
# gt_path = os.path.join(home, "resources", "gt")
# gt_file_path = os.path.join(gt_path, "T-ara_gt.txt")
# pred_file_path = os.path.join(gt_path, "T-ara_pred.txt")
f = open(FLAGS.gt_file_path, "r")
gt = []
while True:
line = f.readline()
if not line: break
a = list(map(int, line.split()))
gt.append(a)
gt = np.asarray(gt)
f.close()
f = open(FLAGS.pred_file_path, "r")
pred = []
while True:
line = f.readline()
if not line: break
a = list(map(int, line.split()))
pred.append(a)
pred = np.asarray(pred)
f.close()
acc = mm.MOTAccumulator(auto_id=True)
frame_idx = 0
count = 0
max_index = max(max(gt[:, 0]), max(pred[:, 0]))
while frame_idx <= max_index:
frame_idx += 1
gt_indexs = gt[:, 0]
pred_indexs = pred[:, 0]
mask1 = frame_idx == gt_indexs
mask2 = frame_idx == pred_indexs
# if not gt[mask1].shape[0] and not pred[mask2].shape[0]:
# break
# gt_ids = sorted(list(set(gt[mask1][:, 1])))
# pred_ids = sorted(list(set(pred[mask2][:, 1])))
gt_ids = gt[mask1][:, 1]
pred_ids = pred[mask2][:, 1]
# print(gt_ids)
# print(pred_ids)
a = gt[mask1][:, 2:]
b = pred[mask2][:, 2:]
# print(mm.distances.iou_matrix(a, b, max_iou=0.5))
f = acc.update(
gt_ids,
pred_ids,
mm.distances.iou_matrix(a, b, max_iou=0.5)
)
# print(mm.distances.iou_matrix(a, b, max_iou=0.5))
# print(acc.mot_events.loc[f])
mh = mm.metrics.create()
custom_metric = [
"num_frames",
"obj_frequencies",
"pred_frequencies",
"num_matches",
"num_switches",
"num_transfer",
"num_ascend",
"num_migrate",
"num_false_positives",
"num_misses",
"num_detections",
"num_objects",
"num_predictions",
"num_unique_objects",
"track_ratios",
"mostly_tracked",
"partially_tracked",
"mostly_lost",
"num_fragmentations",
"motp",
"mota",
"precision",
"recall",
]
summary = mh.compute_many(
[acc, acc.mot_events],
metrics=mm.metrics.motchallenge_metrics,
)
strsummary = mm.io.render_summary(
summary,
formatters=mh.formatters,
namemap=mm.io.motchallenge_metric_names
)
print(strsummary)
if __name__ == '__main__':
try:
app.run(main)
except SystemExit:
pass