ArticleslgStudy

computer science

Detection Transformer

Detection Transformer is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Detection Transformer rather than just read about it. In short: 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. and has since become the baseline for a line of influential algorithms, including DINO DETR (not to be confused with DINO) and CoDETR.

Detection Transformer — main illustration
Detection Transformer — illustration

Key takeaways

  • Detection Transformer belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Detection Transformer to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Detection Transformer from memory before moving on to harder problems.

Reference excerpt

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. and has since become the baseline for a line of influential algorithms, including DINO DETR (not to be confused with DINO) and CoDETR.

Overview The DETR paper 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 architecture 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 (x and y) 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 wij between a ground truth object number i and slot j is given by:

… excerpt ends here. Continue reading the full article.

Illustrations

Detection Transformer: Illustration of bipartite matching. Two ground truth objects have been matched to five slots (candidate predictions). The ground truth objects have been augmented by three no-object nodes to make one-to-one matching possible.
Illustration of bipartite matching. Two ground truth objects have been matched to five slots (candidate predictions). The ground truth objects have been augmented by three no-object nodes to make one-to-one matching possible.

Worked examples

Example 1 — a first encounter with Detection Transformer

Start with the simplest possible case. Write down what Detection Transformer claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Detection Transformer before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Detection Transformer ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Detection Transformer

In research
Detection Transformer appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Detection Transformer in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Detection Transformer is common in secondary-school and first-year university syllabi. It links to neighbouring topics Algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Detection Transformer outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Detection Transformer” →

How to study Detection Transformer in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Detection Transformer means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Detection Transformer out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Detection Transformer in simple terms?

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. and has since become the baseline for a line of influential algorithms, including DINO DETR (not to be confuse…

Why does Detection Transformer matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Detection Transformer?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Detection Transformer.

Tags

  • Algorithms

Keep exploring