Detection-to-track association
A tracker reads detections each frame and assigns each one to a track. Build the per-frame (N_tracks × M_detections) cost matrix — typically 1 − IoU (intersection-over-union overlap) between predicted and detected bounding boxes, optionally filtered by distance between box centers (centroid gating) or visual similarity (appearance distance) — stack frames into a batch, and jonker_dense_batch solves the whole batch in one CUDA launch.
The _unpacked variant returns (matches, unmatched_tracks, unmatched_dets, n_matched) directly — removing the per-frame Python loop that most codebases use to separate matched from unmatched indices after getting the raw assignment.
import torch
import torchmatch
# costs: (B, N_tracks, M_dets) of `1 - IoU`,
# with +inf where centroid distance > gate.
costs = build_iou_cost_batch(
tracks, detections, gate=0.3,
) # (B, N, M)
matches, ur, uc, n_matched = torchmatch.assignment.solve(
costs, unpack=True,
)
# matches[b, :n_matched[b]] = (track_idx, det_idx) pairs