Algorithm Search⌘K

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 α\alpha, 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. HOTAα\mathrm{HOTA}_\alpha 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 S∈[0,1]S \in [0, 1] of two boxes is usually the intersection over union. Fix α∈(0,1)\alpha \in (0, 1). In each frame, a one-to-one matching of true to predicted detections with S≥αS \ge \alpha 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 cc with the true identity gg and the predicted identity pp:

  • TPA(c)\mathrm{TPA}(c) is the set of true positives with the same pair of identities (g,p)(g, p);
  • FNA(c)\mathrm{FNA}(c) is the set of true detections of gg that are not matched to pp: true positives with another predicted identity, and misses;
  • FPA(c)\mathrm{FPA}(c) is the set of predicted detections of pp that are not matched to gg: true positives with another true identity, and false positives.
A(c)=∣TPA(c)∣∣TPA(c)∣+∣FNA(c)∣+∣FPA(c)∣,HOTAα=∑c∈TPA(c)∣TP∣+∣FN∣+∣FP∣,HOTA=119∑α∈{0.05,0.10,…,0.95}HOTAα.\mathcal{A}(c) = \frac{|\mathrm{TPA}(c)|}{|\mathrm{TPA}(c)| + |\mathrm{FNA}(c)| + |\mathrm{FPA}(c)|}, \qquad \mathrm{HOTA}_\alpha = \sqrt{\frac{\sum_{c \in \mathrm{TP}} \mathcal{A}(c)}{|\mathrm{TP}| + |\mathrm{FN}| + |\mathrm{FP}|}}, \qquad \mathrm{HOTA} = \frac{1}{19} \sum_{\alpha \in \{0.05, 0.10, \ldots, 0.95\}} \mathrm{HOTA}_\alpha.

The parts are DetAα=∣TP∣/(∣TP∣+∣FN∣+∣FP∣)\mathrm{DetA}_\alpha = |\mathrm{TP}| / (|\mathrm{TP}| + |\mathrm{FN}| + |\mathrm{FP}|), AssAα=1∣TP∣∑c∈TPA(c)\mathrm{AssA}_\alpha = \frac{1}{|\mathrm{TP}|} \sum_{c \in \mathrm{TP}} \mathcal{A}(c), and the localization accuracy LocAα\mathrm{LocA}_\alpha, the mean of SS over the true positives. If ∣g∣|g| and ∣p∣|p| are the numbers of detections of gg and pp, then ∣FNA(c)∣=∣g∣−∣TPA(c)∣|\mathrm{FNA}(c)| = |g| - |\mathrm{TPA}(c)| and ∣FPA(c)∣=∣p∣−∣TPA(c)∣|\mathrm{FPA}(c)| = |p| - |\mathrm{TPA}(c)|, so A(c)\mathcal{A}(c) 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

MS(g,p)=1ε+Amax⁡(g,p)+ε S(g,p)for S(g,p)≥α,\mathrm{MS}(g, p) = \frac{1}{\varepsilon} + \mathcal{A}_{\max}(g, p) + \varepsilon\, S(g, p) \quad \text{for } S(g, p) \ge \alpha,

with a small ε\varepsilon. The first term asks for the most true positives, the second for the best association, and the third for the best boxes. Amax⁡(g,p)\mathcal{A}_{\max}(g, p) is the largest A\mathcal{A} the pair could get if every frame could match it: n/(∣g∣+∣p∣−n)n / (|g| + |p| - n), where nn is the number of frames in which gg and pp have S≥αS \ge \alpha. The full procedure:

  1. HOTA(the true and the predicted detections)
  2. 1for each α in {0.05, 0.10, ..., 0.95}:
  3. 2in each frame, match the detections with S ≥ α, maximizing the sum of MS (Hungarian)
  4. 3count TP, FN and FP; for each identity pair (g, p), |TPA| = its number of true positives
  5. 4DetA_α ← TP / (TP + FN + FP); AssA_α ← mean of A(c) over TP; HOTA_α ← sqrt(DetA_α · AssA_α)
  6. 5HOTA ← 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. HOTAα=DetAα⋅AssAα\mathrm{HOTA}_\alpha = \sqrt{\mathrm{DetA}_\alpha \cdot \mathrm{AssA}_\alpha} whenever there is a true positive (Eq. 21 of the paper).
  • Theorem: the most true positives. If 1/ε>k(1+ε)1/\varepsilon > k (1 + \varepsilon), where kk 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 α\alpha. A larger threshold allows fewer pairs, so the largest matching cannot grow, and DetAα\mathrm{DetA}_\alpha falls or stays.
  • Theorem: the range. 0≤HOTAα≤10 \le \mathrm{HOTA}_\alpha \le 1, and HOTAα=1\mathrm{HOTA}_\alpha = 1 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 aa and bb, which swap after frame 4. For every α\alpha all 12 detections are true positives, so DetAα=1\mathrm{DetA}_\alpha = 1. The pair (1,a)(1, a) has ∣TPA∣=4|\mathrm{TPA}| = 4 and ∣g∣=∣p∣=6|g| = |p| = 6, so A=4/(6+6−4)=1/2\mathcal{A} = 4 / (6 + 6 - 4) = 1/2; the pair (1,b)(1, b) has A=2/10=1/5\mathcal{A} = 2 / 10 = 1/5, and the same holds for object 2. So AssA=(8⋅12+4⋅15)/12=2/5\mathrm{AssA} = (8 \cdot \tfrac12 + 4 \cdot \tfrac15) / 12 = 2/5 and HOTA=2/5≈0.632\mathrm{HOTA} = \sqrt{2/5} \approx 0.632. On the same input MOTA=5/6\mathrm{MOTA} = 5/6 and IDF1=2/3\mathrm{IDF1} = 2/3.
  • A box that is a little off. One object over 5 frames at (0,0,8,10)(0,0,8,10), and the tracker always gives (2,0,10,10)(2,0,10,10), with IoU 60/100=0.660/100 = 0.6. For the 12 thresholds α≤0.6\alpha \le 0.6, every detection is a true positive and HOTAα=1\mathrm{HOTA}_\alpha = 1; for the 7 thresholds above, there are no true positives and HOTAα=0\mathrm{HOTA}_\alpha = 0. So HOTA=12/19≈0.632\mathrm{HOTA} = 12/19 \approx 0.632, and LocA=0.6\mathrm{LocA} = 0.6 on the thresholds with true positives. MOTA with the threshold 0.5 would be 1: HOTA also asks for good boxes.
  • Not the product. HOTAα\mathrm{HOTA}_\alpha is a geometric mean, not a product. With DetA=1\mathrm{DetA} = 1 and AssA=0.25\mathrm{AssA} = 0.25 it is 0.50.5, not 0.250.25.
  • Not the mean of the parts over α\alpha. HOTA averages DetAαAssAα\sqrt{\mathrm{DetA}_\alpha \mathrm{AssA}_\alpha}, which is in general not DetA⋅AssA\sqrt{\mathrm{DetA} \cdot \mathrm{AssA}} of the averaged parts. In the second example the averaged parts are both 12/1912/19, and their geometric mean happens to agree, but with DetAα\mathrm{DetA}_\alpha and AssAα\mathrm{AssA}_\alpha that fall at different thresholds it does not.

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 A\mathcal{A} of the two trajectories it links, which needs no global matching. DetA and AssA split into recall and precision parts, DetRe\mathrm{DetRe}, DetPr\mathrm{DetPr}, AssRe\mathrm{AssRe} and AssPr\mathrm{AssPr}, 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 A(c)\mathcal{A}(c) again from the set definitions, and check that DetA does not grow with α\alpha.

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 α\alpha. GG and PP are the numbers of true and predicted detections over all frames, TP is the set of matches made by line L2, and ∣FN∣=G−∣TP∣|\mathrm{FN}| = G - |\mathrm{TP}| and ∣FP∣=P−∣TP∣|\mathrm{FP}| = P - |\mathrm{TP}|.

Claim 1: the sizes of FNA and FPA

For a true positive cc with identities (g,p)(g, p), ∣FNA(c)∣=∣g∣−∣TPA(c)∣|\mathrm{FNA}(c)| = |g| - |\mathrm{TPA}(c)| and ∣FPA(c)∣=∣p∣−∣TPA(c)∣|\mathrm{FPA}(c)| = |p| - |\mathrm{TPA}(c)|. So A(c)\mathcal{A}(c) depends only on the pair (g,p)(g, p), and ∑c∈TPA(c)=∑(g,p)kgp2/(∣g∣+∣p∣−kgp)\sum_{c \in \mathrm{TP}} \mathcal{A}(c) = \sum_{(g, p)} k_{gp}^2 / (|g| + |p| - k_{gp}), where kgpk_{gp} is the number of true positives with the identities (g,p)(g, p).

Proof. Each true detection of gg is either a true positive, with some predicted identity, or a miss. Those that are true positives with pp form TPA(c)\mathrm{TPA}(c), and all the others form FNA(c)\mathrm{FNA}(c) by its definition. So the two sets split the ∣g∣|g| detections of gg. The same argument on the predicted side gives the second formula. Then A(c)=kgp/(kgp+(∣g∣−kgp)+(∣p∣−kgp))\mathcal{A}(c) = k_{gp} / (k_{gp} + (|g| - k_{gp}) + (|p| - k_{gp})), and the kgpk_{gp} true positives with the pair (g,p)(g, p) each add this value. □\square

The code uses this formula, and the tests compute A(c)\mathcal{A}(c) again from the set definitions.

Claim 2: the geometric mean

If ∣TP∣>0|\mathrm{TP}| > 0, then HOTAα=DetAα⋅AssAα\mathrm{HOTA}_\alpha = \sqrt{\mathrm{DetA}_\alpha \cdot \mathrm{AssA}_\alpha}.

Proof. DetAα⋅AssAα=∣TP∣∣TP∣+∣FN∣+∣FP∣⋅1∣TP∣∑c∈TPA(c)=∑cA(c)∣TP∣+∣FN∣+∣FP∣\mathrm{DetA}_\alpha \cdot \mathrm{AssA}_\alpha = \dfrac{|\mathrm{TP}|}{|\mathrm{TP}| + |\mathrm{FN}| + |\mathrm{FP}|} \cdot \dfrac{1}{|\mathrm{TP}|} \sum_{c \in \mathrm{TP}} \mathcal{A}(c) = \dfrac{\sum_{c} \mathcal{A}(c)}{|\mathrm{TP}| + |\mathrm{FN}| + |\mathrm{FP}|}, the number under the square root in the definition of HOTAα\mathrm{HOTA}_\alpha. □\square

If there is no true positive, the sum is empty and HOTAα=0\mathrm{HOTA}_\alpha = 0; the code then sets AssAα=0\mathrm{AssA}_\alpha = 0, so the formula holds in this case as well.

Claim 3: the most true positives

Let kk be the largest number of pairs in a matching of one frame, and let 1/ε>k(1+ε)1/\varepsilon > k (1 + \varepsilon). Then the matching of line L2 has the largest number of pairs with S≥αS \ge \alpha in its frame.

Proof. Line L2 gives each pair with S≥αS \ge \alpha the weight MS=1/ε+Amax⁡+εS\mathrm{MS} = 1/\varepsilon + \mathcal{A}_{\max} + \varepsilon S 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 MM of allowed pairs with the largest total MS. Since 0≤Amax⁡≤10 \le \mathcal{A}_{\max} \le 1 and 0≤S≤10 \le S \le 1, a matching with mm pairs has a total in [m/ε,m/ε+m(1+ε)][m/\varepsilon, m/\varepsilon + m(1 + \varepsilon)]. If some matching M′M' had more pairs than MM, say m′≥m+1m' \ge m + 1, then

MS(M)≤mε+k(1+ε)<mε+1ε≤m′ε≤MS(M′),\mathrm{MS}(M) \le \frac{m}{\varepsilon} + k(1 + \varepsilon) < \frac{m}{\varepsilon} + \frac{1}{\varepsilon} \le \frac{m'}{\varepsilon} \le \mathrm{MS}(M'),

against the choice of MM. □\square

With equal numbers of pairs, the same argument shows that the term Amax⁡\mathcal{A}_{\max} decides first when εk\varepsilon k is below the smallest positive gap between two sums of Amax⁡\mathcal{A}_{\max}, and then the term εS\varepsilon S decides. This order is the one that the paper asks for. The code uses ε=10−6\varepsilon = 10^{-6} 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 α<α′\alpha < \alpha' and the condition of Claim 3 holds, then DetAα′≤DetAα\mathrm{DetA}_{\alpha'} \le \mathrm{DetA}_\alpha.

Proof. Every pair with S≥α′S \ge \alpha' also has S≥αS \ge \alpha, so every matching allowed at α′\alpha' is allowed at α\alpha. By Claim 3, the number of true positives in each frame is the largest matching size, so it is at least as large at α\alpha as at α′\alpha'. Summing over the frames gives T=∣TPα∣≥T′=∣TPα′∣T = |\mathrm{TP}_\alpha| \ge T' = |\mathrm{TP}_{\alpha'}|. Now DetA=T/(T+(G−T)+(P−T))=T/(G+P−T)\mathrm{DetA} = T / (T + (G - T) + (P - T)) = T / (G + P - T), which increases with TT for fixed G+PG + P, since the numerator grows and the denominator falls. □\square

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

0≤HOTAα≤10 \le \mathrm{HOTA}_\alpha \le 1, and HOTAα=1\mathrm{HOTA}_\alpha = 1 exactly when there are no misses and no false positives at α\alpha and every true positive cc has FNA(c)=FPA(c)=∅\mathrm{FNA}(c) = \mathrm{FPA}(c) = \emptyset, 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 A(c)\mathcal{A}(c) is in [0,1][0, 1], so the sum under the root is between 0 and ∣TP∣/(∣TP∣+∣FN∣+∣FP∣)≤1|\mathrm{TP}| / (|\mathrm{TP}| + |\mathrm{FN}| + |\mathrm{FP}|) \le 1. It equals 1 exactly when both inequalities are equalities: ∣FN∣=∣FP∣=0|\mathrm{FN}| = |\mathrm{FP}| = 0 and A(c)=1\mathcal{A}(c) = 1 for every cc, which means FNA(c)=FPA(c)=∅\mathrm{FNA}(c) = \mathrm{FPA}(c) = \emptyset. HOTA, a mean of numbers in [0,1][0, 1], is also in [0,1][0, 1]. □\square

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.

hota_metric.pyI0RawGitHub
# 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

  1. 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)
  2. 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
  3. 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.

LadderLevelWhat the next level needs
Human proofH2 full proof
  • correctness: no review record reviews/SAT5C8/proof-correctness.yaml
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/SAT5C8/text.yaml