-
Notifications
You must be signed in to change notification settings - Fork 255
/
Copy pathmot_metrics.py
89 lines (70 loc) · 2.93 KB
/
mot_metrics.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
import os.path
import numpy as np
import pandas as pd
from norfair import FilterPyKalmanFilterFactory, Tracker, metrics
DATASET_PATH = "train"
MOTA_ERROR_THRESHOLD = 0.0
DETECTION_THRESHOLD = 0.01
DISTANCE_THRESHOLD = 0.9
POINTWISE_HIT_COUNTER_MAX = 3
HIT_COUNTER_MAX = 2
def mot_metrics():
"""Tests that Norfair's MOT metrics didn't get worse
Configurable so that it allows some margin on how much worse metrics could get before
the test fails. Margin configured through MOTA_ERROR_THRESHOLD.
Raises:
If the previous metrics file its not found.
"""
# Load previous metrics
try:
previous_metrics = pd.read_fwf("tests/metrics.txt")
previous_metrics.columns = [
column_name.lower() for column_name in previous_metrics.columns
]
previous_metrics = previous_metrics.set_index(previous_metrics.columns[0])
except FileNotFoundError as e:
raise e
accumulator = metrics.Accumulators()
sequences_paths = [
element.path for element in os.scandir(DATASET_PATH) if element.is_dir()
]
for input_path in sequences_paths:
# Search vertical resolution in seqinfo.ini
seqinfo_path = os.path.join(input_path, "seqinfo.ini")
info_file = metrics.InformationFile(file_path=seqinfo_path)
all_detections = metrics.DetectionFileParser(
input_path=input_path, information_file=info_file
)
tracker = Tracker(
distance_function="iou",
distance_threshold=DISTANCE_THRESHOLD,
detection_threshold=DETECTION_THRESHOLD,
pointwise_hit_counter_max=POINTWISE_HIT_COUNTER_MAX,
hit_counter_max=HIT_COUNTER_MAX,
filter_factory=FilterPyKalmanFilterFactory(),
)
# Initialize accumulator for this video
accumulator.create_accumulator(
input_path=input_path, information_file=info_file
)
for detections in all_detections:
tracked_objects = tracker.update(
detections=detections,
)
accumulator.update(predictions=tracked_objects)
accumulator.compute_metrics()
new_metrics = accumulator.summary_dataframe
new_metrics.columns = [column_name.lower() for column_name in new_metrics.columns]
# Unify the scores to be able to compare them. new metrics is the percentage
# expressed between 0 and 1, the previous metrics have the percentage as a string
# with the % character at the end
new_overall_mota = np.around(new_metrics.loc["OVERALL", "mota"] * 100, 1)
previous_overall_mota = np.around(
float(previous_metrics.loc["OVERALL", "mota"][:-1]), 1
)
accumulator.print_metrics()
assert new_overall_mota >= previous_overall_mota * (
1 - MOTA_ERROR_THRESHOLD
), f"New overall MOTA score: {new_overall_mota} is too low, previous overall MOTA score: {previous_overall_mota}"
if __name__ == "__main__":
mot_metrics()