Keeping Track IDs Through Full Occlusion: YOLO + a GPU Kalman Tracker
I wanted to know one thing: when an object walks behind a bus, a pillar or another object, and it comes out again a few seconds later, does it keep its track id? Most trackers say yes in the paper and no in the video. The detector cannot see a hidden object, so the tracker must remember it, predict where it goes, and recognize it when it comes back. If the tracker forgets too early, the same person gets a second id, and every count, dwell time and trajectory after that point is wrong.
So I built my own tracker. Ultralytics YOLO26 is only the detector. The tracking part is my code: a Kalman filter, a matching cascade and an appearance check, all in PyTorch on the GPU, batched over tracks and over video streams. Then I asked a second question: if the whole loop stays on the GPU, how many frames per second can two GPUs track? The source is on GitHub: mraad/yolo-kalman.
The problem with full occlusion
A full occlusion is a time when the object is completely hidden, so the detector gives no box for it. The tracker sees nothing for 10, 60 or 150 frames. Three things must work together to keep the id:
- Memory. The track must stay alive while it is hidden. I keep lost tracks for 8 seconds (
lost_buffer_s). - Motion. The track must coast to a position near the place where the object comes out. This is the job of the Kalman filter.
- Appearance. When motion is not enough (the person slowed down behind the wall), the tracker must recognize the object by how it looks.
There is a fourth problem that I did not expect. Before an object disappears, it is partially hidden. The detector gives a box that gets thinner and thinner. If the tracker trusts these boxes, the Kalman filter learns a wrong size and a wrong speed, and the prediction goes to the wrong place. I had to fix this before full occlusions worked with a real detector.
How the tracker works
The state of each track is a constant-velocity Kalman filter on the box center, width and height (cx, cy, w, h). The measurement noise gets bigger when the detection score is low (NSA, from StrongSORT). When a track is lost for many frames, the prediction is exact over the gap, not one small step at a time.
Each frame goes through a matching cascade. Each stage matches some tracks to some detections, and the next stage gets what is left:
| Stage | Tracks | Detections | Cost | Limit |
|---|---|---|---|---|
| S1 | confirmed (tracked and lost) | high score | IoU fused with appearance + OC-SORT direction term, Mahalanobis gate | 0.8 |
| S2 | seen in the last frame, not matched | low score | IoU (ByteTrack second stage) | 0.5 |
| S3 | not matched, lost up to 30 frames | high score, left over | IoU to the last real observation (OC-SORT OCR) | 0.7 |
| S4 | lost | high score, left over | appearance distance, loose Mahalanobis gate | 0.25 |
| S5 | new, unconfirmed | high score, left over | IoU | 0.7 |
When a lost track gets a match again, OC-SORT ORU replays the gap: it updates the filter along a straight line from the last observation to the new one, so the speed is correct again. A box much smaller than the track's slow average size is a low-quality observation. The track coasts through it, and the filter does not learn the wrong size. And there is one more step: if a new track looks like a track that was lost, the new track takes the old id (young-track id recovery).
The appearance features come from a torchvision ResNet-18 (ImageNet weights) on 128×64 crops. The crops come straight from the decoded frames on the GPU. I chose a generic network on purpose: the person re-ID networks only know people, and I also track cars, buses and birds. It is not a trained re-ID model, and I come back to that below.
One more thing came from looking at the output frame by frame. The detector sometimes gives the same object two times: a second box, or a second class label such as car and truck. I counted 2,794 such pairs (IoU above 0.8) in 10,560 frames of the real clips. Each copy started its own track, so one object had two ids for some frames. The post-processing now drops the lower-score box of such a pair. Frames where two tracks sit on the same object went from 244 to 25, and the speed did not change.
A Hungarian solver on the GPU
Each cascade stage is an assignment problem: find the pairs of tracks and detections with the smallest total cost. The usual tool is lap.lapjv on the CPU. That means the cost matrices go from the GPU to the CPU and the result comes back, with two host waits per frame. With 32 streams, the CPU cascade was the bottleneck.
So I wrote a batched exact Hungarian solver as a CUDA kernel. It is the shortest augmenting path form, with float64 dual potentials. There is no epsilon and no iteration limit, so the answer is an optimal assignment, the same as lapjv. One thread block solves one stream, so all streams are solved in one launch. The kernel has no data-dependent host loop, so it goes into a CUDA graph with the rest of the step. It is a torch custom op, and it uses the same cost limit rule as lapjv(extend_cost=True, cost_limit=L):
import torch
from yolo_kalman.assign import lap_batch
# 2 streams, 3 tracks (rows) x 4 detections (columns); cost = 1 - IoU
cost = torch.tensor([[[0.10, 0.90, 0.95, 0.70],
[0.85, 0.20, 0.90, 0.95],
[0.90, 0.90, 0.90, 0.90]],
[[0.30, 0.25, 9e4, 9e4],
[0.20, 0.40, 9e4, 9e4],
[9e4, 9e4, 9e4, 9e4]]], device="cuda")
rows = torch.tensor([[True, True, True], [True, True, False]], device="cuda")
cols = torch.ones(2, 4, dtype=torch.bool, device="cuda")
print(lap_batch(cost, rows, cols, 0.8).tolist()) # [[0, 1, -1], [1, 0, -1]]
The tests compare the total cost with scipy linear_sum_assignment and with lapjv on random problems, ties, empty and fully gated matrices, NaN and infinity. On real video, I recorded the tracker inputs for 300 frames of 12 clips and solved every problem with both solvers. The total cost was equal in 8,536 of 8,536 problems.
| streams × rows × cols | GPU Hungarian (one launch) | lapjv (per stream, CPU) |
|---|---|---|
| 8 × 20 × 20 | 0.038 ms | 0.148 ms |
| 16 × 60 × 60 | 0.155 ms | 0.918 ms |
| 32 × 150 × 150 | 0.879 ms | 9.780 ms |
The GPU pipeline
Nothing leaves the GPU. NVDEC decodes the video into device memory. The frames are letterboxed into one fp16 batch, and a TensorRT FP16 engine of YOLO26m (NMS-free head, dynamic batch up to 64) gives the boxes. The crops go through ResNet-18 in one call for all streams. Then the tracker runs one step for all streams at the same time, in three CUDA graphs: predict and costs, the matching cascade (six solver launches), and the Kalman update. The host waits for the GPU once per chunk of 8 frames.
NVDEC -> GPU letterbox -> TensorRT YOLO26m -> RoI crops -> ResNet-18
-> CUDA graph pre -> graph match (GPU Hungarian) -> graph post
To try it, install the environment, export the engine and run the tests from the repo folder:
~/.local/bin/uv sync
./run.sh scripts/export_trt.py yolo26m.pt --nms-free
./run.sh scripts/make_synthetic.py
REQUIRE_E2E=1 ./run.sh -m pytest -rs -q
./run.sh scripts/track.py clips/*.webm --out results/real --overlay
Results with ground truth
Real clips have no ground truth for occlusions, so I made synthetic clips. People walk behind a grey bar that hides them completely for a known number of frames: 10, 30, 60 and 120. A fourth clip has two crossings. Every frame has a ground truth box.
The full tracker kept the same id through 13 of 13 full occlusions, with gaps up to 157 frames, and 0 id switches on every clip. The ablations show which part does the work:
| Variant | gap 10 | gap 30 | gap 60 | gap 120 |
|---|---|---|---|---|
| Full (BYTE + OC-SORT + re-ID) | 3/3 | 3/3 | 3/3 | 3/3 |
| No re-ID | 3/3 | 2/3 | 0/3 | 0/3 |
| ByteTrack-like (1 s buffer, no OC-SORT, no re-ID) | 2/3 | 0/3 | 0/3 | 0/3 |
The table shows how many people have the same id 1 second after they come out. Motion alone carries the id through 10 to 30 frames. After that, the people do not come out where a constant-velocity model expects them, and only the appearance stage brings the id back. HOTA for the full tracker is 0.85 to 0.88 on all clips.
Real clips
I also ran 12 Wikimedia Commons clips with open licences as 12 parallel streams on one GPU: streets, trams, a train station and birds in a garden. Without ground truth, I can only count. These counts are from the run before the duplicate fix. With re-ID, the tracker gave 603 ids instead of 833, and 510 objects came back under their old id after a gap of at least 1 second, against 237 without re-ID.
Throughput
The benchmark runs the full pipeline (decode, detect, re-ID, track, no overlay) on two NVIDIA RTX PRO 6000 Blackwell GPUs. Each setting ran three times, and the table shows the median run.
| Streams | 1 | 4 | 8 | 16 | 32 |
|---|---|---|---|---|---|
| FPS, GPU Hungarian | 1,236 | 3,687 | 4,582 | 5,272 | 5,664 |
| FPS, lapjv on the CPU | 868 | 2,437 | 2,837 | 3,200 | 3,798 |
| Speed-up | 1.42× | 1.51× | 1.62× | 1.65× | 1.49× |
The tracker alone takes 0.40 ms per step for 8 streams with the GPU cascade, against 2.09 ms with lapjv. The TensorRT engine alone does about 3,300 images per second per GPU, so 5,664 fps is 86% of what the detector can do on two GPUs, with re-ID and tracking on the same GPUs. I did not get there in one step: the first eager version did 158 fps for one stream, and the README lists the eight changes in between.
What this does not show
- The occlusion results come from synthetic clips. On real clips, I have counts, not accuracy. Some of the extra re-acquisitions can be wrong merges, and I cannot rule that out without ground truth.
- A lost track can match the wrong object for a few frames. In the animation above, the track of car 11 sits on a window of the van for a few frames while the van hides the car.
- ResNet-18 ImageNet features are not a trained re-ID model. Two cars with the same color can get confused. The Mahalanobis gate and the class gate limit this, but they do not remove it.
- The detector is Ultralytics YOLO26, which is AGPL-3.0. My tracker code is Apache-2.0, and the detector sits behind a small
Detectorinterface, so a permissive detector (YOLOX, RT-DETR, D-FINE) can replace it. I did not build that yet. - The pipeline output is not bit-identical from run to run, because of detector and embedding numerics. To compare the two solvers, I replay recorded inputs.
Next, I want to try a trained re-ID network for vehicles and people, a permissive detector, and a real dataset with occlusion ground truth. The code, the STE100 manual and all benchmark files are in mraad/yolo-kalman. More to come.
Comments