Sub topic 15
End-to-end and transformer-based trackers
Prerequisites and scope
This chapter assumes you have read the earlier chapters on tracking-by-detection, the Kalman filter, Hungarian association, SORT, DeepSORT, ByteTrack and the MOTA, IDF1 and HOTA metrics. You should also know what a CNN backbone and an embedding are. Familiarity with transformer attention helps, but each idea is explained as it appears.
The goal is to understand what changes when detection and tracking are trained as one model. You should also be able to decide when that change is worth its cost.
What the tracking-by-detection pipeline leaves on the table
A tracking-by-detection system has separate stages. A detector produces boxes. A motion model predicts positions. An association step matches boxes to tracks. A lifecycle manager creates and deletes tracks.
This design is modular. You can swap the detector without touching the tracker. It also has three weaknesses:
- The detector never learns what the tracker needs. It is trained to find objects in a single frame. It is not trained to produce boxes that are easy to link across frames.
- The hand-tuned parts do not learn. IoU thresholds, the maximum number of missed frames, the Kalman noise matrices and the confidence cut-offs are set by hand. They are tuned per dataset.
- Errors cannot flow back. If association fails because a box was slightly too large, the detector never receives that signal.
End-to-end trackers try to remove these gaps by training one network to detect and associate. The cost is training complexity and less modularity.
Three families of approaches
Methods beyond classic tracking-by-detection fall into three groups. The boundaries blur, but the grouping helps you reason about trade-offs.
| Family | Idea | Examples | What stays hand-designed |
|---|---|---|---|
| Joint detection and embedding | One network outputs boxes and appearance embeddings in one pass | JDE, FairMOT | Association by embedding distance and Hungarian matching |
| Tracking by regression | The detector's box regressor moves last frame's boxes into the current frame | Tracktor, CenterTrack | Track creation and deletion rules |
| Transformer query-based | Persistent track queries carry identity from frame to frame | TrackFormer, MOTR, MeMOTR | Little. Some methods still apply score thresholds and a track-removal rule |
Joint detection and embedding
Joint detection and embedding (JDE) models add an embedding head next to the detection head. A single forward pass gives you boxes and a vector per box. This saves the compute of running a separate re-identification (ReID) network on every crop, which DeepSORT-style pipelines need.
Association is still the usual one. You build a cost matrix from embedding distance, often mixed with IoU or motion gating, and solve it with the Hungarian algorithm. FairMOT is a well-known example. It uses a high-resolution, anchor-free, center-based detector, because anchor-based detectors can give several anchors to one object, which makes the embedding ambiguous.
The main trade-off is that detection and ReID compete for the shared backbone's capacity. Detection wants features shared by all objects of a class. ReID wants features that separate individuals.
Tracking by regression
Tracktor uses an observation about detectors. A detector's second-stage box regressor already refines a rough box into a tight one. If you give it last frame's box as the starting proposal, it will often snap onto the same object in the new frame. The track's identity is carried by the proposal itself, so no association step is needed for those tracks.
CenterTrack follows a similar idea. It feeds the previous frame and previous object centers into the network. The network predicts each object's offset back to its position in the previous frame, and linking is a simple nearest-center match.
These methods work well when motion between frames is small. They struggle when objects move far or when the camera moves, because the old box no longer overlaps the object.
Transformer-based trackers
Transformer trackers extend the DETR family of detectors. DETR uses a fixed set of learned object queries. Each query attends to the image features through cross-attention and decodes into one box and class. Bipartite matching during training pairs queries with ground-truth objects.
TrackFormer and MOTR add track queries. The idea works like this:
- In frame t, detect queries find new objects. Each detection that is kept becomes a track query.
- The decoder output of that query is carried into frame t+1 as the input of a track query.
- The track query attends to the new frame's features and decodes to the same object's new box. Identity is kept because the query is the same.
- New objects are found by the fixed detect queries as before.
- A track query that no longer finds its object outputs a low score and is removed.
There is no Hungarian step between frames at inference. The association is implicit in the query's identity.
How training changes
In tracking-by-detection, you train the detector with a detection loss, and you tune everything else by hand. In transformer trackers, training must teach identity across time, so it changes in three ways.
Video clips, not single images. The model is trained on short sequences of frames. Each step processes frames in order and passes track queries forward.
Label assignment across frames. A track query already tied to ground-truth object 7 must keep predicting object 7. Only the detect queries are matched to the remaining objects with bipartite matching. This fixed assignment is what trains identity.
Augmentation to simulate failures. Methods often drop some track queries and add false ones during training. This teaches the model to end tracks when objects leave and to avoid following false positives. Without it, the model learns that every track query always has an object.
A common reported weakness of early MOTR was that detection and tracking compete inside shared queries. Newly appearing objects were often missed, because the model favored continuing existing tracks. Later work such as MOTRv2 added a separate pretrained detector to propose boxes for the detect queries, which regained detection quality. This partly returns to a tracking-by-detection design inside an end-to-end model.
Edge cases and failure modes
- Long occlusions. The query's memory is a single vector updated frame by frame. When an object is hidden for many frames, that vector can drift or be dropped. Tracking-by-detection systems with a ReID gallery can sometimes recover identity after a long gap. Memory-based methods such as MeMOTR add a longer-term memory to address this.
- Crowded scenes. Query-based methods need enough queries and enough training data with similar density. If the maximum number of queries is below the number of people in the scene, objects are missed.
- Domain shift. Hand-tuned trackers can be retuned quickly for a new camera. A trained end-to-end model may need fine-tuning on new video.
- Frame rate. Models trained at one frame rate expect a typical amount of motion between frames. Running them at a very different rate breaks the assumption, as it does for regression-based trackers.
- Compute and latency. Transformer decoders on high-resolution features are heavier than a detector plus SORT. On edge devices, a lightweight detector with ByteTrack is often the only option that meets real-time limits.
- Metrics hide different errors. An end-to-end tracker may score higher on HOTA because of detection quality while still having more ID switches. Read the detection (DetA) and association (AssA) components of HOTA, plus IDF1, before concluding anything.
Choosing an approach
| Situation | Reasonable choice | Why |
|---|---|---|
| Edge device, tight latency, known camera | Fast detector with SORT or ByteTrack | Few moving parts, cheap, easy to tune |
| Crowded pedestrians, need identity across occlusion | Detection plus appearance (DeepSORT-style or FairMOT) | Embeddings help re-identify after gaps |
| Slow motion, simple scenes, want one network | CenterTrack or Tracktor style | No separate association stage |
| Large labeled video dataset, GPU budget, want maximum accuracy | Transformer tracker such as MOTR or a successor | Learns association from data |
| Frequently swapping detectors or classes | Tracking-by-detection | Modular. No retraining of the tracker |
A practical rule: start with a tracking-by-detection baseline and measure it. Move to an end-to-end method only if error analysis shows that association, not detection, is the main limit, and you have the training data and compute to support it.
A small sketch of query carry-over
The code below is not a transformer. It shows only the bookkeeping that track queries imply: each surviving track keeps its ID, new objects get new IDs, and tracks with low scores are removed. This replaces the Hungarian step with a fixed one-to-one mapping given by the model.
class QueryTracker:
"""Bookkeeping for query-based tracking. The model supplies, for each
existing track query, a score and a box. Detect queries supply new objects."""
def __init__(self, keep_thresh=0.5, new_thresh=0.7):
self.keep_thresh = keep_thresh
self.new_thresh = new_thresh
self.next_id = 1
self.active = [] # list of track IDs, in query order
def step(self, track_outputs, detect_outputs):
"""track_outputs: list of (score, box), same order as self.active.
detect_outputs: list of (score, box) from the fixed detect queries."""
results = []
survivors = []
for tid, (score, box) in zip(self.active, track_outputs):
if score >= self.keep_thresh:
survivors.append(tid)
results.append((tid, box))
for score, box in detect_outputs:
if score >= self.new_thresh:
tid = self.next_id
self.next_id += 1
survivors.append(tid)
results.append((tid, box))
self.active = survivors
return results
tracker = QueryTracker()
print(tracker.step([], [(0.9, [10, 10, 50, 50]), (0.4, [200, 200, 240, 240])]))
print(tracker.step([(0.8, [14, 10, 54, 50])], [(0.95, [300, 300, 340, 340])]))
print(tracker.step([(0.3, [18, 10, 58, 50]), (0.9, [301, 301, 341, 341])], []))The first call creates ID 1 and ignores the weak detection. The second call keeps ID 1 and creates ID 2. In the third call, the first track's score falls below the threshold, so it is removed, and only ID 2 continues.
Notice that the thresholds are still hand-chosen. End-to-end does not mean tuning-free.
Summary
End-to-end trackers move association from a separate algorithm into the network. Joint embedding models share the backbone but keep Hungarian matching. Regression trackers reuse the detector's box refinement. Transformer trackers carry identity in track queries. They can learn association from data, but they need video training data and more compute, and they can miss new objects or lose long-occluded ones. Choose them after a tracking-by-detection baseline shows that association is the bottleneck.
Exercise
A team runs YOLO plus ByteTrack on a fixed warehouse camera. Detection recall is high, but forklifts that pass behind shelves for about 3 seconds come back with new IDs. They propose switching to a MOTR-style tracker. What would you check first, and what is a cheaper alternative to try?
Show answer
First check whether the errors come from association rather than detection, by looking at AssA and IDF1 against DetA, and by counting ID switches around the occlusions. The problem is long occlusion, which MOTR-style single-vector query memory also handles poorly, so switching may not help. Cheaper options are to raise the maximum number of missed frames so tracks survive 3 seconds, or to add appearance embeddings (a DeepSORT-style or FairMOT-style ReID gallery) so a returning forklift can be matched to its old track. A long-term-memory method such as MeMOTR is a later option if those fail.
Exercise
In a MOTR-style tracker, why does training drop some track queries and add false ones, and what would go wrong without it?
Show answer
The augmentation teaches the model to end a track when its object has left the scene and to ignore a track query that has no real object. Without it, every track query in training always has a matching object, so the model learns to keep predicting a box for each query forever. At inference this produces ghost tracks and false positives.