Detection Transformer (DETR) is an object detection algorithm that applies transformers to identify and locate objects in images. It was introduced in a seminal 2020 paper by Carion et al.1 and has since become the baseline for a line of influential algorithms, including DINO DETR2 (not to be confused with DINO) and CoDETR.3
Overview
The DETR paper1 refers to R-CNN as a baseline. A number of innovations were introduced:
- Transformer-based design. DETR replaces the R-CNNs final CNN layers with transformer, attention-based components.
- Single-step. DETR replaces the R-CNN's signature two-step process (region proposal and region classification) with a single, unified learned step that predicts both simultaneously. Namely, the network begins with object queries (learned parameter vectors) and trains to predict a bounding box and classification for each.
- Set prediction. Rather than independently predict each query in isolation (as in R-CNN’s region classification), a combined component jointly predicts a set. This enables coordination, which reduces the massive duplication that plagues R-CNN. This in turn removes the necessity for NMS post-processing.
These innovations largely carry over to a comparison with single-step algorithms like YOLO. While YOLO eliminated the R-CNN's region proposal step, it retained the basic structure which applies a learned network to given fixed anchors (paralleling region proposals). DETR's architecture eliminates fixed, unlearned anchors.
Model design
The main components are illustrated in the figure below.
DETR's core is an encoder-decoder transformer. The encoder processes the image and extracts meaningful representations of its content; the decoder attends to these representations to produce one output embedding per object query.
Object queries
Object queries are the DETR equivalents of R-CNN's region proposals and YOLO's anchors. Each corresponds to a candidate prediction, or "slot".
The queries are implicitly interpreted as distinct search specifications. As the encoder features and network weights are shared across all slots, it is the queries that diversify the predictions across different image regions and box sizes. Their role is thus analogous to "experts", each specializing in a distinct region or object shape.
Importantly, a special "no-object" category is included, paralleling R-CNN's background category. The original architecture1 used 100 queries, well beyond the true number of objects in many images. Most object predictions, in such cases, are classified "no-object". As noted above, a major DETR design target is to make no-object predictions as accurate as possible, to eliminate duplication.
Components
- Backbone. The input image is first processed by the backbone, a convolutional neural network (CNN) which captures local texture and semantic structure. Its output is a low-dimensional feature map (the penultimate layer of a pre-trained ResNet network) that is forwarded to the encoder. Its dimensionality reduction (by a factor 32 in the paper) helps manage the encoder's complexity, which is quadratic in the size of its input.
- Encoder. The feature map is transferred to a standard transformer encoder. The backbone's feature map is flattened, projected to the encode embedding dimension, and position-encoded (as with vision transformers). Position encoding includes both spatial coordinates ( and ) of each map component, each encoded separately and concatenated.
- Decoder. The decoder is distinguished from standard transformer equivalent in that its output is produced in parallel, rather than an autoregressive sequential process. The inputs are the encoder outputs, as well as object queries. The outputs are embedding vectors, one for each of the object queries.
- Feed forward network (FFN). A simple multilayer perceptron (MLP) that is applied to each of the object embeddings to produce a candidate object prediction, consisting of bounding box coordinates and a classification score.

Training loss
DETR's training loss is one of its significant innovations.
The loss consists of two steps. The first is bipartite matching, which involves matching each candidate prediction (slot) from the model with a supervising ground truth object (or "no-object" if none is found). In the second step, a differentiable ("Hungarian") loss is computed between the objects in each pair, and used to backpropagate a gradient.
The two steps have parallels with traditional CNN-based algorithms. With R-CNN and YOLO, object prediction slots coincide with region proposals or anchors, which are fixed or computed independently from the object predictor. Matching slots to ground truth, with those algorithms, uses a simple IoU criterion on the corresponding bounding boxes. Matched pairs are used to compute a differentiable loss equivalent to DETR's.
Note that the matching itself does not participate in the differentiable loss. Once computed, at each training step, the matching is treated as fixed, frozen, and external to the optimization, again paralleling R-CNN and YOLO.
Bipartite matching
Bipartite matching is an important ingredient of the DETR design.

Paralleling anchors or region proposals of the above-discussed baselines, DETR uses the bounding box predicted at each slot (bounding box and classification) as the basis for matching. A cost is computed between every slot and ground truth object (elaborated below).
Bipartite matching is achieved by solving the assignment problem, namely minimizing a sum of costs over all matched pairs. In the typical case, the ground truth objects are augmented by no-object nodes, to match the number of prediction slots. The Hungarian algorithm is used to compute the optimal matching.
The cost between a ground truth object number and slot is given by:
where denote the ground truth and predicted bounding boxes, respectively, is the ground truth category, and is the probability assigned by slot to category . is a metric that compares the bounding boxes.1 No-object nodes are assigned for all slots.
The above procedure frames matching as a competitive game between slots. Slots "bid" for ground truth nodes by making predictions that align with their attributes (bounding box and category). This breaks sharply with R-CNN and YOLO, where the matching is based on fixed or separately computed slot attributes (e.g., anchor box coordinates).
Combined with the differentiable loss below, this creates a positive feedback loop that encourages slot specialization and differentiation. The "winning" slots in each sample, which are matched with closely-aligned ground truth nodes, receive a supervising signal from those nodes that reinforces their alignment, nudging them to increase future "bids" to similar objects even further. The inclusion of the term in serves to suppress "losing" slots. A slot outcompeted for a given object is encouraged to predict no-object, raising its future matching cost (reducing the "bid"). This could push it to specialize elsewhere, or alternatively, instill a prioritization between slots that discourages duplicate positive predictions.
Differentiable ("Hungarian") loss
Once matching's are computed, a differential loss can be built upon them. It is computed separately for each node pair, and summed. It closely resembles R-CNN and YOLO equivalents. Note that the matchings themselves are not differenatible.
The loss also resembles the matching cost of the bipartite matching. An exception is no-object nodes, which are assigned rather than zero, and down-weighted by a coefficient (0.1) to compensate for class imbalance.
To accelerate training convergence, DETR uses auxiliary losses at intermediate decoder layers.4 This is achieved by attaching separate prediction heads to each of the layers, and supervising their outputs (bounding boxes and class scores) using the same set-prediction loss, independently applied at each layer.
Challenges
Complexity
The complexity of the DETR encoder is dominated by its self-attention component, whose complexity is quadratic in the number of tokens. As the tokens are derived from a backbone feature map, this forces the use of coarse, low-resolution maps. This is particularly harmful in the detection of small objects. This was addressed in future DETR variants (below).
Training convergence
The heuristic training loss, which stitches hard matching with a differentiable loss, requires many training epochs to converge. This is because object query specializations emerge from training, and are initially (at training start) unspecified and randomly initialized. The procedure implies circular dependence, where specializations both drive the training (via the matching) and are derived from it. Initially, matchings fluctuate substantially, producing incoherent feedback loops. As training progresses, diverse specializations emerge and stabilize, but this takes many epochs to converge. Overcoming this issue was a focus of many subsequent DETR variations.56
Also, the bipartite matching is performed separately per layer, so query-to-object assignments can differ across layers.
See also
See also
References
References
- Carion, Nicolas; Massa, Francisco; Synnaeve, Gabriel; Usunier, Nicolas; Kirillov, Alexander; Zagoruyko, Sergey (2020-05-28), End-to-End Object Detection with Transformers, arXiv, doi:10.48550/arXiv.2005.12872, arXiv:2005.12872, retrieved 2026-04-23
- Zhang, Hao; Li, Feng; Liu, Shilong; Zhang, Lei; Su, Hang; Zhu, Jun; Ni, Lionel M.; Shum, Heung-Yeung (2022-07-11), DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection, arXiv, doi:10.48550/arXiv.2203.03605, arXiv:2203.03605, retrieved 2026-05-19
- Zong, Zhuofan; Song, Guanglu; Liu, Yu (2023-08-10), DETRs with Collaborative Hybrid Assignments Training, arXiv, doi:10.48550/arXiv.2211.12860, arXiv:2211.12860, retrieved 2026-05-19
- Al-Rfou, Rami; Choe, Dokook; Constant, Noah; Guo, Mandy; Jones, Llion (2018-12-10), Character-Level Language Modeling with Deeper Self-Attention, arXiv, doi:10.48550/arXiv.1808.04444, arXiv:1808.04444, retrieved 2026-05-25
- Liu, Shilong; Li, Feng; Zhang, Hao; Yang, Xiao; Qi, Xianbiao; Su, Hang; Zhu, Jun; Zhang, Lei (2022-03-30), DAB-DETR: Dynamic Anchor Boxes are Better Queries for DETR, arXiv, doi:10.48550/arXiv.2201.12329, arXiv:2201.12329, retrieved 2026-05-21
- Li, Feng; Zhang, Hao; Liu, Shilong; Guo, Jian; Ni, Lionel M.; Zhang, Lei (2022-12-08), DN-DETR: Accelerate DETR Training by Introducing Query DeNoising, arXiv, doi:10.48550/arXiv.2203.01305, arXiv:2203.01305, retrieved 2026-05-21