Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hota iou calculation along with detection/association accuracy #183

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions motmetrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,36 @@ def idf1_m(partials, idtp, num_objects, num_predictions):
return math_util.quiet_divide(2 * idtp, num_objects + num_predictions)


def det_acc(df, num_detections, num_objects, num_false_positives):
"""Detection accuracy.

Source: https://jonathonluiten.medium.com/how-to-evaluate-tracking-with-the-hota-metrics-754036d183e1
"""

del df # unused
return math_util.quiet_divide(num_detections, num_objects + num_false_positives)


def ass_acc(df, idtp, idfn, idfp):
"""Association accuracy.

Source: https://jonathonluiten.medium.com/how-to-evaluate-tracking-with-the-hota-metrics-754036d183e1
"""

del df # unused
return math_util.quiet_divide(idtp, idtp + idfn + idfp)


def hota_iou(df, det_acc, ass_acc):
"""HOTA metric at a specific iou.

Source: https://jonathonluiten.medium.com/how-to-evaluate-tracking-with-the-hota-metrics-754036d183e1
"""

del df
return (det_acc * ass_acc)**0.5


for one in simple_add_func:
name = one.__name__

Expand Down Expand Up @@ -802,6 +832,10 @@ def create():
m.register(idr, formatter="{:.1%}".format)
m.register(idf1, formatter="{:.1%}".format)

m.register(det_acc, formatter="{:.1%}".format)
m.register(ass_acc, formatter="{:.1%}".format)
m.register(hota_iou, formatter="{:.1%}".format)

return m


Expand Down
37 changes: 37 additions & 0 deletions motmetrics/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pandas as pd
import pytest
from pytest import approx

import motmetrics as mm
Expand Down Expand Up @@ -343,6 +344,42 @@ def test_mota_motp():
assert metr["num_frames"] == 6


def test_hota():
"""Tests values of HOTA and its dependents."""
acc = mm.MOTAccumulator()

# All FP
acc.update([], [1, 2], [], frameid=0)
# All miss
acc.update([1, 2], [], [], frameid=1)
# Match
acc.update([1, 2], [1, 2], [[1, 0.5], [0.3, 1]], frameid=2)
# Switch
acc.update([1, 2], [1, 2], [[0.2, np.nan], [np.nan, 0.1]], frameid=3)
# Match. Better new match is available but should prefer history
acc.update([1, 2], [1, 2], [[5, 1], [1, 5]], frameid=4)
# No data
acc.update([], [], [], frameid=5)

mh = mm.metrics.create()
metr = mh.compute(
acc,
return_dataframe=False,
return_cached=True,
metrics=[
"hota_iou",
"det_acc",
"ass_acc",
"num_frames",
],
)

assert metr["det_acc"] == approx(6 / (8 + 2))
assert metr["ass_acc"] == approx(6 / (8 + 2))
assert metr["hota_iou"] == approx(0.6)
assert metr["num_frames"] == 6


def test_ids():
"""Test metrics with frame IDs specified manually."""
acc = mm.MOTAccumulator()
Expand Down