-
Notifications
You must be signed in to change notification settings - Fork 258
/
example.py
80 lines (65 loc) · 2.13 KB
/
example.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
# py-motmetrics - Metrics for multiple object tracker (MOT) benchmarking.
# https://github.com/cheind/py-motmetrics/
#
# MIT License
# Copyright (c) 2017-2020 Christoph Heindl, Jack Valmadre and others.
# See LICENSE file for terms.
"""Example usage."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import motmetrics as mm
if __name__ == '__main__':
# Create an accumulator that will be updated during each frame
acc = mm.MOTAccumulator(auto_id=True)
# Each frame a list of ground truth object / hypotheses ids and pairwise distances
# is passed to the accumulator. For now assume that the distance matrix given to us.
# 2 Matches, 1 False alarm
acc.update(
[1, 2], # Ground truth objects in this frame
[1, 2, 3], # Detector hypotheses in this frame
[[0.1, np.nan, 0.3], # Distances from object 1 to hypotheses 1, 2, 3
[0.5, 0.2, 0.3]] # Distances from object 2 to hypotheses 1, 2,
)
print(acc.events)
# 1 Match, 1 Miss
df = acc.update(
[1, 2],
[1],
[[0.2], [0.4]]
)
print(df)
# 1 Match, 1 Switch
df = acc.update(
[1, 2],
[1, 3],
[[0.6, 0.2],
[0.1, 0.6]]
)
print(df)
# Compute metrics
mh = mm.metrics.create()
summary = mh.compute(acc, metrics=['num_frames', 'mota', 'motp'], name='acc')
print(summary)
summary = mh.compute_many(
[acc, acc.events.loc[0:1]],
metrics=['num_frames', 'mota', 'motp'],
names=['full', 'part'])
print(summary)
strsummary = mm.io.render_summary(
summary,
formatters={'mota': '{:.2%}'.format},
namemap={'mota': 'MOTA', 'motp': 'MOTP'}
)
print(strsummary)
summary = mh.compute_many(
[acc, acc.events.loc[0:1]],
metrics=mm.metrics.motchallenge_metrics,
names=['full', 'part'])
strsummary = mm.io.render_summary(
summary,
formatters=mh.formatters,
namemap=mm.io.motchallenge_metric_names
)
print(strsummary)