Sub topic 11
ByteTrack: Recovering Low-Confidence Detections
This chapter assumes basic Python and NumPy, object-detection bounding boxes, and the Hungarian algorithm. It focuses on how ByteTrack improves tracking when an object is partly hidden or blurred.
Why low-confidence detections matter
An object detector gives each bounding box a confidence score. The score estimates how likely the box is to contain an object of the requested class.
A common tracker keeps only detections above a high threshold, such as 0.6. This removes many false positives, but it also removes real objects during occlusion. A person partly hidden behind another person may receive a score of 0.25 even though the detector's box is useful.
ByteTrack uses these detections in a controlled way. It does not treat every low-score box as a new object.
The two-stage association process
ByteTrack divides detections into two groups:
- High-confidence detections: scores at or above a high threshold.
- Low-confidence detections: scores between a low threshold and the high threshold.
It first matches existing tracks with high-confidence detections. It then takes tracks that remain unmatched and tries to match them with low-confidence detections. A low-confidence detection can therefore continue an existing track without creating a false track on its own.
The low threshold prevents extremely weak boxes from entering the second stage. The IoU gate still rejects a low-confidence box that does not overlap the predicted track location.
| Detection group | Typical use |
|---|---|
| High confidence | Main association and new-track candidates |
| Low confidence | Recovery of existing tracks |
| Below low threshold | Usually ignored |
A minimal two-stage implementation
The following example uses IoU and the Hungarian algorithm. It leaves track creation and deletion to the surrounding tracker.
import numpy as np
from scipy.optimize import linear_sum_assignment
def iou_matrix(a, b):
a = np.asarray(a, dtype=float).reshape(-1, 1, 4)
b = np.asarray(b, dtype=float).reshape(1, -1, 4)
x1 = np.maximum(a[..., 0], b[..., 0])
y1 = np.maximum(a[..., 1], b[..., 1])
x2 = np.minimum(a[..., 2], b[..., 2])
y2 = np.minimum(a[..., 3], b[..., 3])
intersection = np.clip(x2 - x1, 0, None) * np.clip(y2 - y1, 0, None)
area_a = (a[..., 2] - a[..., 0]) * (a[..., 3] - a[..., 1])
area_b = (b[..., 2] - b[..., 0]) * (b[..., 3] - b[..., 1])
union = area_a + area_b - intersection
return intersection / np.maximum(union, 1e-9)
def associate(track_boxes, det_boxes, track_ids, det_ids, threshold=0.3):
if not track_ids or not det_ids:
return [], list(track_ids), list(det_ids)
scores = iou_matrix(
[track_boxes[i] for i in track_ids],
[det_boxes[j] for j in det_ids],
)
cost = np.where(scores >= threshold, 1.0 - scores, 1e6)
rows, cols = linear_sum_assignment(cost)
matches = []
used_tracks, used_dets = set(), set()
for row, col in zip(rows, cols):
if cost[row, col] < 1e6:
matches.append((track_ids[row], det_ids[col]))
used_tracks.add(track_ids[row])
used_dets.add(det_ids[col])
unmatched_tracks = [i for i in track_ids if i not in used_tracks]
unmatched_dets = [j for j in det_ids if j not in used_dets]
return matches, unmatched_tracks, unmatched_dets
tracks = [[10, 10, 50, 50], [100, 100, 150, 160]]
detections = [[12, 11, 52, 52], [102, 103, 152, 162], [300, 300, 340, 340]]
confidence = [0.85, 0.28, 0.95]
high = [i for i, s in enumerate(confidence) if s >= 0.6]
low = [i for i, s in enumerate(confidence) if 0.1 <= s < 0.6]
first, unmatched_tracks, _ = associate(
tracks, detections, list(range(len(tracks))), high
)
second, unmatched_tracks, unmatched_low = associate(
tracks, detections, unmatched_tracks, low
)
print("high-confidence matches:", first)
print("recovered matches:", second)
print("still unmatched tracks:", unmatched_tracks)Common errors and trade-offs
A low-confidence box should not automatically start a track. That choice often creates false identities from shadows, reflections, or detector noise. New tracks usually require high confidence, repeated evidence, or both.
The thresholds are scene-dependent. A high threshold that is too strict loses objects during occlusion. A low threshold that is too permissive increases accidental matches and computation. Also, ByteTrack mainly addresses detection confidence. It does not solve long occlusions or identity swaps when two objects have similar motion and overlap for many frames.
Exercise
A track has no match among detections with scores above 0.6. A box with score 0.25 overlaps its predicted location with IoU 0.7. What should ByteTrack do?
Show answer
Try the box in the second association stage and update the existing track if the match passes the IoU gate.