Project 5: Multi-Object Tracking
In the tracking lesson SORT tracked three vehicles in separate lanes without a single identity switch. That was the easy case. In this project the objects move in every direction, bounce off the borders, cross each other's paths and hide each other, and the detector is noisy. You start from the lesson's SORT, measure it with MOTA and IDF1, tune its parameters on development videos, find the remaining identity switches one by one, fix their cause, and report the final tracker once on test videos it has never seen.
Goal and success criteria
| Requirement | Metric | Target |
|---|---|---|
| Objects are covered in most frames | MOTA (pooled FN, FP, IDSW over all true boxes) | at least 0.90 |
| Each object keeps one identity | IDF1 (mean over videos) and the IDSW count | IDF1 at least 0.93, IDSW in single digits |
| Online | uses only past and current frames | yes |
Both metrics come from the lesson; the identity target is the hard one, because identity errors are what make a track useless for counting, dwell times or trajectories.
The data and the detector
make_crossing is this project's variant of make_video: 60 frames, 160 x 90, seven rectangles of different sizes and grey levels that move at constant speed in random directions and bounce off the borders, so their velocity changes suddenly. Objects drawn later hide earlier ones, and the ground truth records for every box how much of it is visible. A simulated detector turns the truth into detections: an object less than half visible is never detected (occlusion), the others are dropped with probability 0.1, every box corner is jittered by 1 pixel, and 0.2 false boxes per frame appear at random. The detector has its own seed (100 + video seed), so detections are reproducible.
Seeds 0 and 1 are the development videos on which every choice is made; seeds 2 and 3 are the test videos, used once at the end.
import numpy as np
def bounce(p, lo, hi):
"""Position p reflected into [lo, hi]: an object that reaches a border bounces back."""
span = hi - lo
q = (p - lo) % (2 * span)
return lo + (q if q <= span else 2 * span - q)
def make_crossing(rng, n_frames=60, h=90, w=160, n_objects=7):
"""Project variant of make_video: objects move at constant speed in all directions and bounce off
the borders, so paths cross and nearer objects (drawn later) hide farther ones.
Each object has its own grey level.
Returns frames (T, h, w) uint8 and gt per frame: list of (id, [x1, y1, x2, y2], visible fraction)."""
objs = []
for k in range(n_objects):
bw, bh = int(rng.integers(12, 20)), int(rng.integers(10, 16))
x, y = float(rng.uniform(0, w - bw)), float(rng.uniform(0, h - bh))
speed, angle = float(rng.uniform(1.0, 2.5)), float(rng.uniform(0, 2 * np.pi))
objs.append([x, y, bw, bh, speed * np.cos(angle), speed * np.sin(angle), int(rng.integers(120, 250))])
frames, gt = [], []
for t in range(n_frames):
f = rng.normal(60, 6, (h, w))
owner = np.full((h, w), -1)
boxes = []
for k, (x, y, bw, bh, vx, vy, g) in enumerate(objs):
x1, y1 = int(round(bounce(x + vx * t, 0, w - bw))), int(round(bounce(y + vy * t, 0, h - bh)))
bx = [x1, y1, x1 + bw, y1 + bh]
f[bx[1]:bx[3], bx[0]:bx[2]] = g; owner[bx[1]:bx[3], bx[0]:bx[2]] = k
boxes.append([k, bx])
gt.append([(k, b, float(np.mean(owner[b[1]:b[3], b[0]:b[2]] == k))) for k, b in boxes])
frames.append(f.clip(0, 255).astype(np.uint8))
return np.array(frames), gt
def noisy_detector(gt, rng, p_miss=0.1, jitter=1.0, false_rate=0.2, min_visible=0.5, h=90, w=160):
"""Simulated detector: misses objects less than min_visible visible, drops the rest with p_miss,
jitters corners, adds Poisson(false_rate) false boxes per frame. Returns (n, 4) arrays, no ids."""
out = []
for objects in gt:
d = [np.array(b, float) + rng.normal(0, jitter, 4) for _, b, vis in objects
if vis >= min_visible and rng.random() > p_miss]
for _ in range(rng.poisson(false_rate)):
x, y = rng.uniform(0, w - 15), rng.uniform(0, h - 12)
d.append(np.array([x, y, x + 15, y + 12]))
out.append(np.array(d).reshape(-1, 4))
return out
for seed in (0, 1): # the two development videos
frames, gt = make_crossing(np.random.default_rng(seed))
dets = noisy_detector(gt, np.random.default_rng(100 + seed))
n_gt = sum(len(g) for g in gt)
hidden = sum(v < 0.5 for g in gt for _, _, v in g)
pairs = set()
for g in gt: # which objects overlap at some point (crossings)
for i in range(len(g)):
for j in range(i + 1, len(g)):
a, b = g[i][1], g[j][1]
if min(a[2], b[2]) > max(a[0], b[0]) and min(a[3], b[3]) > max(a[1], b[1]):
pairs.add((g[i][0], g[j][0]))
print(f"seed {seed}: {frames.shape[0]} frames, 7 objects, {n_gt} true boxes, {hidden} less than half visible, "
f"{sum(len(d) for d in dets)} detections")
print(f" objects that overlap at some time: {sorted(pairs)}")
print("frame 0 of seed 0:", [(k, b, round(v, 2)) for k, b, v in make_crossing(np.random.default_rng(0))[1][0]])seed 0: 60 frames, 7 objects, 420 true boxes, 15 less than half visible, 379 detections
objects that overlap at some time: [(1, 2), (1, 4), (1, 5), (2, 4), (2, 5), (4, 5), (5, 6)]
seed 1: 60 frames, 7 objects, 420 true boxes, 4 less than half visible, 386 detections
objects that overlap at some time: [(0, 5), (2, 3), (2, 6), (4, 6)]
frame 0 of seed 0: [(0, [38, 3, 56, 16], 1.0), (1, [103, 42, 122, 55], 0.83), (2, [123, 3, 140, 13], 1.0), (3, [43, 34, 61, 44], 1.0), (4, [96, 47, 108, 61], 0.5), (5, [92, 54, 111, 66], 1.0), (6, [76, 24, 92, 38], 1.0)]
Each video has 420 true boxes (7 objects in 60 frames). Seed 0 is the hard one: 7 pairs of objects overlap at some point and 15 boxes are less than half visible, so they are never detected; overall the detector delivers 379 detections, about 10 % fewer than true boxes plus a few false alarms. Even frame 0 of seed 0 starts with object 4 half hidden behind object 5 (visible fraction 0.5).
Step 1: baseline and parameter sweep
The tracker is the lesson's SORT (Kalman filter on centre, size and velocity; IoU cost; Hungarian matching) with two practical changes and two options:
- A track is confirmed once it has
min_hits = 2matches and then stays confirmed (the lesson's version needed a fresh streak after every miss, which cost many false negatives). coast: a confirmed track that missed up tocoastframes is still reported, at its predicted box. With a detector that misses 10 % of the objects, this trades a few false positives for many fewer false negatives.cascadeandapp_weight, the two improvements of step 3, are off for now.
The baseline uses the lesson's values (max_age 3, iou_thr 0.3, no coasting). Then a small grid over coasting, max_age and the IoU threshold, scored on the two development videos together:
import numpy as np
def bounce(p, lo, hi):
"""Position p reflected into [lo, hi]: an object that reaches a border bounces back."""
span = hi - lo
q = (p - lo) % (2 * span)
return lo + (q if q <= span else 2 * span - q)
def make_crossing(rng, n_frames=60, h=90, w=160, n_objects=7):
"""Project variant of make_video: objects move at constant speed in all directions and bounce off
the borders, so paths cross and nearer objects (drawn later) hide farther ones.
Each object has its own grey level.
Returns frames (T, h, w) uint8 and gt per frame: list of (id, [x1, y1, x2, y2], visible fraction)."""
objs = []
for k in range(n_objects):
bw, bh = int(rng.integers(12, 20)), int(rng.integers(10, 16))
x, y = float(rng.uniform(0, w - bw)), float(rng.uniform(0, h - bh))
speed, angle = float(rng.uniform(1.0, 2.5)), float(rng.uniform(0, 2 * np.pi))
objs.append([x, y, bw, bh, speed * np.cos(angle), speed * np.sin(angle), int(rng.integers(120, 250))])
frames, gt = [], []
for t in range(n_frames):
f = rng.normal(60, 6, (h, w))
owner = np.full((h, w), -1)
boxes = []
for k, (x, y, bw, bh, vx, vy, g) in enumerate(objs):
x1, y1 = int(round(bounce(x + vx * t, 0, w - bw))), int(round(bounce(y + vy * t, 0, h - bh)))
bx = [x1, y1, x1 + bw, y1 + bh]
f[bx[1]:bx[3], bx[0]:bx[2]] = g; owner[bx[1]:bx[3], bx[0]:bx[2]] = k
boxes.append([k, bx])
gt.append([(k, b, float(np.mean(owner[b[1]:b[3], b[0]:b[2]] == k))) for k, b in boxes])
frames.append(f.clip(0, 255).astype(np.uint8))
return np.array(frames), gt
def noisy_detector(gt, rng, p_miss=0.1, jitter=1.0, false_rate=0.2, min_visible=0.5, h=90, w=160):
"""Simulated detector: misses objects less than min_visible visible, drops the rest with p_miss,
jitters corners, adds Poisson(false_rate) false boxes per frame. Returns (n, 4) arrays, no ids."""
out = []
for objects in gt:
d = [np.array(b, float) + rng.normal(0, jitter, 4) for _, b, vis in objects
if vis >= min_visible and rng.random() > p_miss]
for _ in range(rng.poisson(false_rate)):
x, y = rng.uniform(0, w - 15), rng.uniform(0, h - 12)
d.append(np.array([x, y, x + 15, y + 12]))
out.append(np.array(d).reshape(-1, 4))
return out
from scipy.optimize import linear_sum_assignment
def iou_matrix(a, b):
a, b = np.asarray(a, float).reshape(-1, 4)[:, None], np.asarray(b, float).reshape(-1, 4)[None]
iw = np.clip(np.minimum(a[..., 2], b[..., 2]) - np.maximum(a[..., 0], b[..., 0]), 0, None)
ih = np.clip(np.minimum(a[..., 3], b[..., 3]) - np.maximum(a[..., 1], b[..., 1]), 0, None)
inter = iw * ih
area = lambda r: (r[..., 2] - r[..., 0]) * (r[..., 3] - r[..., 1])
return inter / (area(a) + area(b) - inter)
class KalmanBox:
"""Constant-velocity Kalman filter on the box centre; width and height as slowly varying states.
State x = [cx, cy, w, h, vx, vy]."""
def __init__(self, box, q=1.0, r=1.0):
cx, cy, w, h = (box[0] + box[2]) / 2, (box[1] + box[3]) / 2, box[2] - box[0], box[3] - box[1]
self.x = np.array([cx, cy, w, h, 0.0, 0.0])
self.P = np.diag([r, r, r, r, 100.0, 100.0]) # velocity unknown at birth
self.F = np.eye(6); self.F[0, 4] = self.F[1, 5] = 1.0 # position += velocity (dt = 1 frame)
self.H = np.eye(4, 6) # we measure cx, cy, w, h
self.Q = np.diag([q, q, 0.1, 0.1, 0.1 * q, 0.1 * q]); self.R = r * np.eye(4)
def predict(self):
self.x = self.F @ self.x; self.P = self.F @ self.P @ self.F.T + self.Q
return self.box()
def update(self, box):
z = np.array([(box[0] + box[2]) / 2, (box[1] + box[3]) / 2, box[2] - box[0], box[3] - box[1]])
S = self.H @ self.P @ self.H.T + self.R
K = self.P @ self.H.T @ np.linalg.inv(S)
self.x = self.x + K @ (z - self.H @ self.x); self.P = (np.eye(6) - K @ self.H) @ self.P
def box(self):
cx, cy, w, h = self.x[:4]
return [cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2]
def appearance(frame, box):
"""A one-number appearance descriptor: the median grey level inside the box (2 px inset)."""
x1, y1, x2, y2 = [int(round(v)) for v in box]
patch = frame[max(y1 + 2, 0):max(y2 - 2, y1 + 3), max(x1 + 2, 0):max(x2 - 2, x1 + 3)]
return float(np.median(patch)) if patch.size else 0.0
def sort_tracker(dets, frames=None, iou_thr=0.3, max_age=3, min_hits=2, app_weight=0.0, app_gate=40.0, coast=0, cascade=False):
"""SORT with an optional appearance term (the DeepSORT idea): cost = 1 - IoU + app_weight * |grey
difference| / 100, and pairs whose grey levels differ by more than app_gate are forbidden.
min_hits: matches needed before a track is confirmed (it then stays confirmed).
cascade: match confirmed tracks first, tentative tracks only with the detections left over.
coast: also report confirmed tracks unmatched for up to frames, at their predicted box.
Returns per frame a list of (track_id, box)."""
tracks, next_id, out = [], 1, []
for t, D in enumerate(dets):
preds = [tr["kf"].predict() for tr in tracks]
app = [appearance(frames[t], d) for d in D] if app_weight else [0.0] * len(D)
matches, unmatched = [], set(range(len(D)))
if tracks and len(D):
iou = iou_matrix(preds, D)
diff = np.abs(np.array([tr["app"] for tr in tracks])[:, None] - np.array(app)[None, :])
cost = 1 - iou + app_weight * diff / 100
if app_weight:
cost[diff > app_gate] = 10.0
groups = ([[i for i, tr in enumerate(tracks) if tr["confirmed"]], [i for i, tr in enumerate(tracks) if not tr["confirmed"]]]
if cascade else [list(range(len(tracks)))])
for rows in groups:
cols = sorted(unmatched)
if not rows or not cols:
continue
for a, b in zip(*linear_sum_assignment(cost[np.ix_(rows, cols)])):
i, j = rows[a], cols[b]
if iou[i, j] >= iou_thr and cost[i, j] < 10:
matches.append((i, j)); unmatched.discard(j)
matched = {i for i, _ in matches}
for i, j in matches:
tr = tracks[i]; tr["kf"].update(D[j]); tr["hits"] += 1; tr["age"] = 0
tr["confirmed"] = tr["confirmed"] or tr["hits"] >= min_hits
tr["app"] = 0.8 * tr["app"] + 0.2 * app[j]
for i, tr in enumerate(tracks):
if i not in matched:
tr["age"] += 1
for j in sorted(unmatched):
tracks.append({"id": next_id, "kf": KalmanBox(D[j]), "hits": 1, "age": 0, "app": app[j], "confirmed": min_hits <= 1}); next_id += 1
tracks = [tr for tr in tracks if tr["age"] <= max_age]
out.append([(tr["id"], tr["kf"].box()) for tr in tracks if tr["confirmed"] and tr["age"] <= coast])
return out
def mot_metrics(gt, hyp, thr=0.5):
"""CLEAR-MOT counts (FN, FP, ID switches, MOTA) and IDF1, from scratch."""
fn = fp = idsw = n_gt = 0
last = {} # gt id -> track id it was last matched to
pair_frames = {} # (gt id, track id) -> frames matched
for G, Hy in zip(gt, hyp):
n_gt += len(G)
if G and Hy:
iou = iou_matrix([b for _, b in G], [b for _, b in Hy])
rows, cols = linear_sum_assignment(-iou)
pairs = [(G[i][0], Hy[j][0]) for i, j in zip(rows, cols) if iou[i, j] >= thr]
else:
pairs = []
for g, h in pairs:
if g in last and last[g] != h:
idsw += 1
last[g] = h
pair_frames[(g, h)] = pair_frames.get((g, h), 0) + 1
fn += len(G) - len(pairs); fp += len(Hy) - len(pairs)
gids = sorted({g for G in gt for g, _ in G}); hids = sorted({h for Hy in hyp for h, _ in Hy})
M = np.zeros((len(gids), len(hids)))
for (g, h), n in pair_frames.items():
M[gids.index(g), hids.index(h)] = n
r, c = linear_sum_assignment(-M) if M.size else ([], [])
idtp = M[r, c].sum() if M.size else 0
n_hyp = sum(len(Hy) for Hy in hyp)
return {"FN": fn, "FP": fp, "IDSW": idsw, "MOTA": 1 - (fn + fp + idsw) / n_gt,
"IDF1": 2 * idtp / (n_gt + n_hyp), "tracks": len(hids)}
def evaluate(seeds, **params):
"""Run the tracker on each video (with its own simulated detector) and pool the CLEAR-MOT counts."""
tot = {"FN": 0, "FP": 0, "IDSW": 0, "GT": 0, "IDF1": []}
for seed in seeds:
frames, gt = make_crossing(np.random.default_rng(seed))
dets = noisy_detector(gt, np.random.default_rng(100 + seed))
gt_boxes = [[(k, b) for k, b, _ in g] for g in gt]
m = mot_metrics(gt_boxes, sort_tracker(dets, frames, **params))
for k in ["FN", "FP", "IDSW"]:
tot[k] += m[k]
tot["GT"] += sum(len(g) for g in gt); tot["IDF1"].append(m["IDF1"])
mota = 1 - (tot["FN"] + tot["FP"] + tot["IDSW"]) / tot["GT"]
return f"FN {tot['FN']:3d} FP {tot['FP']:2d} IDSW {tot['IDSW']:2d} MOTA {mota:.3f} IDF1 {np.mean(tot['IDF1']):.3f}"
DEV = (0, 1)
print("baseline (max_age 3, iou_thr 0.3, min_hits 2, no coasting):", evaluate(DEV))
print("sweep on the development videos:")
for coast in (0, 1, 2):
for max_age in (3, 8):
for iou_thr in (0.1, 0.3):
print(f" coast {coast} max_age {max_age} iou_thr {iou_thr}: "
+ evaluate(DEV, coast=coast, max_age=max_age, iou_thr=iou_thr))baseline (max_age 3, iou_thr 0.3, min_hits 2, no coasting): FN 125 FP 1 IDSW 10 MOTA 0.838 IDF1 0.819
sweep on the development videos:
coast 0 max_age 3 iou_thr 0.1: FN 122 FP 2 IDSW 7 MOTA 0.844 IDF1 0.859
coast 0 max_age 3 iou_thr 0.3: FN 125 FP 1 IDSW 10 MOTA 0.838 IDF1 0.819
coast 0 max_age 8 iou_thr 0.1: FN 120 FP 2 IDSW 8 MOTA 0.845 IDF1 0.906
coast 0 max_age 8 iou_thr 0.3: FN 124 FP 1 IDSW 12 MOTA 0.837 IDF1 0.839
coast 1 max_age 3 iou_thr 0.1: FN 53 FP 6 IDSW 5 MOTA 0.924 IDF1 0.900
coast 1 max_age 3 iou_thr 0.3: FN 56 FP 6 IDSW 8 MOTA 0.917 IDF1 0.859
coast 1 max_age 8 iou_thr 0.1: FN 51 FP 9 IDSW 6 MOTA 0.921 IDF1 0.951
coast 1 max_age 8 iou_thr 0.3: FN 55 FP 9 IDSW 10 MOTA 0.912 IDF1 0.880
coast 2 max_age 3 iou_thr 0.1: FN 36 FP 11 IDSW 5 MOTA 0.938 IDF1 0.908
coast 2 max_age 3 iou_thr 0.3: FN 39 FP 13 IDSW 8 MOTA 0.929 IDF1 0.866
coast 2 max_age 8 iou_thr 0.1: FN 34 FP 16 IDSW 6 MOTA 0.933 IDF1 0.959
coast 2 max_age 8 iou_thr 0.3: FN 38 FP 18 IDSW 10 MOTA 0.921 IDF1 0.886
Three things stand out. Coasting is worth more than any other knob: reporting predicted boxes for one or two frames cuts the false negatives from about 125 to between 34 and 56, at a cost of 6 to 18 false positives (predictions of objects that really were hidden), and MOTA goes from about 0.84 to between 0.91 and 0.94. A low IoU threshold (0.1) beats 0.3 in IDF1 in every pair of rows: right after a bounce, the constant-velocity prediction is several pixels off and the IoU with the new detection drops, and a strict threshold then kills the match and starts a new track. A longer memory (max_age 8) raises IDF1 by keeping a track alive through short occlusions. The best IDF1, 0.959 with MOTA 0.933, is at coast 2, max_age 8, iou_thr 0.1. The 6 identity switches that remain are the next target.
Step 2: failure analysis
Every identity switch is an event with a frame number, an object and two track ids. Listing them and looking at what happened around each is the tracking version of error analysis. The script below prints each switch with a crude cause (was another object overlapping it in the last 3 frames?) and then traces one of them in detail.
import numpy as np
def bounce(p, lo, hi):
"""Position p reflected into [lo, hi]: an object that reaches a border bounces back."""
span = hi - lo
q = (p - lo) % (2 * span)
return lo + (q if q <= span else 2 * span - q)
def make_crossing(rng, n_frames=60, h=90, w=160, n_objects=7):
"""Project variant of make_video: objects move at constant speed in all directions and bounce off
the borders, so paths cross and nearer objects (drawn later) hide farther ones.
Each object has its own grey level.
Returns frames (T, h, w) uint8 and gt per frame: list of (id, [x1, y1, x2, y2], visible fraction)."""
objs = []
for k in range(n_objects):
bw, bh = int(rng.integers(12, 20)), int(rng.integers(10, 16))
x, y = float(rng.uniform(0, w - bw)), float(rng.uniform(0, h - bh))
speed, angle = float(rng.uniform(1.0, 2.5)), float(rng.uniform(0, 2 * np.pi))
objs.append([x, y, bw, bh, speed * np.cos(angle), speed * np.sin(angle), int(rng.integers(120, 250))])
frames, gt = [], []
for t in range(n_frames):
f = rng.normal(60, 6, (h, w))
owner = np.full((h, w), -1)
boxes = []
for k, (x, y, bw, bh, vx, vy, g) in enumerate(objs):
x1, y1 = int(round(bounce(x + vx * t, 0, w - bw))), int(round(bounce(y + vy * t, 0, h - bh)))
bx = [x1, y1, x1 + bw, y1 + bh]
f[bx[1]:bx[3], bx[0]:bx[2]] = g; owner[bx[1]:bx[3], bx[0]:bx[2]] = k
boxes.append([k, bx])
gt.append([(k, b, float(np.mean(owner[b[1]:b[3], b[0]:b[2]] == k))) for k, b in boxes])
frames.append(f.clip(0, 255).astype(np.uint8))
return np.array(frames), gt
def noisy_detector(gt, rng, p_miss=0.1, jitter=1.0, false_rate=0.2, min_visible=0.5, h=90, w=160):
"""Simulated detector: misses objects less than min_visible visible, drops the rest with p_miss,
jitters corners, adds Poisson(false_rate) false boxes per frame. Returns (n, 4) arrays, no ids."""
out = []
for objects in gt:
d = [np.array(b, float) + rng.normal(0, jitter, 4) for _, b, vis in objects
if vis >= min_visible and rng.random() > p_miss]
for _ in range(rng.poisson(false_rate)):
x, y = rng.uniform(0, w - 15), rng.uniform(0, h - 12)
d.append(np.array([x, y, x + 15, y + 12]))
out.append(np.array(d).reshape(-1, 4))
return out
from scipy.optimize import linear_sum_assignment
def iou_matrix(a, b):
a, b = np.asarray(a, float).reshape(-1, 4)[:, None], np.asarray(b, float).reshape(-1, 4)[None]
iw = np.clip(np.minimum(a[..., 2], b[..., 2]) - np.maximum(a[..., 0], b[..., 0]), 0, None)
ih = np.clip(np.minimum(a[..., 3], b[..., 3]) - np.maximum(a[..., 1], b[..., 1]), 0, None)
inter = iw * ih
area = lambda r: (r[..., 2] - r[..., 0]) * (r[..., 3] - r[..., 1])
return inter / (area(a) + area(b) - inter)
class KalmanBox:
"""Constant-velocity Kalman filter on the box centre; width and height as slowly varying states.
State x = [cx, cy, w, h, vx, vy]."""
def __init__(self, box, q=1.0, r=1.0):
cx, cy, w, h = (box[0] + box[2]) / 2, (box[1] + box[3]) / 2, box[2] - box[0], box[3] - box[1]
self.x = np.array([cx, cy, w, h, 0.0, 0.0])
self.P = np.diag([r, r, r, r, 100.0, 100.0]) # velocity unknown at birth
self.F = np.eye(6); self.F[0, 4] = self.F[1, 5] = 1.0 # position += velocity (dt = 1 frame)
self.H = np.eye(4, 6) # we measure cx, cy, w, h
self.Q = np.diag([q, q, 0.1, 0.1, 0.1 * q, 0.1 * q]); self.R = r * np.eye(4)
def predict(self):
self.x = self.F @ self.x; self.P = self.F @ self.P @ self.F.T + self.Q
return self.box()
def update(self, box):
z = np.array([(box[0] + box[2]) / 2, (box[1] + box[3]) / 2, box[2] - box[0], box[3] - box[1]])
S = self.H @ self.P @ self.H.T + self.R
K = self.P @ self.H.T @ np.linalg.inv(S)
self.x = self.x + K @ (z - self.H @ self.x); self.P = (np.eye(6) - K @ self.H) @ self.P
def box(self):
cx, cy, w, h = self.x[:4]
return [cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2]
def appearance(frame, box):
"""A one-number appearance descriptor: the median grey level inside the box (2 px inset)."""
x1, y1, x2, y2 = [int(round(v)) for v in box]
patch = frame[max(y1 + 2, 0):max(y2 - 2, y1 + 3), max(x1 + 2, 0):max(x2 - 2, x1 + 3)]
return float(np.median(patch)) if patch.size else 0.0
def sort_tracker(dets, frames=None, iou_thr=0.3, max_age=3, min_hits=2, app_weight=0.0, app_gate=40.0, coast=0, cascade=False):
"""SORT with an optional appearance term (the DeepSORT idea): cost = 1 - IoU + app_weight * |grey
difference| / 100, and pairs whose grey levels differ by more than app_gate are forbidden.
min_hits: matches needed before a track is confirmed (it then stays confirmed).
cascade: match confirmed tracks first, tentative tracks only with the detections left over.
coast: also report confirmed tracks unmatched for up to frames, at their predicted box.
Returns per frame a list of (track_id, box)."""
tracks, next_id, out = [], 1, []
for t, D in enumerate(dets):
preds = [tr["kf"].predict() for tr in tracks]
app = [appearance(frames[t], d) for d in D] if app_weight else [0.0] * len(D)
matches, unmatched = [], set(range(len(D)))
if tracks and len(D):
iou = iou_matrix(preds, D)
diff = np.abs(np.array([tr["app"] for tr in tracks])[:, None] - np.array(app)[None, :])
cost = 1 - iou + app_weight * diff / 100
if app_weight:
cost[diff > app_gate] = 10.0
groups = ([[i for i, tr in enumerate(tracks) if tr["confirmed"]], [i for i, tr in enumerate(tracks) if not tr["confirmed"]]]
if cascade else [list(range(len(tracks)))])
for rows in groups:
cols = sorted(unmatched)
if not rows or not cols:
continue
for a, b in zip(*linear_sum_assignment(cost[np.ix_(rows, cols)])):
i, j = rows[a], cols[b]
if iou[i, j] >= iou_thr and cost[i, j] < 10:
matches.append((i, j)); unmatched.discard(j)
matched = {i for i, _ in matches}
for i, j in matches:
tr = tracks[i]; tr["kf"].update(D[j]); tr["hits"] += 1; tr["age"] = 0
tr["confirmed"] = tr["confirmed"] or tr["hits"] >= min_hits
tr["app"] = 0.8 * tr["app"] + 0.2 * app[j]
for i, tr in enumerate(tracks):
if i not in matched:
tr["age"] += 1
for j in sorted(unmatched):
tracks.append({"id": next_id, "kf": KalmanBox(D[j]), "hits": 1, "age": 0, "app": app[j], "confirmed": min_hits <= 1}); next_id += 1
tracks = [tr for tr in tracks if tr["age"] <= max_age]
out.append([(tr["id"], tr["kf"].box()) for tr in tracks if tr["confirmed"] and tr["age"] <= coast])
return out
def mot_metrics(gt, hyp, thr=0.5):
"""CLEAR-MOT counts (FN, FP, ID switches, MOTA) and IDF1, from scratch."""
fn = fp = idsw = n_gt = 0
last = {} # gt id -> track id it was last matched to
pair_frames = {} # (gt id, track id) -> frames matched
for G, Hy in zip(gt, hyp):
n_gt += len(G)
if G and Hy:
iou = iou_matrix([b for _, b in G], [b for _, b in Hy])
rows, cols = linear_sum_assignment(-iou)
pairs = [(G[i][0], Hy[j][0]) for i, j in zip(rows, cols) if iou[i, j] >= thr]
else:
pairs = []
for g, h in pairs:
if g in last and last[g] != h:
idsw += 1
last[g] = h
pair_frames[(g, h)] = pair_frames.get((g, h), 0) + 1
fn += len(G) - len(pairs); fp += len(Hy) - len(pairs)
gids = sorted({g for G in gt for g, _ in G}); hids = sorted({h for Hy in hyp for h, _ in Hy})
M = np.zeros((len(gids), len(hids)))
for (g, h), n in pair_frames.items():
M[gids.index(g), hids.index(h)] = n
r, c = linear_sum_assignment(-M) if M.size else ([], [])
idtp = M[r, c].sum() if M.size else 0
n_hyp = sum(len(Hy) for Hy in hyp)
return {"FN": fn, "FP": fp, "IDSW": idsw, "MOTA": 1 - (fn + fp + idsw) / n_gt,
"IDF1": 2 * idtp / (n_gt + n_hyp), "tracks": len(hids)}
def id_switches(gt, hyp, thr=0.5):
"""Every identity switch as (frame, true object, previous track id, new track id)."""
last, out = {}, []
for t, (G, Hy) in enumerate(zip(gt, hyp)):
if not (G and Hy):
continue
iou = iou_matrix([b for _, b, _ in G], [b for _, b in Hy])
for i, j in zip(*linear_sum_assignment(-iou)):
if iou[i, j] >= thr:
g, h = G[i][0], Hy[j][0]
if g in last and last[g] != h:
out.append((t, g, last[g], h))
last[g] = h
return out
params = dict(coast=2, max_age=8, iou_thr=0.1) # the best setting of the sweep
for seed in (0, 1):
frames, gt = make_crossing(np.random.default_rng(seed))
dets = noisy_detector(gt, np.random.default_rng(100 + seed))
hyp = sort_tracker(dets, frames, **params)
for t, g, h0, h1 in id_switches(gt, hyp):
own = {k: b for k, b, _ in gt[t]}[g]
others = sorted({k for tt in range(max(0, t - 3), t + 1) for k, b, _ in gt[tt]
if k != g and g in {kk for kk, _, _ in gt[tt]}
and iou_matrix([{kk: bb for kk, bb, _ in gt[tt]}[g]], [b])[0, 0] > 0})
tracks_on_it = [i for i, b in hyp[t] if iou_matrix([own], [b])[0, 0] > 0.3]
cause = f"crossing with object {others}" if others else "no other object near"
print(f"seed {seed} frame {t:2d}: object {g} moves from track {h0} to track {h1} | {cause} | tracks on it now: {tracks_on_it}")
frames, gt = make_crossing(np.random.default_rng(0))
dets = noisy_detector(gt, np.random.default_rng(100))
hyp = sort_tracker(dets, frames, **params)
print("seed 0, object 3, frames 11-15 (true box | detections touching it | tracks touching it):")
for t in range(11, 16):
b = {k: bb for k, bb, _ in gt[t]}[3]
d = [[int(round(v)) for v in x] for x in dets[t] if iou_matrix([b], [x])[0, 0] > 0]
h = [(i, [int(round(v)) for v in x]) for i, x in hyp[t] if iou_matrix([b], [x])[0, 0] > 0]
print(f" {t}: {b} | {d} | {h}")seed 0 frame 15: object 3 moves from track 4 to track 12 | no other object near | tracks on it now: [4, 12]
seed 0 frame 18: object 3 moves from track 12 to track 4 | no other object near | tracks on it now: [4, 12]
seed 0 frame 20: object 3 moves from track 4 to track 12 | no other object near | tracks on it now: [4, 12]
seed 0 frame 21: object 3 moves from track 12 to track 4 | no other object near | tracks on it now: [4, 12]
seed 0 frame 56: object 6 moves from track 7 to track 6 | crossing with object [5] | tracks on it now: [6]
seed 0 frame 58: object 5 moves from track 6 to track 21 | crossing with object [6] | tracks on it now: [21]
seed 0, object 3, frames 11-15 (true box | detections touching it | tracks touching it):
11: [51, 42, 69, 52] | [[52, 40, 70, 51]] | [(4, [51, 41, 69, 51])]
12: [51, 43, 69, 53] | [[52, 42, 71, 53], [56, 37, 71, 49], [56, 44, 71, 56]] | [(4, [52, 42, 70, 52])]
13: [52, 43, 70, 53] | [[52, 42, 71, 52]] | [(4, [53, 42, 71, 53])]
14: [53, 44, 71, 54] | [[52, 46, 72, 55]] | [(4, [53, 43, 72, 53]), (12, [54, 45, 71, 56])]
15: [54, 45, 72, 55] | [[55, 45, 72, 55]] | [(4, [54, 43, 73, 54]), (12, [55, 45, 72, 55])]
Two kinds of failure appear, and they need different fixes:
- Crossings (seed 0, frames 56 and 58): objects 5 and 6 overlap; object 6 ends up on the track that had been following object 5, and object 5 gets a new track (21). While two boxes overlap, the hidden one is often not detected at all, and when they separate, IoU and motion alone cannot tell which detection is which; this is the case appearance features are for.
- Duplicate tracks (seed 0, frames 15 to 21): object 3 is alone, yet it flips four times between tracks 4 and 12. The trace shows why. At frame 12 the detector reports two false alarms overlapping object 3, next to its real detection; with the low IoU threshold, one of them starts a new tentative track (12), which at frame 14 wins the real detection (the Hungarian algorithm found that pairing slightly cheaper) while track 4 coasts, and from then on the two take turns. Both tracks then live on the same object, and each frame the "wrong" one may get the match. The low threshold that fixed bounces made this possible.
Step 3: two fixes
Matching cascade (a simplified version of DeepSORT's, which also orders the confirmed tracks by how many frames since their last match): match the confirmed tracks first, and give tentative tracks only the detections that are left over. A fresh track born from a false alarm can then never steal the detection of an established track, so it dies after max_age frames without being confirmed.
Appearance (also the DeepSORT idea, in miniature): each object here has its own grey level, so the median grey level inside a box is a one-number appearance descriptor. The cost becomes with , pairs whose grey levels differ by more than 40 are forbidden, and a track's appearance is a running average of its matches. Real trackers use a re-identification CNN's embedding instead (person re-identification).
import numpy as np
def bounce(p, lo, hi):
"""Position p reflected into [lo, hi]: an object that reaches a border bounces back."""
span = hi - lo
q = (p - lo) % (2 * span)
return lo + (q if q <= span else 2 * span - q)
def make_crossing(rng, n_frames=60, h=90, w=160, n_objects=7):
"""Project variant of make_video: objects move at constant speed in all directions and bounce off
the borders, so paths cross and nearer objects (drawn later) hide farther ones.
Each object has its own grey level.
Returns frames (T, h, w) uint8 and gt per frame: list of (id, [x1, y1, x2, y2], visible fraction)."""
objs = []
for k in range(n_objects):
bw, bh = int(rng.integers(12, 20)), int(rng.integers(10, 16))
x, y = float(rng.uniform(0, w - bw)), float(rng.uniform(0, h - bh))
speed, angle = float(rng.uniform(1.0, 2.5)), float(rng.uniform(0, 2 * np.pi))
objs.append([x, y, bw, bh, speed * np.cos(angle), speed * np.sin(angle), int(rng.integers(120, 250))])
frames, gt = [], []
for t in range(n_frames):
f = rng.normal(60, 6, (h, w))
owner = np.full((h, w), -1)
boxes = []
for k, (x, y, bw, bh, vx, vy, g) in enumerate(objs):
x1, y1 = int(round(bounce(x + vx * t, 0, w - bw))), int(round(bounce(y + vy * t, 0, h - bh)))
bx = [x1, y1, x1 + bw, y1 + bh]
f[bx[1]:bx[3], bx[0]:bx[2]] = g; owner[bx[1]:bx[3], bx[0]:bx[2]] = k
boxes.append([k, bx])
gt.append([(k, b, float(np.mean(owner[b[1]:b[3], b[0]:b[2]] == k))) for k, b in boxes])
frames.append(f.clip(0, 255).astype(np.uint8))
return np.array(frames), gt
def noisy_detector(gt, rng, p_miss=0.1, jitter=1.0, false_rate=0.2, min_visible=0.5, h=90, w=160):
"""Simulated detector: misses objects less than min_visible visible, drops the rest with p_miss,
jitters corners, adds Poisson(false_rate) false boxes per frame. Returns (n, 4) arrays, no ids."""
out = []
for objects in gt:
d = [np.array(b, float) + rng.normal(0, jitter, 4) for _, b, vis in objects
if vis >= min_visible and rng.random() > p_miss]
for _ in range(rng.poisson(false_rate)):
x, y = rng.uniform(0, w - 15), rng.uniform(0, h - 12)
d.append(np.array([x, y, x + 15, y + 12]))
out.append(np.array(d).reshape(-1, 4))
return out
from scipy.optimize import linear_sum_assignment
def iou_matrix(a, b):
a, b = np.asarray(a, float).reshape(-1, 4)[:, None], np.asarray(b, float).reshape(-1, 4)[None]
iw = np.clip(np.minimum(a[..., 2], b[..., 2]) - np.maximum(a[..., 0], b[..., 0]), 0, None)
ih = np.clip(np.minimum(a[..., 3], b[..., 3]) - np.maximum(a[..., 1], b[..., 1]), 0, None)
inter = iw * ih
area = lambda r: (r[..., 2] - r[..., 0]) * (r[..., 3] - r[..., 1])
return inter / (area(a) + area(b) - inter)
class KalmanBox:
"""Constant-velocity Kalman filter on the box centre; width and height as slowly varying states.
State x = [cx, cy, w, h, vx, vy]."""
def __init__(self, box, q=1.0, r=1.0):
cx, cy, w, h = (box[0] + box[2]) / 2, (box[1] + box[3]) / 2, box[2] - box[0], box[3] - box[1]
self.x = np.array([cx, cy, w, h, 0.0, 0.0])
self.P = np.diag([r, r, r, r, 100.0, 100.0]) # velocity unknown at birth
self.F = np.eye(6); self.F[0, 4] = self.F[1, 5] = 1.0 # position += velocity (dt = 1 frame)
self.H = np.eye(4, 6) # we measure cx, cy, w, h
self.Q = np.diag([q, q, 0.1, 0.1, 0.1 * q, 0.1 * q]); self.R = r * np.eye(4)
def predict(self):
self.x = self.F @ self.x; self.P = self.F @ self.P @ self.F.T + self.Q
return self.box()
def update(self, box):
z = np.array([(box[0] + box[2]) / 2, (box[1] + box[3]) / 2, box[2] - box[0], box[3] - box[1]])
S = self.H @ self.P @ self.H.T + self.R
K = self.P @ self.H.T @ np.linalg.inv(S)
self.x = self.x + K @ (z - self.H @ self.x); self.P = (np.eye(6) - K @ self.H) @ self.P
def box(self):
cx, cy, w, h = self.x[:4]
return [cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2]
def appearance(frame, box):
"""A one-number appearance descriptor: the median grey level inside the box (2 px inset)."""
x1, y1, x2, y2 = [int(round(v)) for v in box]
patch = frame[max(y1 + 2, 0):max(y2 - 2, y1 + 3), max(x1 + 2, 0):max(x2 - 2, x1 + 3)]
return float(np.median(patch)) if patch.size else 0.0
def sort_tracker(dets, frames=None, iou_thr=0.3, max_age=3, min_hits=2, app_weight=0.0, app_gate=40.0, coast=0, cascade=False):
"""SORT with an optional appearance term (the DeepSORT idea): cost = 1 - IoU + app_weight * |grey
difference| / 100, and pairs whose grey levels differ by more than app_gate are forbidden.
min_hits: matches needed before a track is confirmed (it then stays confirmed).
cascade: match confirmed tracks first, tentative tracks only with the detections left over.
coast: also report confirmed tracks unmatched for up to frames, at their predicted box.
Returns per frame a list of (track_id, box)."""
tracks, next_id, out = [], 1, []
for t, D in enumerate(dets):
preds = [tr["kf"].predict() for tr in tracks]
app = [appearance(frames[t], d) for d in D] if app_weight else [0.0] * len(D)
matches, unmatched = [], set(range(len(D)))
if tracks and len(D):
iou = iou_matrix(preds, D)
diff = np.abs(np.array([tr["app"] for tr in tracks])[:, None] - np.array(app)[None, :])
cost = 1 - iou + app_weight * diff / 100
if app_weight:
cost[diff > app_gate] = 10.0
groups = ([[i for i, tr in enumerate(tracks) if tr["confirmed"]], [i for i, tr in enumerate(tracks) if not tr["confirmed"]]]
if cascade else [list(range(len(tracks)))])
for rows in groups:
cols = sorted(unmatched)
if not rows or not cols:
continue
for a, b in zip(*linear_sum_assignment(cost[np.ix_(rows, cols)])):
i, j = rows[a], cols[b]
if iou[i, j] >= iou_thr and cost[i, j] < 10:
matches.append((i, j)); unmatched.discard(j)
matched = {i for i, _ in matches}
for i, j in matches:
tr = tracks[i]; tr["kf"].update(D[j]); tr["hits"] += 1; tr["age"] = 0
tr["confirmed"] = tr["confirmed"] or tr["hits"] >= min_hits
tr["app"] = 0.8 * tr["app"] + 0.2 * app[j]
for i, tr in enumerate(tracks):
if i not in matched:
tr["age"] += 1
for j in sorted(unmatched):
tracks.append({"id": next_id, "kf": KalmanBox(D[j]), "hits": 1, "age": 0, "app": app[j], "confirmed": min_hits <= 1}); next_id += 1
tracks = [tr for tr in tracks if tr["age"] <= max_age]
out.append([(tr["id"], tr["kf"].box()) for tr in tracks if tr["confirmed"] and tr["age"] <= coast])
return out
def mot_metrics(gt, hyp, thr=0.5):
"""CLEAR-MOT counts (FN, FP, ID switches, MOTA) and IDF1, from scratch."""
fn = fp = idsw = n_gt = 0
last = {} # gt id -> track id it was last matched to
pair_frames = {} # (gt id, track id) -> frames matched
for G, Hy in zip(gt, hyp):
n_gt += len(G)
if G and Hy:
iou = iou_matrix([b for _, b in G], [b for _, b in Hy])
rows, cols = linear_sum_assignment(-iou)
pairs = [(G[i][0], Hy[j][0]) for i, j in zip(rows, cols) if iou[i, j] >= thr]
else:
pairs = []
for g, h in pairs:
if g in last and last[g] != h:
idsw += 1
last[g] = h
pair_frames[(g, h)] = pair_frames.get((g, h), 0) + 1
fn += len(G) - len(pairs); fp += len(Hy) - len(pairs)
gids = sorted({g for G in gt for g, _ in G}); hids = sorted({h for Hy in hyp for h, _ in Hy})
M = np.zeros((len(gids), len(hids)))
for (g, h), n in pair_frames.items():
M[gids.index(g), hids.index(h)] = n
r, c = linear_sum_assignment(-M) if M.size else ([], [])
idtp = M[r, c].sum() if M.size else 0
n_hyp = sum(len(Hy) for Hy in hyp)
return {"FN": fn, "FP": fp, "IDSW": idsw, "MOTA": 1 - (fn + fp + idsw) / n_gt,
"IDF1": 2 * idtp / (n_gt + n_hyp), "tracks": len(hids)}
def evaluate(seeds, **params):
"""Run the tracker on each video (with its own simulated detector) and pool the CLEAR-MOT counts."""
tot = {"FN": 0, "FP": 0, "IDSW": 0, "GT": 0, "IDF1": []}
for seed in seeds:
frames, gt = make_crossing(np.random.default_rng(seed))
dets = noisy_detector(gt, np.random.default_rng(100 + seed))
gt_boxes = [[(k, b) for k, b, _ in g] for g in gt]
m = mot_metrics(gt_boxes, sort_tracker(dets, frames, **params))
for k in ["FN", "FP", "IDSW"]:
tot[k] += m[k]
tot["GT"] += sum(len(g) for g in gt); tot["IDF1"].append(m["IDF1"])
mota = 1 - (tot["FN"] + tot["FP"] + tot["IDSW"]) / tot["GT"]
return f"FN {tot['FN']:3d} FP {tot['FP']:2d} IDSW {tot['IDSW']:2d} MOTA {mota:.3f} IDF1 {np.mean(tot['IDF1']):.3f}"
DEV, TEST = (0, 1), (2, 3)
tuned = dict(coast=2, max_age=8, iou_thr=0.1)
variants = [("baseline", {}),
("tuned", tuned),
("tuned + cascade", dict(tuned, cascade=True)),
("tuned + cascade + appearance", dict(tuned, cascade=True, app_weight=1.0))]
print("development videos (seeds 0, 1):")
for name, p in variants:
print(f" {name:29s} {evaluate(DEV, **p)}")
print("test videos (seeds 2, 3), chosen setting first, run once:")
for name, p in [variants[2], variants[0], variants[3]]:
print(f" {name:29s} {evaluate(TEST, **p)}")development videos (seeds 0, 1):
baseline FN 125 FP 1 IDSW 10 MOTA 0.838 IDF1 0.819
tuned FN 34 FP 16 IDSW 6 MOTA 0.933 IDF1 0.959
tuned + cascade FN 35 FP 5 IDSW 1 MOTA 0.951 IDF1 0.973
tuned + cascade + appearance FN 36 FP 3 IDSW 0 MOTA 0.954 IDF1 0.976
test videos (seeds 2, 3), chosen setting first, run once:
tuned + cascade FN 37 FP 3 IDSW 1 MOTA 0.951 IDF1 0.949
baseline FN 136 FP 0 IDSW 3 MOTA 0.835 IDF1 0.864
tuned + cascade + appearance FN 45 FP 7 IDSW 5 MOTA 0.932 IDF1 0.937
On the development videos the cascade removes almost every identity switch (6 to 1) and most false positives (16 to 5), raising IDF1 from 0.959 to 0.973 and MOTA from 0.933 to 0.951. The appearance term adds very little on top (IDF1 0.976, IDSW 0). A difference of 0.003 on two videos is noise, so by the rule "prefer the simpler model unless the gain is clear", the chosen tracker is tuned + cascade.
On the test videos, run once, the chosen tracker reaches MOTA 0.951 and IDF1 0.949 with 1 identity switch, against MOTA 0.835 and IDF1 0.864 for the baseline. All targets are met. The appearance variant was also run on the test videos, only to learn from it, not to choose: there it is worse (5 switches, IDF1 0.937). The likely reason is visible in the data: when an object is partly hidden, the median grey level inside its box is the occluder's, so the descriptor is wrong exactly at the crossings where it should help, and the gate then forbids the correct match. A descriptor must be computed on the visible part of the object, which is what learned re-ID features trained with occlusions do far better than one grey level.
Your turn
- In step 1, add
min_hits1 and 3 to the sweep (with coast 2,max_age8,iou_thr0.1). Predict the effect on FP, FN and IDSW first.
Hint and answer
min_hits 1 reports every new track from its first detection: fewer false negatives at track starts, but every false alarm becomes a reported one-frame track, so FP rises. min_hits 3 does the opposite and delays every track by one more frame. On a detector with 0.2 false alarms per frame, 2 is usually the sweet spot; measure it on the development videos only.
- Make the detector worse:
p_miss=0.3. Which parameters would you retune first, and why?
Answer
With more misses, tracks must survive longer gaps: increase coast (report predictions for more frames) and keep max_age well above the longest typical gap. The Kalman prediction drifts during long gaps, especially around bounces, so the IoU threshold may need to stay low; the cascade protects against the duplicate tracks that a low threshold invites.
- Improve the appearance descriptor so that it helps at crossings. Two ideas: compute it only on the pixels of the box that no other track's predicted box covers, and update the track's appearance only when the detection is not overlapping another one.
Hint
Build a mask of the box minus the union of the other predicted boxes and take the median grey level there; skip the running-average update when the detection's IoU with any other detection exceeds 0.1. Evaluate on the development videos; if it beats the cascade clearly, you may run it once on the test videos.
- Bounces break the constant-velocity model. Propose a change to the Kalman filter so that it recovers faster after a sudden change of direction.
Answer
Increase the process noise on the velocity components (), so the filter trusts new measurements more and re-estimates the velocity in one or two frames, at the cost of noisier estimates in straight motion. More principled: an interacting multiple model (IMM) filter that runs a constant-velocity and a "manoeuvre" model in parallel and mixes them by their likelihoods.
Write-up template
| Section | Content |
|---|---|
| Task | online multi-object tracking, 7 objects, crossings, occlusions, bounces |
| Data and detector | make_crossing, 60 frames x 4 videos; simulated detector (occlusion below 50 % visible, 10 % misses, 1 px jitter, 0.2 false alarms per frame); development seeds 0, 1; test seeds 2, 3 |
| Metrics | MOTA pooled over videos, IDF1 averaged over videos, IDSW count; IoU 0.5 for matching |
| Baseline | SORT, max_age 3, iou_thr 0.3: MOTA 0.838, IDF1 0.819 (development) |
| Tuning | coast 2, max_age 8, iou_thr 0.1: MOTA 0.933, IDF1 0.959 (development) |
| Failure analysis | crossings with occlusion; duplicate tracks started by false alarms next to real objects |
| Fix | matching cascade (confirmed tracks first) |
| Final (test, once) | MOTA 0.951, IDF1 0.949, 1 IDSW |
| Negative result | a one-number appearance cue did not help (it is corrupted by occluders) |
| Limits | synthetic rectangles, simulated detector; real people and cars change appearance, scale and speed |
| Privacy | tracks of people are personal data: minimise, aggregate, delete (privacy, consent and licensing) |
Test yourself
Lowering the IoU threshold from 0.3 to 0.1 improved IDF1 in every row of the sweep. Why?
- It removed false alarms
- After a bounce the constant-velocity prediction is several pixels off, so a strict threshold rejects the right detection and starts a new track
- It made the Kalman filter faster
- It increases min_hits
What does the matching cascade change?
- It matches tentative tracks first
- Confirmed tracks are matched first, and tentative tracks only get the detections that are left, so a track born from a false alarm cannot steal an established track's detection
- It removes the Hungarian algorithm
- It adds appearance features
The appearance variant had the best development IDF1 (0.976 against 0.973) but was not chosen. Which reasoning is sound?
- The test set should decide between them
- A 0.003 difference on two videos is within noise; with a rule fixed in advance (prefer the simpler model unless the gain is clear) the cascade alone is chosen, and the test videos are used once to report it
- Appearance features are always useless
- IDF1 cannot compare trackers