Definitionresearch
Higher order tracking accuracy
Also called HOTA.
The geometric mean of detection accuracy and association accuracy, averaged over localization thresholds, which weighs detection and association evenly.
HOTA, higher order tracking accuracy, scores a multi-object tracker with one number that gives the same weight to finding the objects and to keeping their identities. For a localization threshold , it matches the detections frame by frame and computes two parts. The detection accuracy DetA is the Jaccard index of the detections: true positives over true positives plus misses plus false positives. The association accuracy AssA is the mean, over the true positives, of a Jaccard index of the two whole trajectories that the true positive links. is the geometric mean of the two, and HOTA averages it over 19 thresholds from 0.05 to 0.95. Luiten et al. published it in 2021 as a balance between MOTA, which is ruled by detection, and the IDF1 score, which is ruled by one global matching of trajectories.
Definition
The ground truth and the tracker give, in each frame, detections with an identity and a box; a similarity of two boxes is usually the intersection over union. Fix . In each frame, a one-to-one matching of true to predicted detections with gives the true positives TP; the other true detections are the misses FN, and the other predicted ones the false positives FP. For a true positive with the true identity and the predicted identity :
- is the set of true positives with the same pair of identities ;
- is the set of true detections of that are not matched to : true positives with another predicted identity, and misses;
- is the set of predicted detections of that are not matched to : true positives with another true identity, and false positives.
The parts are , , and the localization accuracy , the mean of over the true positives. If and are the numbers of detections of and , then and , so is the Jaccard index of the two trajectories' sets of frames, counting only the frames in which they are matched as shared.
The matching of each frame maximizes the sum of the score
with a small . The first term asks for the most true positives, the second for the best association, and the third for the best boxes. is the largest the pair could get if every frame could match it: , where is the number of frames in which and have . The full procedure:
HOTA(the true and the predicted detections)- 1
for each α in {0.05, 0.10, ..., 0.95}: - 2
in each frame, match the detections with S ≥ α, maximizing the sum of MS (Hungarian) - 3
count TP, FN and FP; for each identity pair (g, p), |TPA| = its number of true positives - 4
DetA_α ← TP / (TP + FN + FP); AssA_α ← mean of A(c) over TP; HOTA_α ← sqrt(DetA_α · AssA_α) - 5
HOTA ← the mean of HOTA_α over the 19 values of α
These facts follow from the definition and are proved in the correctness file of this page:
- Theorem: the geometric mean. whenever there is a true positive (Eq. 21 of the paper).
- Theorem: the most true positives. If , where is the largest number of pairs in a frame, the matching of line L2 has the largest possible number of true positives in each frame.
- Theorem: DetA does not grow with . A larger threshold allows fewer pairs, so the largest matching cannot grow, and falls or stays.
- Theorem: the range. , and exactly when there are no misses and no false positives and each true identity is matched to one predicted identity in all its frames, and the other way around.
Examples and non-examples
- A swap. Two objects stand still for 6 frames, and the tracker follows them with exact boxes and the identities and , which swap after frame 4. For every all 12 detections are true positives, so . The pair has and , so ; the pair has , and the same holds for object 2. So and . On the same input and .
- A box that is a little off. One object over 5 frames at , and the tracker always gives , with IoU . For the 12 thresholds , every detection is a true positive and ; for the 7 thresholds above, there are no true positives and . So , and on the thresholds with true positives. MOTA with the threshold 0.5 would be 1: HOTA also asks for good boxes.
- Not the product. is a geometric mean, not a product. With and it is , not .
- Not the mean of the parts over . HOTA averages , which is in general not of the averaged parts. In the second example the averaged parts are both , and their geometric mean happens to agree, but with and that fall at different thresholds it does not.
Related definitions
MOTA uses the same per frame matching, but it counts association only through identity switches, events against the last match, so detection errors dominate it. The IDF1 score matches whole trajectories once, so only the matched trajectories count as correct, and better detection in unmatched parts can lower it. HOTA scores every true positive with the overlap of the two trajectories it links, which needs no global matching. DetA and AssA split into recall and precision parts, , , and , in the same way as precision and recall. The per frame matching is an assignment problem, solved with the Hungarian algorithm. AssA measures the result of the data association step of a tracker, and the ByteTrack paper reports HOTA together with MOTA and IDF1. The Python code of this page computes the parts with exact fractions, and its tests compare the per frame matching with all matchings, compute again from the set definitions, and check that DetA does not grow with .
Proof: HOTA_alpha is the geometric mean of DetA and AssA, the matching gives the most true positives, and DetA does not grow with the thresholdfull
Notation as on the page. Fix a threshold . and are the numbers of true and predicted detections over all frames, TP is the set of matches made by line L2, and and .
Claim 1: the sizes of FNA and FPA
For a true positive with identities , and . So depends only on the pair , and , where is the number of true positives with the identities .
Proof. Each true detection of is either a true positive, with some predicted identity, or a miss. Those that are true positives with form , and all the others form by its definition. So the two sets split the detections of . The same argument on the predicted side gives the second formula. Then , and the true positives with the pair each add this value.
The code uses this formula, and the tests compute again from the set definitions.
Claim 2: the geometric mean
If , then .
Proof. , the number under the square root in the definition of .
If there is no true positive, the sum is empty and ; the code then sets , so the formula holds in this case as well.
Claim 3: the most true positives
Let be the largest number of pairs in a matching of one frame, and let . Then the matching of line L2 has the largest number of pairs with in its frame.
Proof. Line L2 gives each pair with the weight and the other pairs the weight 0, finds a maximum weight assignment with the Hungarian algorithm (its optimality is proved on the SORT proof), and removes the pairs of weight 0. As for the CLEAR MOT matching, this gives a matching of allowed pairs with the largest total MS. Since and , a matching with pairs has a total in . If some matching had more pairs than , say , then
against the choice of .
With equal numbers of pairs, the same argument shows that the term decides first when is below the smallest positive gap between two sums of , and then the term decides. This order is the one that the paper asks for. The code uses with exact fractions, and the tests compare the total MS and the number of pairs with all matchings.
Claim 4: DetA does not grow with the threshold
If and the condition of Claim 3 holds, then .
Proof. Every pair with also has , so every matching allowed at is allowed at . By Claim 3, the number of true positives in each frame is the largest matching size, so it is at least as large at as at . Summing over the frames gives . Now , which increases with for fixed , since the numerator grows and the denominator falls.
AssA has no such order: a larger threshold can remove the true positives of a badly associated pair and raise the mean.
Claim 5: the range
, and exactly when there are no misses and no false positives at and every true positive has , that is, each true identity is matched to one predicted identity in all its frames and that predicted identity is matched to it in all of its own frames.
Proof. Each is in , so the sum under the root is between 0 and . It equals 1 exactly when both inequalities are equalities: and for every , which means . HOTA, a mean of numbers in , is also in .
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hota-metric/. The authors are listed in prov/SAT5C8.jsonl.
"""HOTA, higher order tracking accuracy (Luiten et al. 2021), with IoU as the similarity S.
A sequence is a list of frames; a frame is a dict from an identity to a box
(x1, y1, x2, y2). For each alpha in {0.05, 0.10, ..., 0.95}:
1. in each frame, the true and the predicted detections with S >= alpha are
matched one to one, maximizing the sum of MS = 1/eps + A_max + eps S
(the Hungarian algorithm). A_max(g, p) = n / (|g| + |p| - n), where n is the
number of frames in which g and p have S >= alpha;
2. the matches are the TPs, the other true detections the FNs and the other
predicted detections the FPs;
3. a TP c with identities (g, p) has TPA(c) = the TPs with the identities
(g, p), FNA(c) = |g| - TPA(c), FPA(c) = |p| - TPA(c), and
A(c) = TPA / (TPA + FNA + FPA);
4. DetA = TP / (TP + FN + FP), AssA = the mean of A(c) over the TPs,
HOTA_alpha = sqrt(DetA AssA).
HOTA is the mean of HOTA_alpha over the 19 values of alpha. The squares and
the parts are exact fractions.
"""
import math
from fractions import Fraction
ALPHAS = [Fraction(k, 20) for k in range(1, 20)]
EPS = Fraction(1, 10 ** 6)
def iou(a, b):
w = min(a[2], b[2]) - max(a[0], b[0])
h = min(a[3], b[3]) - max(a[1], b[1])
inter = w * h if w > 0 and h > 0 else 0
union = (a[2] - a[0]) * (a[3] - a[1]) + (b[2] - b[0]) * (b[3] - b[1]) - inter
return Fraction(inter) / union if union > 0 else Fraction(0)
def hungarian_min(cost):
"""Minimum cost assignment of a rectangular matrix; exact for fractions.
Returns the sorted pairs (row, column), min(rows, columns) of them."""
r = len(cost)
if r == 0 or len(cost[0]) == 0:
return []
c = len(cost[0])
flip = r > c
if flip:
cost = [list(col) for col in zip(*cost)]
r, c = c, r
inf = float("inf")
u, v = [0] * (r + 1), [0] * (c + 1)
p, way = [0] * (c + 1), [0] * (c + 1)
for i in range(1, r + 1):
p[0], j0 = i, 0
minv, used = [inf] * (c + 1), [False] * (c + 1)
while True:
used[j0] = True
i0, delta, j1 = p[j0], inf, 0
for j in range(1, c + 1):
if not used[j]:
cur = cost[i0 - 1][j - 1] - u[i0] - v[j]
if cur < minv[j]:
minv[j], way[j] = cur, j0
if minv[j] < delta:
delta, j1 = minv[j], j
for j in range(c + 1):
if used[j]:
u[p[j]] += delta
v[j] -= delta
else:
minv[j] -= delta
j0 = j1
if p[j0] == 0:
break
while True:
j1 = way[j0]
p[j0] = p[j1]
j0 = j1
if j0 == 0:
break
pairs = [(p[j] - 1, j - 1) for j in range(1, c + 1) if p[j] != 0]
if flip:
pairs = [(b, a) for a, b in pairs]
return sorted(pairs)
def lengths(frames):
out = {}
for f in frames:
for k in f:
out[k] = out.get(k, 0) + 1
return out
def potential_counts(gt_frames, pr_frames, alpha):
"""n[(g, p)] = the number of frames in which g and p have S >= alpha."""
n = {}
for gt, pr in zip(gt_frames, pr_frames):
for g, a in gt.items():
for p, b in pr.items():
if iou(a, b) >= alpha:
n[(g, p)] = n.get((g, p), 0) + 1
return n
def match_score(s, a_max, eps=EPS):
return 1 / eps + a_max + eps * s
def frame_matching(gt, pr, alpha, a_max, eps=EPS):
"""The pairs (g, p) of one frame with S >= alpha and the largest sum of MS."""
gs, ps = sorted(gt, key=repr), sorted(pr, key=repr)
if not gs or not ps:
return []
sim = [[iou(gt[g], pr[p]) for p in ps] for g in gs]
cost = [[-match_score(sim[i][j], a_max.get((g, p), 0), eps) if sim[i][j] >= alpha else 0
for j, p in enumerate(ps)] for i, g in enumerate(gs)]
return [(gs[i], ps[j]) for i, j in hungarian_min(cost) if sim[i][j] >= alpha]
def hota_alpha(gt_frames, pr_frames, alpha, eps=EPS):
"""Returns a dict with tp, fn, fp, deta, assa, hota_sq (exact), hota and loca."""
glen, plen = lengths(gt_frames), lengths(pr_frames)
n = potential_counts(gt_frames, pr_frames, alpha)
a_max = {k: Fraction(v, glen[k[0]] + plen[k[1]] - v) for k, v in n.items()}
tpa = {}
tp, sum_s = 0, Fraction(0)
for gt, pr in zip(gt_frames, pr_frames):
for g, p in frame_matching(gt, pr, alpha, a_max, eps): # @line L2
tpa[(g, p)] = tpa.get((g, p), 0) + 1
tp += 1
sum_s += iou(gt[g], pr[p])
fn = sum(glen.values()) - tp # @line L3
fp = sum(plen.values()) - tp
# sum over the TPs c of A(c): each identity pair (g, p) has tpa TPs with the same A
sum_a = sum((Fraction(k * k, glen[g] + plen[p] - k) for (g, p), k in tpa.items()), Fraction(0))
total = tp + fn + fp
deta = Fraction(tp, total) if total else Fraction(0) # @line L4
assa = sum_a / tp if tp else Fraction(0)
hota_sq = deta * assa
return {"tp": tp, "fn": fn, "fp": fp, "deta": deta, "assa": assa, "hota_sq": hota_sq,
"hota": math.sqrt(hota_sq), "loca": sum_s / tp if tp else None, "tpa": tpa}
def hota(gt_frames, pr_frames, alphas=ALPHAS, eps=EPS):
"""Returns HOTA, DetA, AssA and LocA averaged over alpha, and the per alpha results.
LocA is averaged over the alphas with at least one TP."""
per = [hota_alpha(gt_frames, pr_frames, a, eps) for a in alphas] # @line L1
k = len(per)
locs = [r["loca"] for r in per if r["loca"] is not None]
return {
"hota": sum(r["hota"] for r in per) / k, # @line L5
"deta": sum((r["deta"] for r in per), Fraction(0)) / k,
"assa": sum((r["assa"] for r in per), Fraction(0)) / k,
"loca": sum(locs, Fraction(0)) / len(locs) if locs else None,
"per_alpha": per,
}
test_hota_metric.py 142 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hota-metric/. The authors are listed in prov/SAT5C8.jsonl.
import itertools
import math
import random
from fractions import Fraction
from hota_metric import (ALPHAS, frame_matching, hota, hota_alpha, iou, lengths,
match_score, potential_counts)
P1 = (0, 0, 10, 10)
P2 = (40, 0, 50, 10)
def a_max_of(gt_frames, pr_frames, alpha):
glen, plen = lengths(gt_frames), lengths(pr_frames)
n = potential_counts(gt_frames, pr_frames, alpha)
return {k: Fraction(v, glen[k[0]] + plen[k[1]] - v) for k, v in n.items()}
def test_page_example_swap():
gt = [{1: P1, 2: P2}] * 6
pr = [{"a": P1, "b": P2}] * 4 + [{"a": P2, "b": P1}] * 2
r = hota(gt, pr)
for x in r["per_alpha"]:
assert (x["tp"], x["fn"], x["fp"]) == (12, 0, 0)
assert x["tpa"] == {(1, "a"): 4, (2, "b"): 4, (1, "b"): 2, (2, "a"): 2}
assert x["deta"] == 1 and x["assa"] == Fraction(2, 5)
assert abs(r["hota"] - math.sqrt(0.4)) < 1e-12
assert r["loca"] == 1
def test_page_example_offset():
# IoU((0,0,8,10), (2,0,10,10)) = 60 / 100: a true positive for alpha <= 0.6 only
assert iou((0, 0, 8, 10), (2, 0, 10, 10)) == Fraction(3, 5)
gt = [{1: (0, 0, 8, 10)}] * 5
pr = [{"a": (2, 0, 10, 10)}] * 5
r = hota(gt, pr)
assert [x["hota_sq"] for x in r["per_alpha"]] == [1] * 12 + [0] * 7
assert abs(r["hota"] - 12 / 19) < 1e-12
assert r["deta"] == Fraction(12, 19) and r["assa"] == Fraction(12, 19)
assert r["loca"] == Fraction(3, 5)
def test_perfect_and_empty():
gt = [{1: P1, 2: P2}] * 3
assert hota(gt, gt)["hota"] == 1
assert hota(gt, [{}] * 3)["hota"] == 0
def random_box(rng):
x, y = rng.randint(0, 10), rng.randint(0, 10)
return (x, y, x + rng.randint(3, 6), y + rng.randint(3, 6))
def random_sequence(rng, objects=3, frames=6):
start = {o: random_box(rng) for o in range(objects)}
names = {o: "abcde"[o] for o in range(objects)}
gt_frames, pr_frames = [], []
for t in range(rng.randint(1, frames)):
gt, pr = {}, {}
for o, b in start.items():
if rng.random() < 0.8:
gt[o] = (b[0] + t, b[1], b[2] + t, b[3])
if rng.random() < 0.2:
names[o] = rng.choice("abcdef")
if rng.random() < 0.8 and names[o] not in pr:
dx = rng.randint(-2, 2)
pr[names[o]] = (gt[o][0] + dx, gt[o][1], gt[o][2] + dx, gt[o][3] + rng.randint(-1, 1))
if rng.random() < 0.3:
pr["z"] = random_box(rng)
gt_frames.append(gt)
pr_frames.append(pr)
return gt_frames, pr_frames
def brute_frame_matching(gt, pr, alpha, a_max):
gs, ps = list(gt), list(pr)
best_count, best_score = 0, Fraction(0)
for k in range(min(len(gs), len(ps)) + 1):
for rs in itertools.combinations(gs, k):
for cs in itertools.permutations(ps, k):
pairs = list(zip(rs, cs))
if all(iou(gt[g], pr[p]) >= alpha for g, p in pairs):
best_count = max(best_count, k)
s = sum((match_score(iou(gt[g], pr[p]), a_max.get((g, p), 0)) for g, p in pairs), Fraction(0))
best_score = max(best_score, s)
return best_count, best_score
def test_frame_matching_against_brute_force():
rng = random.Random(1)
for _ in range(25):
gt_frames, pr_frames = random_sequence(rng, objects=4)
alpha = rng.choice(ALPHAS)
a_max = a_max_of(gt_frames, pr_frames, alpha)
for gt, pr in zip(gt_frames, pr_frames):
pairs = frame_matching(gt, pr, alpha, a_max)
score = sum((match_score(iou(gt[g], pr[p]), a_max.get((g, p), 0)) for g, p in pairs), Fraction(0))
count, best = brute_frame_matching(gt, pr, alpha, a_max)
assert score == best
assert len(pairs) == count # the most true positives come first
def test_association_scores_from_the_set_definitions():
rng = random.Random(2)
for _ in range(25):
gt_frames, pr_frames = random_sequence(rng)
alpha = rng.choice(ALPHAS)
r = hota_alpha(gt_frames, pr_frames, alpha)
a_max = a_max_of(gt_frames, pr_frames, alpha)
tps, fns, fps = [], [], []
for t, (gt, pr) in enumerate(zip(gt_frames, pr_frames)):
pairs = frame_matching(gt, pr, alpha, a_max)
tps += [(t, g, p) for g, p in pairs]
fns += [(t, g) for g in gt if g not in {g2 for g2, _ in pairs}]
fps += [(t, p) for p in pr if p not in {p2 for _, p2 in pairs}]
sum_a = Fraction(0)
for _, g, p in tps:
tpa = [k for k in tps if k[1] == g and k[2] == p]
fna = [k for k in tps if k[1] == g and k[2] != p] + [k for k in fns if k[1] == g]
fpa = [k for k in tps if k[2] == p and k[1] != g] + [k for k in fps if k[1] == p]
sum_a += Fraction(len(tpa), len(tpa) + len(fna) + len(fpa))
assert (r["tp"], r["fn"], r["fp"]) == (len(tps), len(fns), len(fps))
total = len(tps) + len(fns) + len(fps)
if total:
assert r["hota_sq"] == sum_a / total
if tps:
assert r["assa"] == sum_a / len(tps)
assert r["hota_sq"] == r["deta"] * r["assa"]
assert 0 <= r["deta"] <= 1 and 0 <= r["assa"] <= 1
def test_detection_accuracy_does_not_grow_with_alpha():
rng = random.Random(3)
for _ in range(10):
gt_frames, pr_frames = random_sequence(rng)
r = hota(gt_frames, pr_frames)
deta = [x["deta"] for x in r["per_alpha"]]
assert all(a >= b for a, b in zip(deta, deta[1:]))
assert 0 <= r["hota"] <= 1
References
- Jonathon Luiten, Aljosa Osep, Patrick Dendorfer, Philip Torr, Andreas Geiger, Laura Leal-Taixe and Bastian Leibe, HOTA: a higher order metric for evaluating multi-object tracking, International Journal of Computer Vision 129(2), 2021, 548-578, Section 5 (TPA, FNA and FPA, Eq. 10 to 12; HOTA_alpha, Eq. 13 and 14; the matching score, Eq. 15; the mean over 19 thresholds, Eq. 16), Section 6 (LocA, DetA and AssA, Eq. 17 to 19; HOTA_alpha as the geometric mean, Eq. 21; the recall and precision parts, Eq. 22 to 27), Section 7 (detection against trajectory matching), Section 9.1 (the problems of MOTA)
- Keni Bernardin and Rainer Stiefelhagen, Evaluating multiple object tracking performance: the CLEAR MOT metrics, EURASIP Journal on Image and Video Processing 2008, article 246309, the definition of MOTA, which HOTA is compared with
- Ergys Ristani, Francesco Solera, Roger S. Zou, Rita Cucchiara and Carlo Tomasi, Performance measures and a data set for multi-target, multi-camera tracking, ECCV 2016 Workshops, 17-35, Section 3.4 (IDF1, which HOTA is compared with)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H2 full proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag SAT5C8 Edit this page History Report an error Markdown