Definitioncore
CLEAR MOT metrics
Also called MOTA, MOTP.
MOTA counts misses, false positives and identity switches against the number of objects, and MOTP averages the localization error of matched pairs.
The CLEAR MOT metrics are two numbers that score the output of a multi-object tracker against a ground truth. In each frame, the tracker's hypotheses are matched one to one with the true objects. MOTA, the multiple object tracking accuracy, counts three kinds of errors over the whole video: missed objects, false positives and identity switches, and divides their sum by the number of true objects. MOTP, the multiple object tracking precision, is the mean localization quality of the matched pairs. MOTA weighs detection errors much more than identity errors, which is the weakness that the IDF1 score and HOTA address.
Definition
The ground truth gives, for each frame , a set of objects with boxes, and the tracker gives a set of hypotheses with boxes; an identity stays the same over the frames. A similarity , here the intersection over union of the boxes, and a threshold decide when a pair is valid: . The MOT16 benchmark, on boxes, uses . The original paper also allows a distance, such as the distance of two points on the ground, with a pair valid when the distance is below a threshold.
The matching is made frame by frame, and it remembers the matches of the frame before:
CLEAR-MOT(the objects and the hypotheses of each frame, the threshold T)- 1
for each frame t: - 2
keep each match (o, h) of frame t - 1 when o and h are present and s(o, h) ≥ T - 3
match the other objects and hypotheses: the most valid pairs, then the largest total s - 4
for each match (o, h): if o was last matched to some h' ≠ h, count an identity switch - 5
count the misses (unmatched objects), the false positives (unmatched hypotheses) and the matches - 6
MOTA ← 1 - (FN + FP + IDSW) / GT; MOTP ← (sum of s over all matches) / (number of matches)
Line L2 keeps a match even when another hypothesis is closer, as the MOT16 protocol states. Line L3 is an assignment problem, solved with the Hungarian algorithm. Implementations differ in how they weigh the number of pairs against the total similarity; this page takes the most pairs first. The last match of line L4 may be from any earlier frame, so an object that is missed for some frames and then found again by the same hypothesis gives no switch. With the number of objects in frame , , and the counts of the frame, the number of matches and the similarity of match ,
With a distance instead of a similarity, MOTP is the mean distance of the matches, and lower is better. These facts follow from the definition and are proved in the correctness file of this page:
- Theorem: the counts add up. In every frame, the matches plus the misses equal the objects, and the matches plus the false positives equal the hypotheses. The switches are at most the matches.
- Theorem: the range. , with equality exactly when there are no errors. MOTA has no lower bound: false positives can make it as negative as we like. With overlap, .
- Theorem: the matching of line L3 is optimal. It has the most valid pairs among the remaining objects and hypotheses, and among those the largest total similarity.
Examples and non-examples
- A small sequence. Two objects move to the right by 2 pixels per frame, from the boxes and . In frame 1 the hypotheses are with IoU to object 1, exactly on object 2, and on nothing. In frame 2 only is there, exactly on object 2, so object 1 is missed. In frame 3 a new hypothesis is exactly on object 1, and has IoU to object 2. The counts are 6 objects, 5 matches, 1 miss (frame 2), 1 false positive () and 1 identity switch (object 1 goes from to ). So and .
- Keeping the last match. An object at is matched to in frame 1. In frame 2, is at with IoU , and a second hypothesis at has the better IoU . Line L2 keeps , so is a false positive and there is no switch: MOTA is . A matching without line L2 would take , count a switch and a false positive, and give MOTA 0. Line L2 is what keeps a correct track from being punished for a better box nearby.
- Negative MOTA. One object over 3 frames, found in each frame, and 3 false positives in each frame: . MOTA is not a fraction of correct answers.
- Not a measure of identity. One object over 100 frames. Tracker A follows it with hypothesis for 50 frames and then with for 50 frames: one switch, . Tracker B finds it in all 100 frames with the same identity, but adds one false positive: also . The IDF1 score of tracker A is , and that of B is .
- Not a mean over frames. MOTA sums the errors over the whole video before it divides, so frames with many objects weigh more. A per-frame average of is a different number.
Related definitions
MOTA is built from the same counts as precision and recall of detections: with the matches, and , the score without switches is . Identity enters only through switches, which are events in single frames, so a tracker that keeps a wrong identity for a long time pays only once. The IDF1 score instead matches whole trajectories once for the full video and counts the frames that agree with that match. HOTA combines a detection score and an association score with equal weight, and averages over the threshold . The papers of SORT and Deep SORT report MOTA and MOTP; the paper of ByteTrack reports MOTA, IDF1 and HOTA. The Python code of this page computes MOTA and MOTP with exact fractions, and its tests check the matching of line L3 against all matchings, and the whole procedure against a version that uses that brute force matching in every frame.
Proof: The CLEAR MOT matching is a valid one-to-one matching with the most pairs, the counts add up, and MOTA is at most 1 but has no lower boundfull
Notation as on the page. In frame , is the set of objects, the set of hypotheses, the similarity, and a pair is valid when with . The procedure CLEAR-MOT keeps old matches in line L2, matches the rest in line L3, and counts in lines L4 and L5.
Claim 1: each frame gets a one-to-one matching of valid pairs
After line L3, the set of matches of frame uses each object and each hypothesis at most once, and every pair in it is valid.
Proof. The matches of line L2 come from , which is one-to-one by induction ( is empty), and line L2 keeps only pairs whose two members are present and valid. Line L3 works on the objects and the hypotheses that line L2 did not use, so its pairs share no member with the kept ones. The Hungarian algorithm returns an assignment, which is one-to-one, and the code drops the pairs that are not valid.
Claim 2: line L3 finds the most valid pairs, then the largest total similarity
Let the remaining objects be and the remaining hypotheses , with similarities . Let and give the pair the weight if it is valid and 0 if not. A maximum weight assignment, with the pairs of weight 0 then removed, is a matching of valid pairs whose key is the largest in lexicographic order.
Proof. For a matching of valid pairs, with , and . Each such extends to an assignment with the same weight by adding pairs of weight 0, and an assignment loses nothing when its pairs of weight 0 are removed. So the maximum weight assignment, after the removal, is a matching of valid pairs that maximizes .
Let be another matching of valid pairs. If , its key is smaller. If , then , against the choice of ; so this case does not happen. If , then gives . In every case the key of is at most that of . The Hungarian algorithm finds a maximum weight assignment; the proof of its optimality is on the SORT proof and the Hungarian algorithm page.
The tests compare the key of the matching with the largest key over all matchings of small random matrices.
Claim 3: the counts add up
For every frame, and , and .
Proof. By Claim 1, is one-to-one, so it uses exactly objects and hypotheses. Line L5 counts the other objects as misses and the other hypotheses as false positives. Line L4 counts at most one switch for each match.
Summing over the frames gives and , with .
Claim 4: the range of MOTA and MOTP
If , then , with equality exactly when . For every real there is an input with . If there is a match, .
Proof. The three counts are nonnegative, so the fraction in MOTA is at least 0, and it is 0 exactly when all three are 0. For the lower bound, take one object in one frame and hypotheses far from it: and , so , which is below for . MOTP is a mean of similarities of valid pairs, each in by Claim 1, so the mean is in .
Claim 5: what an identity switch counts
Let be the hypothesis that was matched to in its last match before frame , if any. Then is the number of matches with defined and different from . In particular, an object that is missed for some frames and then matched again to the same hypothesis adds no switch, and an object that changes its hypothesis times over the video adds switches.
Proof. The code keeps a table last that it sets to for every match after it tests it, and never changes otherwise. So at the start of frame the table holds , and line L4 counts exactly the stated matches. A change of hypothesis is a match with , which happens times.
This shows why MOTA treats identity lightly: a hypothesis that takes the wrong object and keeps it for the rest of the video costs one switch, the same as a short swap.
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/clear-mot-metrics/. The authors are listed in prov/TXWACJ.jsonl.
"""The CLEAR MOT metrics MOTA and MOTP (Bernardin and Stiefelhagen 2008), with IoU.
A sequence is a list of frames; a frame is a dict from an identity to a box
(x1, y1, x2, y2). A pair (object o, hypothesis h) is valid when IoU(o, h) >= T.
In each frame:
1. the pairs of the frame before stay matched if both are present and valid;
2. the other objects and hypotheses are matched with the most valid pairs,
and among those the largest total IoU (the Hungarian algorithm);
3. a match (o, h) is an identity switch if o was last matched to h' != h;
4. unmatched objects are misses, unmatched hypotheses are false positives.
MOTA = 1 - (FN + FP + IDSW) / GT and MOTP = (sum of IoU of matches) / matches.
With integer boxes all values are exact fractions.
"""
from fractions import Fraction
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 best_matching(sim, threshold):
"""Among the matchings that use only pairs with sim >= threshold, one with the
most pairs and, among those, the largest total sim. sim[i][j] lies in [0, 1].
Returns the sorted list of pairs (i, j)."""
if not sim or not sim[0]:
return []
big = min(len(sim), len(sim[0])) + 1 # one more pair is worth more than any total sim
cost = [[-(big + s) if s >= threshold else 0 for s in row] for row in sim]
return [(i, j) for i, j in hungarian_min(cost) if sim[i][j] >= threshold]
def clear_mot(gt_frames, hyp_frames, threshold=Fraction(1, 2), keep_previous=True):
"""Returns a dict with gt, matches, fn, fp, idsw, sum_iou, mota and motp."""
gt_total = matches = fn = fp = idsw = 0
sum_iou = Fraction(0)
previous = {} # object -> hypothesis, the matches of the frame before
last = {} # object -> the hypothesis it was last matched to, in any earlier frame
for gt, hyp in zip(gt_frames, hyp_frames): # @line L1
current = {}
if keep_previous:
for o, h in previous.items(): # @line L2
if o in gt and h in hyp and iou(gt[o], hyp[h]) >= threshold:
current[o] = h
objs = sorted(o for o in gt if o not in current)
used = set(current.values())
hyps = sorted(h for h in hyp if h not in used)
sim = [[iou(gt[o], hyp[h]) for h in hyps] for o in objs]
for i, j in best_matching(sim, threshold): # @line L3
current[objs[i]] = hyps[j]
for o, h in current.items():
if o in last and last[o] != h: # @line L4
idsw += 1
last[o] = h
sum_iou += iou(gt[o], hyp[h])
gt_total += len(gt) # @line L5
matches += len(current)
fn += len(gt) - len(current)
fp += len(hyp) - len(current)
previous = current
mota = 1 - Fraction(fn + fp + idsw, gt_total) if gt_total else None # @line L6
motp = sum_iou / matches if matches else None
return {"gt": gt_total, "matches": matches, "fn": fn, "fp": fp, "idsw": idsw,
"sum_iou": sum_iou, "mota": mota, "motp": motp}
test_clear_mot_metrics.py 177 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/clear-mot-metrics/. The authors are listed in prov/TXWACJ.jsonl.
import itertools
import random
from fractions import Fraction
from clear_mot_metrics import best_matching, clear_mot, iou
HALF = Fraction(1, 2)
def brute_matching(sim, threshold):
"""All matchings of valid pairs; the key is (number of pairs, total sim)."""
rows = len(sim)
cols = len(sim[0]) if rows else 0
best_key, best = (0, Fraction(0)), []
for k in range(min(rows, cols) + 1):
for rs in itertools.combinations(range(rows), k):
for cs in itertools.permutations(range(cols), k):
pairs = list(zip(rs, cs))
if all(sim[i][j] >= threshold for i, j in pairs):
key = (k, sum((sim[i][j] for i, j in pairs), Fraction(0)))
if key > best_key:
best_key, best = key, pairs
return best_key
def key_of(sim, pairs):
return (len(pairs), sum((sim[i][j] for i, j in pairs), Fraction(0)))
def test_iou_values():
assert iou((0, 0, 10, 10), (1, 0, 11, 10)) == Fraction(9, 11)
assert iou((0, 0, 10, 10), (3, 0, 13, 10)) == Fraction(7, 13)
assert iou((0, 0, 10, 10), (20, 0, 30, 10)) == 0
def test_best_matching_against_brute_force():
rng = random.Random(1)
for _ in range(300):
r, c = rng.randint(0, 4), rng.randint(0, 4)
sim = [[Fraction(rng.randint(0, 10), 10) for _ in range(c)] for _ in range(r)]
if r == 0:
sim = []
pairs = best_matching(sim, HALF)
assert len({i for i, _ in pairs}) == len(pairs) == len({j for _, j in pairs})
assert all(sim[i][j] >= HALF for i, j in pairs)
assert key_of(sim, pairs) == brute_matching(sim, HALF)
PAGE_GT = [
{1: (0, 0, 10, 10), 2: (20, 0, 30, 10)},
{1: (2, 0, 12, 10), 2: (22, 0, 32, 10)},
{1: (4, 0, 14, 10), 2: (24, 0, 34, 10)},
]
PAGE_HYP = [
{"a": (1, 0, 11, 10), "b": (20, 0, 30, 10), "c": (50, 50, 60, 60)},
{"b": (22, 0, 32, 10)},
{"d": (4, 0, 14, 10), "b": (25, 0, 35, 10)},
]
def test_page_example():
r = clear_mot(PAGE_GT, PAGE_HYP)
assert (r["gt"], r["matches"], r["fn"], r["fp"], r["idsw"]) == (6, 5, 1, 1, 1)
assert r["mota"] == HALF
assert r["motp"] == Fraction(51, 55)
def test_previous_pairs_are_kept():
gt = [{1: (0, 0, 10, 10)}, {1: (0, 0, 10, 10)}]
hyp = [{"h": (0, 0, 10, 10)}, {"h": (3, 0, 13, 10), "g": (1, 0, 11, 10)}]
kept = clear_mot(gt, hyp)
assert (kept["idsw"], kept["fp"], kept["mota"]) == (0, 1, HALF)
assert kept["motp"] == (1 + Fraction(7, 13)) / 2
plain = clear_mot(gt, hyp, keep_previous=False)
assert (plain["idsw"], plain["fp"], plain["mota"]) == (1, 1, 0)
def test_switch_is_counted_against_the_last_match():
box = (0, 0, 10, 10)
gt = [{1: box}] * 4
hyp = [{"a": box}, {}, {"a": box}, {"b": box}]
r = clear_mot(gt, hyp)
assert (r["matches"], r["fn"], r["idsw"]) == (3, 1, 1)
def test_bounds_of_mota():
box = (0, 0, 10, 10)
gt = [{1: box}] * 3
assert clear_mot(gt, [{"a": box}] * 3)["mota"] == 1
assert clear_mot(gt, [{}] * 3)["mota"] == 0
far = {"x": (50, 0, 60, 10), "y": (70, 0, 80, 10), "z": (90, 0, 100, 10)}
assert clear_mot(gt, [dict(far, a=box)] * 3)["mota"] == -2
def random_box(rng):
x, y = rng.randint(0, 12), rng.randint(0, 12)
return (x, y, x + rng.randint(3, 6), y + rng.randint(3, 6))
def reference(gt_frames, hyp_frames, threshold):
"""The same procedure with a brute force matching in each frame; returns the counts."""
previous, last = {}, {}
out = [0, 0, 0, 0, 0, Fraction(0)]
for gt, hyp in zip(gt_frames, hyp_frames):
cur = {o: h for o, h in previous.items() if o in gt and h in hyp and iou(gt[o], hyp[h]) >= threshold}
objs = [o for o in sorted(gt) if o not in cur]
hyps = [h for h in sorted(hyp) if h not in cur.values()]
sim = [[iou(gt[o], hyp[h]) for h in hyps] for o in objs]
best_key, best = (-1, 0), []
for k in range(min(len(objs), len(hyps)) + 1):
for rs in itertools.combinations(range(len(objs)), k):
for cs in itertools.permutations(range(len(hyps)), k):
pairs = list(zip(rs, cs))
if all(sim[i][j] >= threshold for i, j in pairs):
key = key_of(sim, pairs)
if key > best_key:
best_key, best = key, pairs
for i, j in best:
cur[objs[i]] = hyps[j]
for o, h in cur.items():
out[4] += o in last and last[o] != h
last[o] = h
out[5] += iou(gt[o], hyp[h])
out[0] += len(gt)
out[1] += len(cur)
out[2] += len(gt) - len(cur)
out[3] += len(hyp) - len(cur)
previous = cur
return out
def random_sequence(rng):
"""Objects that move a little; a tracker that copies them with jitter, sometimes
with another identity, sometimes not at all, plus random false positives."""
start = {o: random_box(rng) for o in range(4)}
names = {o: "abcd"[o] for o in range(4)}
gt_frames, hyp_frames = [], []
for t in range(rng.randint(1, 6)):
gt, hyp = {}, {}
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.15:
names[o] = rng.choice("abcdef")
if rng.random() < 0.8 and names[o] not in hyp:
dx = rng.randint(-1, 1)
g = gt[o]
hyp[names[o]] = (g[0] + dx, g[1], g[2] + dx, g[3] + rng.randint(-1, 1))
if rng.random() < 0.4:
hyp["z"] = random_box(rng)
gt_frames.append(gt)
hyp_frames.append(hyp)
return gt_frames, hyp_frames
def test_against_reference_and_invariants():
rng = random.Random(2)
switches = 0
for _ in range(80):
gt_frames, hyp_frames = random_sequence(rng)
r = clear_mot(gt_frames, hyp_frames)
ref = reference(gt_frames, hyp_frames, HALF)
assert [r[k] for k in ("gt", "matches", "fn", "fp", "idsw", "sum_iou")] == ref
switches += r["idsw"]
hyp_total = sum(len(h) for h in hyp_frames)
assert r["fn"] + r["matches"] == r["gt"]
assert r["fp"] + r["matches"] == hyp_total
assert r["idsw"] <= r["matches"]
if r["gt"]:
assert r["mota"] == 1 - Fraction(r["fn"] + r["fp"] + r["idsw"], r["gt"])
assert r["mota"] <= 1
if r["matches"]:
assert HALF <= r["motp"] <= 1
assert switches >= 5 # the sequences do exercise identity switches
References
- 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 whole paper (the frame by frame mapping of hypotheses to objects, the counting of mismatches, and the definitions of MOTP and MOTA)
- Anton Milan, Laura Leal-Taixe, Ian Reid, Stefan Roth and Konrad Schindler, MOT16: a benchmark for multi-object tracking, arXiv:1603.00831, 2016, Section IV-A1 (the kept correspondences and the switches against the last known match), Section IV-A2 (the IoU threshold 0.5), Section IV-A4, Eq. 1 (MOTA) and Section IV-A5, Eq. 2 (MOTP)
- 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, the discussion of the measures based on events, such as MOTA, compared with the identity measures
- 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 4.1 (MOTA in the notation of HOTA) and Section 9.1 (the problems of MOTA, among them that detection outweighs association and that a switch looks only at the previous match)
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 TXWACJ Edit this page History Report an error Markdown