Sub topic 11
ByteTrack: recovering low-confidence detections
This chapter assumes you know the SORT pipeline from earlier chapters: a Kalman filter predicts each track's box, IoU builds a cost matrix, and the Hungarian algorithm assigns detections to tracks. You should also be comfortable with NumPy and with detector confidence scores. Here you will learn what ByteTrack changes in that pipeline, why the change works, and where it breaks.
The problem: thresholding throws away evidence
Most trackers discard detections whose confidence score is below a cutoff such as 0.5 or 0.6. The cutoff removes false positives, which are boxes on background clutter. It also removes true objects that are hard to see.
An object that is partly occluded gets a lower detector score. Motion blur, small size, and unusual pose have the same effect. So the frames where a person walks behind a pole are the frames where the detection falls below the threshold. The track then receives no match and starts accumulating misses. If the occlusion lasts long enough, the track is deleted. When the person reappears, the tracker creates a new track with a new ID, which is an ID switch.
ByteTrack (Zhang et al., 2022) is based on one observation: a low-score box that overlaps a track's predicted position is much more likely to be a real object than a low-score box in empty space. The tracker can use that motion evidence to tell the two apart, so the low-score boxes do not have to be discarded.
The two-stage association
ByteTrack keeps the SORT machinery (constant-velocity Kalman filter, IoU cost, Hungarian matching) and changes only how detections are fed into it. Every frame, each detection falls into one of three groups, based on two score thresholds.
| Group | Score range | Role |
|---|---|---|
| High | score ≥ `high` (for example 0.6) | Matched first. May start new tracks. |
| Low | `low` ≤ score < `high` (for example 0.1 to 0.6) | Matched only to tracks the first stage left unmatched. |
| Discarded | score < `low` | Ignored as background. |
The steps for one frame:
- Predict every track's box with the Kalman filter.
- First association: match all tracks to the high-score detections using IoU and the Hungarian algorithm.
- Second association: match the tracks left unmatched in step 2 to the low-score detections. Use a stricter IoU threshold than in step 2.
- Tracks still unmatched are marked lost. They are kept for a number of frames (30 in the reference implementation) so they can be recovered later.
- High-score detections that matched nothing start new tracks. Low-score detections never start tracks.
Two design choices matter here. Stage 1 runs first so that confident detections get priority and a noisy low-score box cannot steal a track from a clean one. And only tracks, not detections, carry over from stage 1 to stage 2. A high-score detection that failed to match is never offered to stage 2.
A runnable sketch
The code below implements the association logic only. The Kalman prediction and the track objects are the same as in the SORT chapter, so this function works on predicted boxes. It repeats iou_matrix and match so the example runs on its own.
import numpy as np
from scipy.optimize import linear_sum_assignment
def iou_matrix(boxes_a, boxes_b):
a = np.asarray(boxes_a, dtype=float).reshape(-1, 1, 4)
b = np.asarray(boxes_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])
inter = 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])
return inter / np.maximum(area_a + area_b - inter, 1e-9)
def match(track_boxes, det_boxes, iou_thresh):
if len(track_boxes) == 0 or len(det_boxes) == 0:
return [], list(range(len(track_boxes))), list(range(len(det_boxes)))
iou = iou_matrix(track_boxes, det_boxes)
rows, cols = linear_sum_assignment(1.0 - iou)
matches = [(int(r), int(c)) for r, c in zip(rows, cols) if iou[r, c] >= iou_thresh]
mt = {r for r, _ in matches}
md = {c for _, c in matches}
ut = [i for i in range(len(track_boxes)) if i not in mt]
ud = [j for j in range(len(det_boxes)) if j not in md]
return matches, ut, ud
def byte_associate(track_boxes, det_boxes, scores,
high=0.6, low=0.1, iou_high=0.3, iou_low=0.5):
"""Return (matches, lost_track_indices, new_track_detection_indices).
All indices refer to the original track and detection lists."""
det_boxes = np.asarray(det_boxes, dtype=float).reshape(-1, 4)
scores = np.asarray(scores, dtype=float)
high_idx = np.flatnonzero(scores >= high)
low_idx = np.flatnonzero((scores >= low) & (scores < high))
# Stage 1: all tracks against high-score detections.
m1, ut1, ud1 = match(track_boxes, det_boxes[high_idx], iou_high)
matches = [(t, int(high_idx[d])) for t, d in m1]
# Stage 2: leftover tracks against low-score detections, stricter IoU.
sub_tracks = [track_boxes[t] for t in ut1]
m2, ut2, _ = match(sub_tracks, det_boxes[low_idx], iou_low)
matches += [(ut1[t], int(low_idx[d])) for t, d in m2]
lost = [ut1[t] for t in ut2]
new = [int(high_idx[d]) for d in ud1] # only high-score boxes start tracks
return matches, lost, new
tracks = [[10, 10, 50, 50], [100, 100, 150, 160]]
dets = [[12, 11, 52, 52], # clear detection of track 0
[104, 108, 150, 150], # occluded object: track 1, low score
[300, 300, 340, 340], # background clutter, low score
[200, 200, 240, 240]] # new object, high score
scores = [0.9, 0.35, 0.2, 0.8]
print(byte_associate(tracks, dets, scores))The output is ([(0, 0), (1, 1)], [], [3]). Track 1 survives because its low-score detection overlaps its predicted box with an IoU of about 0.64. The clutter box at index 2 has no track near it, so it is dropped. The new object at index 3 has a high score, so it starts a track.
With a single threshold at 0.6, track 1 would have gone unmatched and begun counting misses.
Threshold choices and what they control
ByteTrack has more tunable parameters than SORT, and each one has a specific effect.
high: the score above which a detection is trusted on its own. It also decides which detections can start tracks. Raising it means fewer false tracks and slower track creation.low: the floor. If it is too low, clutter boxes enter stage 2. They can only match tracks that are already unmatched, so the damage is limited, but each bad match corrupts that track's box.iou_low: the stage 2 IoU threshold. Low-score boxes are often poorly localized, so you might expect a looser threshold. The reference implementation uses a stricter one (0.5, against 0.2 in stage 1), because the only protection against clutter in stage 2 is spatial agreement with a track.- Lost-track buffer: how many frames a lost track survives. Longer buffers recover from longer occlusions, but they raise the chance that a lost track is wrongly matched to a different object.
How ByteTrack differs from DeepSORT
DeepSORT recovers from occlusion by comparing appearance embeddings, so a reappearing person can be matched to a track by how they look. ByteTrack uses no appearance model. It recovers through the detector's own weak signal plus motion.
| Aspect | DeepSORT | ByteTrack |
|---|---|---|
| Recovery signal | Appearance embedding plus motion | Low-score detection plus motion |
| Extra network | Re-ID model per box | None |
| Cost per frame | Grows with number of boxes | Close to SORT |
| Long occlusion (object fully hidden) | Can re-identify after reappearance | Cannot, because no detection exists to match |
| Look-alike objects | Embeddings can help | IoU alone can confuse them |
ByteTrack helps when the object is still partly visible and the detector sees it weakly. It does nothing when the object is fully hidden, because there is no box at all. The paper reports about 80 MOTA, 77 IDF1, and 63 HOTA on the MOT17 test set at roughly 30 FPS, with a YOLOX detector. Treat these numbers as dependent on that detector and on the benchmark's pedestrian-heavy scenes.
Failure modes and edge cases
- Crowded scenes with overlapping boxes. A low-score box from person B can overlap track A's predicted box enough to pass the stage 2 threshold. If A is also unmatched, A takes B's box. Stage 1 priority reduces this, but it does not remove it.
- Detector score calibration. Scores from different detectors, or from the same detector after retraining, are not comparable. A
highvalue of 0.6 may be too strict for one model and too loose for another. Re-tune on validation video whenever the detector changes. - Camera motion. Both stages assume the Kalman prediction is close to the true position. A moving camera breaks that, and no score trick fixes it. Camera-motion compensation is a separate step.
- Fast objects. If an object moves far between frames, its box may not overlap the predicted box at all, in either stage.
- Reappearance after the buffer expires. After the lost buffer runs out, the track is deleted, and the object gets a new ID when it returns.
Exercise
A tracker uses high = 0.6, low = 0.1, stage 1 IoU threshold 0.3, and stage 2 IoU threshold 0.5. Track T has a predicted box that overlaps a detection scored 0.45 with IoU 0.4, and no detection scored 0.6 or above overlaps T at all. Is T matched, lost, or deleted this frame? What changes if the stage 2 threshold is 0.3?
Show answer
With the 0.5 stage 2 threshold, T is marked lost (not deleted). The 0.45 detection is in the low group, so it is offered only to stage 2, and IoU 0.4 is below 0.5, so no match is made. T keeps its ID and stays in the lost buffer, where it can be recovered in a later frame. If the stage 2 threshold is 0.3, the IoU of 0.4 passes, so T is matched to the low-score detection, its misses reset, and it stays active.