File size: 1,618 Bytes
6b41115 | 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 | import csv
import json
import pytest
from trafficvision.evaluation.tracking_metrics import tracking_metrics
def test_real_tracking_metrics_detect_identity_switch(tmp_path):
truth = tmp_path / "frames.jsonl"
truth.write_text(
"\n".join(
json.dumps(
dict(
video_id="MVI",
frame_id=i,
split="test",
boxes=[[0, 0, 10, 10]],
labels=[1],
track_ids=[8],
)
)
for i in range(1, 5)
)
)
pred = tmp_path / "pred.csv"
def write(switch):
with pred.open("w", newline="") as handle:
writer = csv.DictWriter(
handle, fieldnames=["video_id", "frame_id", "track_id", "label", "x1", "y1", "x2", "y2"]
)
writer.writeheader()
for i in range(1, 5):
writer.writerow(
dict(
video_id="MVI",
frame_id=i,
track_id=2 if switch and i > 2 else 1,
label=1,
x1=0,
y1=0,
x2=10,
y2=10,
)
)
write(False)
perfect = tracking_metrics(truth, pred)
assert perfect["HOTA"] == pytest.approx(1) and perfect["IDF1"] == pytest.approx(1)
write(True)
switched = tracking_metrics(truth, pred)
assert switched["ID_switches"] == 1 and switched["IDF1"] < 1 and switched["HOTA"] < 1
|