Skip to content

Commit aac5080

Browse files
author
agirbau
committed
Merge branch 'develop' of https://github.com/cheind/py-motmetrics into develop
2 parents 47b6ac6 + 6597e8a commit aac5080

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

motmetrics/tests/test_utils.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# py-motmetrics - Metrics for multiple object tracker (MOT) benchmarking.
2+
# https://github.com/cheind/py-motmetrics/
3+
#
4+
# MIT License
5+
# Copyright (c) 2017-2020 Christoph Heindl, Jack Valmadre and others.
6+
# See LICENSE file for terms.
7+
8+
"""Tests accumulation of events using utility functions."""
9+
10+
from __future__ import absolute_import
11+
from __future__ import division
12+
from __future__ import print_function
13+
14+
import itertools
15+
16+
import numpy as np
17+
import pandas as pd
18+
19+
import motmetrics as mm
20+
21+
22+
def test_annotations_xor_predictions_present():
23+
"""Tests frames that contain only annotations or predictions."""
24+
_ = None
25+
anno_tracks = {
26+
1: [0, 2, 4, 6, _, _, _],
27+
2: [_, _, 0, 2, 4, _, _],
28+
}
29+
pred_tracks = {
30+
1: [_, _, 3, 5, 7, 7, 7],
31+
}
32+
anno = _tracks_to_dataframe(anno_tracks)
33+
pred = _tracks_to_dataframe(pred_tracks)
34+
acc = mm.utils.compare_to_groundtruth(anno, pred, 'euc', distfields=['Position'], distth=2)
35+
mh = mm.metrics.create()
36+
metrics = mh.compute(acc, return_dataframe=False, metrics=[
37+
'num_objects', 'num_predictions', 'num_unique_objects',
38+
])
39+
np.testing.assert_equal(metrics['num_objects'], 7)
40+
np.testing.assert_equal(metrics['num_predictions'], 5)
41+
np.testing.assert_equal(metrics['num_unique_objects'], 2)
42+
43+
44+
def _tracks_to_dataframe(tracks):
45+
rows = []
46+
for track_id, track in tracks.items():
47+
for frame_id, position in zip(itertools.count(1), track):
48+
if position is None:
49+
continue
50+
rows.append({
51+
'FrameId': frame_id,
52+
'Id': track_id,
53+
'Position': position,
54+
})
55+
return pd.DataFrame(rows).set_index(['FrameId', 'Id'])

0 commit comments

Comments
 (0)