Detection Transformer (DETR) is an object detection algorithm that applies transformers to identify and locate objects in images. It was introduced in a seminal
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 DETR[2] (not to be confused with DINO) and CoDETR.[3]
The DETR paper[1] refers to R-CNN as a baseline. A number of innovations were introduced:
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.
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 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 architecture[1] 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.

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 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.
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.
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).
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.[5][6]
Also, the bipartite matching is performed separately per layer, so query-to-object assignments can differ across layers.
{{cite journal}}: Cite journal requires |journal= (help)
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.