๐ The First Transformer-based Image Detection Model!! DETR! - Transformer๋ก ๊ฐ์ฑ ํ์ง๊น์ง!! DETR์ ๋ฑ์ฅ!! (CVPR 2020)
๐ What is DETR?
In NLP, Transformers are already the dominant force!
But in vision (image detection), CNN-based models like AlexNet and YOLO still prevailed.
Facebook developed DETR, a Transformer-based image detection model,
and demonstrated that Transformers work well in vision tasks too!
DETR (DEtection TRansformer) was introduced by Facebook AI in 2020.
Unlike traditional CNN-based detectors, it is the first object detection model using a Transformer.
๐ Motivation: Limitations of Traditional Object Detectors
- Anchor Box Design: Requires manual tuning
- Complex Post-processing: Needs Non-Maximum Suppression (NMS)
- Modular Design: Not truly end-to-end
- Region Proposal: Required as a separate stage
1. Anchor Box Design: Manual Tuning Required
- Anchor boxes were once an innovative solution for object detection.
- In earlier models, the entire image had to be scanned with sliding windows of various sizes and aspect ratios to detect objects.
- This resulted in high computational cost and issues with varying scales and shapes of objects.
- Anchor boxes were introduced to solve this โ by predefining different shapes of boxes and calculating matches more efficiently.
- Most detectors at the time used multiple predefined anchor boxes to estimate object locations.
- For example: using 3 scales ร 3 aspect ratios = 9 anchors per location.
๐ด Problems:
- Anchor sizes, ratios, and quantities must be manually tuned.
- Optimal anchors vary per dataset โ limited generalization.
- Poor alignment between anchors and objects reduces detection accuracy.
2. Complex Post-processing: Non-Maximum Suppression (NMS)
- Traditional detectors tend to predict multiple boxes for the same object.
- NMS is used to select the box with the highest confidence and remove overlapping ones.
๐ด Problems:
- Performance is sensitive to the NMS threshold.
- May mistakenly suppress nearby true objects.
- Hard to parallelize on GPU, limiting inference speed.
3. Modular Design: Hard to Train End-to-End
- Traditional detection models consist of multiple modules:
- Backbone (CNN feature extractor)
- Region Proposal Network (RPN)
- RoI Pooling
- Classifier & Box Regressor
๐ด Problems:
- Modules operate independently, making end-to-end learning difficult.
- Complex pipelines, harder debugging, and risk of performance bottlenecks.
4. Region Proposal Required
- Models like Faster R-CNN generate thousands of region proposals first, then classify which ones contain real objects.
- This step is performed by the Region Proposal Network (RPN).
๐ด Problems:
- Region proposal introduces extra computation and training.
- Slows down processing and increases architectural complexity.
These challenges laid the foundation for the creation of DETR.
๐ง Key Ideas Behind DETR
โ How does DETR solve these traditional problems?
Traditional Problems | DETRโs Solution |
---|---|
Anchor Boxes | โ Not used โ boxes are predicted via object queries |
NMS | โ Not used โ each GT is assigned one prediction only |
Modular Structure | โ Unified End-to-End Transformer-based model |
Region Proposal | โ Not needed โ Transformer directly predicts box location |
Summary of Advantages
- โ Fully End-to-End Training Structure
- ๐งน Anchor-Free & NMS-Free
- ๐ฌ Global Context with Transformer Attention
Advantage 1: Fully End-to-End Training
- DETR consists of a single integrated Transformer model:
- Input image โ predicted object boxes + classes
- Trained using a single loss function
- No need for region proposal, anchor configuration, or NMS post-processing.
๐ Result: Simplified code, easier debugging and maintenance
Advantage 2: ๐งน Anchor-Free & NMS-Free
- Anchor-Free:
- No predefined anchor boxes
- Object queries directly predict positions
- Automatically adapts to dataset characteristics โ no anchor tuning
- NMS-Free:
- Each object query learns to handle only one object
- No need to remove overlaps via NMS
- Accurate predictions even without post-processing
๐ Enables a cleaner and simpler training/inference pipeline
Advantage 3: Global Context from Transformers
- CNN-based detectors focus on local features
- DETRโs Transformer models learn:
- Global relationships between image patches
- Robustness to distant parts or occluded views of an object
๐ Useful for detecting objects in cluttered scenes or with structural context
โ DETR Architecture
DETR frames object detection as a sequence prediction task, enabling direct application of the Transformer.
- Backbone: CNN (e.g., ResNet)
- Transformer Encoder-Decoder
- Object Queries: Fixed-size set of learnable queries
- Hungarian Matching: One-to-one match with ground truth
- No Post-processing: NMS not needed
DETR Pipeline Summary:
1
2
3
4
5
Input Image
โ CNN Backbone (e.g., ResNet)
โ Transformer Encoder-Decoder
โ Object Query Set
โ Predictions {Class, Bounding Box}โ~โ
DETR Component 1: Backbone
- Extracts image features
- Uses a CNN-based backbone (e.g., ResNet-50, ResNet-101) to process the input image
- Outputs a 2D feature map that retains spatial layout and semantics
DETR Component 2: Transformer Encoder-Decoder
- Encoder:
- Flattens CNN feature map into a sequence of tokens
- Processes them with self-attention in the Transformer encoder
- Learns global context across the entire image
- Decoder:
- Input: a fixed set of learnable object queries
- Each query is responsible for predicting one object
- Uses cross-attention to interact with encoder outputs and predicts bounding boxes and classes
DETR Component 3: Object Query
- DETR uses a fixed number of learnable object queries
- For example, with 100 queries, the model always outputs 100 predictions
- Some predictions correspond to real objects, others are classified as โno objectโ
๐ Unlike anchor-based approaches, this enables direct and interpretable position learning
DETR Component 4: Hungarian Matching
๐ง What is Hungarian Matching?
- A classic algorithm for solving the assignment problem, which finds the optimal one-to-one pairing between two sets based on a cost matrix
Yes โ itโs named after Hungarian mathematicians!
- Goal:
- Given a set of jobs and workers with assignment costs,
- Find the minimum-cost one-to-one matching
- Example:
- If you have 3 workers and 3 tasks,
- How should they be assigned to minimize total cost?
๐ง Hungarian Matching in DETR
This algorithm is used only during training!
- During training, DETR uses Hungarian Matching to match predicted boxes to ground-truth objects (GT)
- DETRโs 100 queries may predict many different boxes for the same object
- But only the best match is used for each GT object
- It calculates a cost matrix combining classification error, L1 box distance, and IoU
- Matching ensures that:
- Each GT is paired with the best fitting query
- Overlapping or redundant boxes are discouraged
- This enables clean and duplicate-free training without needing NMS
๐ However, during inference, no such matching is used โ
so if the model is not well trained, it can predict multiple boxes for the same object.
โ ๏ธ DETR Limitations
Summary in One Line:
Itโs slow to train, and not great at small object detection.
- ๐ข Very slow convergence (training requires hundreds of thousands of steps)
- ๐ Poor performance on small objects
- ๐ง High computational cost of Transformer self-attention
๐ข Slow Convergence
- DETR takes a long time to learn meaningful assignments between object queries and GT
- Compared to models like Faster R-CNN, it converges very slowly
500 epochs!? Thatโs a lot!
- On the COCO dataset, it typically needs 500+ epochs for strong performance
๐ Reason:
- Object queries are initialized randomly
- Early predictions are meaningless
- Weak supervision signal in the beginning (many queries just predict background)
๐ Weakness on Small Objects
- While Transformers capture global context, they may overlook fine local details
- Small objects often get lost in the low-resolution feature map
- Object queries may struggle to lock onto such small targets
๐ Traditional CNN detectors often use FPNs and multi-scale tricks
DETR (in its original form) lacked these enhancements
๐ง Transformer Compute Cost
- Transformer self-attention has O(Nยฒ) complexity
- (N: number of patches/tokens, proportional to image resolution)
- High-resolution inputs lead to huge compute and memory demands
๐ As a result:
- Inference is slower
- Large memory use and limited batch size
Curiosity While Studying โ How is DETR related to ViT?
I thought ViT was the model that brought Transformers to vision?
But turns out DETR came first!
In short: ViT uses the Transformer encoder for classification,
while DETR uses CNN features with a Transformer for object detection.
- ViT (Vision Transformer) was released after DETR (Oct 2020)
- DETR was one of the first applications of Transformers in vision
DETR is a CNN + Transformer hybrid,
while ViT is a pure Transformer vision model- After ViT, many DETR variants started using ViT backbones
(e.g., DINOv2)
๐ง Core Differences
Item | DETR | ViT |
---|---|---|
Published | May 2020 (ECCV) | Oct 2020 (arXiv) |
Transformer Use | Encoder-Decoder for object detection | Encoder-only for image classification |
Input Format | CNN feature map to Transformer | Raw image patches to Transformer |
Model Purpose | Predict bounding boxes + classes | Predict class label |
ViTโs Impact on DETR Evolution
- ViT popularized Transformer backbones for vision
- Later DETR variants began using ViT:
- e.g., DINO + Swin Transformer
- e.g., Grounding DINO + CLIP-ViT
- e.g., DINOv2 + ViT-L
๐ ViT made DETR variants more expressive and opened new paths:
open-vocabulary detection, grounding, and multimodal vision models
๐ฌ Final Thoughts
Transformers are amazing โ and DETR is proof that
even in vision, weโre moving from CNNs to attention-based models!
Itโs a bit disappointing that like most object detectors, DETR can only detect pretrained classes.
Thankfully, newer research addresses this with the grounding family of models.
And as DETR merges with ViT, we now see many successors that push the field forward.
Iโm excited to continue learning from here!
(ํ๊ตญ์ด) ๐ง ํธ๋์คํฌ๋จธ ๊ธฐ๋ฐ์ ์ฒซ Image Detection ๋ชจ๋ธ!! DETR!
ใEnd-to-End Object Detection with Transformersใ(CVPR, 2020) ๊ณต๋ถ
๋ ผ๋ฌธ: End-to-End Object Detection with Transformers
๋ฐํ: CVPR 2020
์ฝ๋: facebookresearch/detr
โ๏ธ ์ ์: Meta AI Research (Carion, Massa et al.)
๐ ํ์ค ์์ฝ: Transformer๋ฅผ ์ฌ์ฉํด ๊ฐ์ฑ ํ์ง๋ฅผ ํ๋ ์ฒซ ๋ชจ๋ธ!!!
๐ DETR๋ ๋ฌด์์ธ๊ฐ?
ํ ์คํธ ์ธ๊ณ์์๋ ์ด๋ฏธ Transformer๊ฐ ์์ฑํ๊ฒ ํ๋์ค!!
๊ทธ๋ฌ๋ ์ด๋ฏธ์ง ์ธ๊ณ๋ (์ด๋ฏธ์ง Detection) Alexnet, Yolo ๋ฑ ์ฌ์ ํ CNN ๊ธฐ๋ฐ์ ๋ชจ๋ธ๋ค๋ง ์กด์ฌ!
ํ์ด์ค๋ถ์์ Transformer ๊ธฐ๋ฐ์ ์ด๋ฏธ์ง Detection ๋ชจ๋ธ DETR์ ๊ฐ๋ฐํ๊ณ ,
์ด๋ฏธ์ง์ ์์ญ์์๋ Transformer๊ฐ ์ ์๋ํจ์ ๋ณด์ฌ์ค!!
DETR (DEtection TRansformer)๋ Facebook AI์์ 2020๋
์ ๋ฐํํ ๊ฐ์ฒด ํ์ง ๋ชจ๋ธ๋ก,
๊ธฐ์กด CNN ๊ธฐ๋ฐ์ ํ์ง๊ธฐ์ ๋ฌ๋ฆฌ Transformer๋ฅผ ์ฌ์ฉํ ์ต์ด์ ๊ฐ์ฒด ํ์ง ๋ชจ๋ธ!!
๐ ์ฐ๊ตฌ์ ๋ฐฐ๊ฒฝ : ๊ธฐ์กด ๊ฐ์ฒด ํ์ง(Image Detection) ๋ฐฉ์์ ํ๊ณ
- Anchor Box ์ค๊ณ: ์๋ ํ๋ ํ์
- ๋ณต์กํ ํ์ฒ๋ฆฌ: Non-Maximum Suppression(NMS)
- ๋ชจ๋ ๋ถ๋ฆฌ ๊ตฌ์กฐ: End-to-End ํ์ต์ด ์ด๋ ค์
- Region Proposal ํ์
1. Anchor Box ์ค๊ณ: ์๋ ํ๋ ํ์
- ์๋ Anchor Box ๋ ๊ฐ์ฒด ๊ฐ์ง์ ์์ด ์ฐธ์ ํ ํด๊ฒฐ์ฑ
์ด์์
- ๊ธฐ์กด์๋ ๊ฐ์ฑ ์ธ์์ ์ํค ์ด๋ฏธ์ง ๋ด์ ๋ชจ๋ ๊ฐ๋ฅํ ์์น์ ๋ค์ํ ํฌ๊ธฐ์ ์๋์ฐ๋ฅผ ์ฌ๋ผ์ด๋ฉํ๋ฉฐ ๊ฐ์ฒด์ ์กด์ฌ ์ฌ๋ถ๋ฅผ ํ์ธํ์ต๋๋ค.
- ์ด๋ ๋์ ๊ณ์ฐ๋น์ฉ, ๋ค์ํ ์ข ํก๋น, ๊ฐ์ฒด ํฌ๊ธฐ์ ๋ณํ ๋ฑ์ ๋ฌธ์ ๊ฐ์์์ต๋๋ค.
- ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด Anchor Box์ด ๋ฑ์ฅ์ฐ!!
- Anchor Box๋ ๋ฏธ๋ฆฌ ๋ค์ํ ํํ์ ๋ฐ์ค๋ฅผ ์ ์ํด์ ํจ์จ์ ์ผ๋ก ๊ณ์ฐํ๊ฒํ๋๊ฒ์!!
- ์ด์, ์ด์์ ๋๋ถ๋ถ์ ๊ฐ์ฒด ํ์ง๊ธฐ๋ ์ฌ์ ์ ์ ์๋ ์ฌ๋ฌ ๊ฐ์ Anchor Box๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌผ์ฒด์ ์์น ์ถ์
- ์: 3๊ฐ์ ์ค์ผ์ผ๊ณผ 3๊ฐ์ ๋น์จ์ ์กฐํฉํ์ฌ ์ด 9๊ฐ์ anchor๋ฅผ ํ๋์ ์์น์ ๋ฐฐ์น
๐ด ๋ฌธ์ ์
- Anchor์ ํฌ๊ธฐ, ๋น์จ, ์๋ ๋ฑ์ ์๋ ์ค๊ณ ๋ฐ ํ๋ํด์ผ ํจ
- ๋ฐ์ดํฐ์ ๋ง๋ค ์ต์ ์ anchor ๊ตฌ์ฑ์ด ๋ฌ๋ผ ๋ฒ์ฉ์ฑ์ด ๋จ์ด์ง
- Anchor box๊ฐ ์ค์ ๊ฐ์ฒด์ ๋ง์ง ์์ผ๋ฉด ํ์ง ์ฑ๋ฅ ์ ํ
2. ๋ณต์กํ ํ์ฒ๋ฆฌ: Non-Maximum Suppression (NMS)
- ๊ธฐ์กด ๋ชจ๋ธ๋ค์ ๊ฐ์ ๊ฐ์ฒด์ ๋ํด ์ฌ๋ฌ ๊ฐ์ ๋ฐ์ค๋ฅผ ์์ธก ํ๊ฒ๋จ
- ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด NMS ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉ, ๊ฒน์น๋ ๋ฐ์ค ์ค์์ ๊ฐ์ฅ ์ ๋ขฐ๋ ๋์ ๊ฒ๋ง ๋จ๊ธฐ๊ณ ๋๋จธ์ง๋ฅผ ์ ๊ฑฐ
๐ด ๋ฌธ์ ์
- NMS๋ ์๊ณ๊ฐ ์ค์ ์ด ๋ฏผ๊ฐํ์ฌ ์ฑ๋ฅ์ ์ํฅ์ ์ค
- ๊ทผ์ ํ ๊ฐ์ฒด๋ฅผ ์๋ชป ์ ๊ฑฐํ ์ํ์ด ์์
- GPU ๋ณ๋ ฌํ์ ์ ํฉํ์ง ์์ ์ฐ์ฐ ์๋์ ์ ์ฝ
3. ๋ชจ๋ ๋ถ๋ฆฌ ๊ตฌ์กฐ: End-to-End ํ์ต์ด ์ด๋ ค์
- ๊ธฐ์กด ํ์ง๊ธฐ๋ ์ฌ๋ฌ ๊ฐ์ ๋ชจ๋๋ก ๊ตฌ์ฑ๋จ:
- Backbone (CNN ๊ธฐ๋ฐ ํน์ง ์ถ์ถ๊ธฐ)
- Region Proposal Network (RPN)
- RoI Pooling
- Classifier & Box Regressor
๐ด ๋ฌธ์ ์
- ๊ฐ ๋ชจ๋์ด ๋ถ๋ฆฌ๋ ๋ฐฉ์์ผ๋ก ๋์ํ์ฌ ์ ์ฒด ๋ชจ๋ธ์ ํ๋๋ก ํ์ตํ๊ธฐ ์ด๋ ค์
- ํ์ต ํ์ดํ๋ผ์ธ์ด ๋ณต์กํ๊ณ , ๋๋ฒ๊น ์ด ์ด๋ ต๊ณ , ์ฑ๋ฅ ๋ณ๋ชฉ์ด ๋ฐ์ํ ์ ์์
4. Region Proposal ํ์
- Faster R-CNN๊ณผ ๊ฐ์ ๋ชจ๋ธ์ ๋จผ์ ์์ฒ ๊ฐ์ ํ๋ณด ๋ฐ์ค(region proposals)๋ฅผ ์์ฑํ ํ, ์ด ์ค์์ ์ง์ง ๊ฐ์ฒด๋ฅผ ๋ถ๋ฅ
- ์ด ๊ณผ์ ์ RPN(Region Proposal Network)์ ํตํด ์ํ๋จ
๐ด ๋ฌธ์ ์
- Region Proposal ๋จ๊ณ๋ ์ถ๊ฐ์ ์ธ ์ฐ์ฐ๊ณผ ํ์ต์ด ํ์
- ์ ์ฒด ์ฒ๋ฆฌ ์๋๋ฅผ ๋๋ฆฌ๊ฒ ๋ง๋ค๊ณ ๊ตฌ์กฐ ๋ณต์ก๋๋ฅผ ์ฆ๊ฐ์ํด
์ด๋ฌํ ๋ฌธ์ ์ ๋ค์ DETR๊ฐ ๋ฑ์ฅํ๊ฒ ๋ ๊ณ๊ธฐ์ด์ ๋ฐฐ๊ฒฝ์ ๋๋ค.
๐ง DETR์ ํต์ฌ ์์ด๋์ด
โ DETR๋ ๊ธฐ์กด์ ๋ฌธ์ ๋ค์ ์ด๋ป๊ฒ ํด๊ฒฐํ์๊น?
๊ธฐ์กด ๋ฌธ์ ์ | DETR์ ์ ๊ทผ ๋ฐฉ์ |
---|---|
Anchor Box ํ์ | โ ์์ โ object query๋ฅผ ํตํด ์ง์ box ์์ธก |
NMS ํ์ | โ ์์ โ ํ๋์ GT์ ํ๋์ ์์ธก box๋ง ํ ๋น |
๋ชจ๋ ๋ถ๋ฆฌ ๊ตฌ์กฐ | โ End-to-End transformer ๊ตฌ์กฐ๋ก ํตํฉ |
Region Proposal ํ์ | โ ์์ โ transformer๊ฐ ์ง์ ์์น ์์ธก ์ํ |
์ฅ์ ์์ฝ
- โ ์์ ํ End-to-End ํ์ต ๊ตฌ์กฐ
- ๐งน Anchor-Free & NMS-Free
- ๐ฌ Transformer์ ๊ธ๋ก๋ฒ ์ปจํ ์คํธ ํ์ฉ
์ฅ์ 1 : ์์ ํ End-to-End ํ์ต ๊ตฌ์กฐ
- DETR์ ํ๋์ ํตํฉ๋ transformer ๋คํธ์ํฌ๋ก ๊ตฌ์ฑ,
- ์ด๋ฏธ์ง ์ ๋ ฅ โ ๊ฐ์ฒด ์์น(box) + ํด๋์ค๊น์ง
- ๋จ ํ๋์ ์์ค ํจ์๋ก ์ง์ ํ์ต ๊ฐ๋ฅ
- ๋ณ๋์ region proposal, anchor ์ค์ , NMS ๋ฑ์ ํ์ฒ๋ฆฌ๊ฐ ํ์ ์์
๐ ๊ฒฐ๊ณผ์ ์ผ๋ก ์ฝ๋๊ฐ ๋จ์ํด์ง๊ณ , ๋๋ฒ๊น ๊ณผ ์ ์ง๋ณด์๊ฐ ์ฌ์์ง
์ฅ์ 2 : ๐งน Anchor-Free & NMS-Free
- Anchor-Free:
- ์ฌ์ ์ ์๋ anchor box๊ฐ ์๊ณ
- transformer์ object query๊ฐ ๊ฐ์ฒด ์์น๋ฅผ ์ง์ ์์ธก
- anchor ํ๋ ํ์ ์์ด, ๋ฐ์ดํฐ ํน์ฑ์ ์๋ ์ ์
- NMS-Free:
- DETR๋ ๊ฐ object query๊ฐ ํ๋์ ๊ฐ์ฒด๋ง ๋ด๋นํ๋๋ก ํ์ต๋จ
- ๊ฒน์น๋ ๋ฐ์ค๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ NMS๊ฐ ๋ถํ์
- ํ์ฒ๋ฆฌ ์์ด๋ ์ ํํ ์์ธก์ด ๊ฐ๋ฅ
๐ ์ด๋ก ์ธํด ํ์ต/์ถ๋ก ํ์ดํ๋ผ์ธ์ด ๋ ๊ฐ๋จํ๊ณ ๊น๋ํด์ง
์ฅ์ 3 : Transformer์ ๊ธ๋ก๋ฒ ์ปจํ ์คํธ ํ์ฉ
- ๊ธฐ์กด CNN ๊ธฐ๋ฐ ํ์ง๊ธฐ๋ ๋ก์ปฌ ํน์ง(local pattern) ์ค์ฌ
- ๋ฐ๋ฉด DETR๋ transformer๋ฅผ ์ฌ์ฉํ์ฌ
- ์ด๋ฏธ์ง ์ ์ฒด์ ํจ์น ๊ฐ ๊ด๊ณ(global context)๋ฅผ ํ์ตํจ
- ๊ฐ์ฒด๊ฐ ๋จ์ด์ ธ ์๊ฑฐ๋ ๋ถ๋ถ์ ์ผ๋ก ๋ณด์ผ ๋๋ ๊ฐ๋ ฅํจ
๐ ๋ณต์กํ ๋ฐฐ๊ฒฝ, ๊ฒน์น ๊ฐ์ฒด, ๊ตฌ์กฐ์ ๊ด๊ณ ํ์ง์ ์ ๋ฆฌ
โ DETR์ ๊ตฌ์กฐ!
DETR๋ ๊ฐ์ฒด ํ์ง๋ฅผ sequence prediction ๋ฌธ์ ๋ก ๋ฐ๊พธ์ด Transformer๋ฅผ ์ ์ฉํฉ๋๋ค.
- Backbone: ResNet ๋ฑ CNN ์ฌ์ฉ
- Transformer Encoder-Decoder ๊ตฌ์กฐ
- Object Query: ์์ธกํ ๊ฐ์ฒด ๊ฐ์๋งํผ learnable query ์ฌ์ฉ
- Hungarian Matching: ground truth์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ์ผ๋์ผ ๋์
- Post-processing ์์: NMS ์์ด end-to-end๋ก ํ์ต
DETR์ ๊ตฌ์กฐ ์์ฝ!
1
2
3
4
5
Input Image
โ CNN Backbone (e.g., ResNet)
โ Transformer Encoder-Decoder
โ Object Query Set
โ Predictions {Class, Bounding Box}โ~โ
DETR์ ์์1 : Backbone
- ์ด๋ฏธ์ง ํน์ง ์ถ์ถ
- ์ ๋ ฅ ์ด๋ฏธ์ง๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด CNN ๊ธฐ๋ฐ backbone ์ฌ์ฉ (์: ResNet-50, ResNet-101)
- ์ด ๋จ๊ณ์์๋ ๊ณ ์์ค์ ์๊ฐ ํน์ง(feature map)์ ์ถ์ถ
- ์ถ๋ ฅ: ์ด๋ฏธ์ง์ ๊ณต๊ฐ์ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ 2D feature map
DETR์ ์์2 : Transformer Encoder-Decoder
- Encoder:
- CNN์ feature map์ flattenํ์ฌ sequence๋ก ๋ณํ
- ์ด sequence๋ฅผ self-attention ๊ธฐ๋ฐ transformer encoder์ ์ ๋ ฅ
- ์ด๋ฏธ์ง์ ์ ์ญ ์ปจํ ์คํธ(global context)๋ฅผ ํ์ต
- Decoder:
- ์ ๋ ฅ: learnableํ object query ์งํฉ
- ๊ฐ query๋ ์์ธกํด์ผ ํ ๊ฐ์ฒด ํ ๊ฐ๋ฅผ ๋ด๋น
- cross-attention์ ํตํด ์ด๋ฏธ์ง์ ์ํธ์์ฉํ๋ฉฐ ๊ฐ์ฒด ์์น(box)์ ํด๋์ค(class)๋ฅผ ์์ธก
DETR์ ์์3 : Object Query
- DETR๋ ๊ณ ์ ๋ ๊ฐ์์ learnable object query๋ฅผ ์ฌ์ฉ
- ์: object query๊ฐ 100๊ฐ๋ผ๋ฉด, ํญ์ 100๊ฐ์ ์์ธก์ด ์ถ๋ ฅ๋จ
- ์ด ์ค ์ผ๋ถ๋ ์ค์ ๊ฐ์ฒด, ์ผ๋ถ๋ โno objectโ๋ก ๋ถ๋ฅ๋จ
๐ ๊ธฐ์กด anchor box ๊ธฐ๋ฐ ์ ๊ทผ๊ณผ ๋ฌ๋ฆฌ, ์ง์ ์ ์ธ ์์น ํ์ต์ด ๊ฐ๋ฅ
DETR์ ์์4 : Hungarian Matching
๐ง Hungarian Matching์ด๋?
- Hungarian Matching ์๊ณ ๋ฆฌ์ฆ์ ๋ ์งํฉ ๊ฐ์ โ์ต์ ์ ์ผ๋์ผ ๋งค์นญโ์ ์ฐพ๋, ํ ๋น ๋ฌธ์ (Assignment Problem)๋ฅผ ํด๊ฒฐํ๋๋ฐ ์ต์ ํ๋ ์๊ณ ๋ฆฌ์ฆ
์ด๋ฆ์ฒ๋ผ ํ๊ฐ๋ฆฌ ์ํ์์ ์ํ์ฌ ๊ฐ๋ฐ๋ ๊ฒ์ด ๋ง์!!
- ๋ชฉํ:
- ์์ (Job)๊ณผ ์์ ์(Worker) ์ฌ์ด์ ๋น์ฉ(cost)์ด ์ฃผ์ด์ก์ ๋,
- ์ด ๋น์ฉ์ด ์ต์๊ฐ ๋๋ 1:1 ๋งค์นญ์ ์ฐพ๋ ๊ฒ
- ์:
- 3๋ช ์ ์์ ์์ 3๊ฐ์ ์์ ์ด ์์ ๋,
- ๊ฐ๊ฐ์ ์ด๋ป๊ฒ ๋ฐฐ์ ํ๋ฉด ์ด ๋น์ฉ์ด ์ต์ํ๋ ๊น?
๐ง DETR์์์ Hungarian Matching!!
์ด ํ๊ฐ๋ฆฌ์ ์๊ณ ๋ฆฌ์ฆ์ ํ์ต์์๋ง ์ฌ์ฉ๋จ!!
- DETR์์๋ ํ์ต์์ ์์ธก๋ ๊ฐ์ฒด์ ์ค์ ๊ฐ์ฒด(GT) ๊ฐ์ ๋งค์นญ์ ์ด ์๊ณ ๋ฆฌ์ฆ์ ํ์ฉ
- DETR์ ์ด์ ๊ฒฐ๊ณผ์์๋ ํ๋์ ๊ฐ์ฑ๋ฅผ ์ฌ๋ฌ ๋ฐฉ์์ผ๋ก ์์ธก ํ ๊ฒ์ด๊ณ !
- ๊ทธ ์ค ์ค์ ๊ฒฐ๊ณผ ํ๋๋ง์ ๋งค์นญํด์ผ ํ๋ฉฐ
- โ๋ชจ๋ GT ๊ฐ์ฒด๋ฅผ ์์ธก ์ค ๊ฐ์ฅ ์ ๋ง๋ ํ๋์ query์ ๋งค์นญโํ๋ ์ต์ ์ ์กฐํฉ์ ๊ณ์ฐ
- ์ด๋ฅผ ํตํด NMS ์์ด๋ ์ค๋ณต ์์ด ๊น๋ํ ํ์ง ๊ฒฐ๊ณผ ์ ์ ๊ฐ๋ฅ
- ๋ฌผ๋ก , ์ถ๋ก ์์๋ ๋ณ๋ ์๊ณ ๋ฆฌ์ฆ์ด ์๊ธฐ์ ๋ชจ๋ธ์ ์ฑ๋ฅ์ ๋ฐ๋ผ ํ๊ฐ์ ๊ฐ์ฒด๋ฅผ ์ฌ๋ฌ๊ฐ๋ก ํ์งํ ์ํ๋ ์กด์ฌ
โ ๏ธ DETR์ ํ๊ณ
ํ๊ณ๋ฅผ ์์ฝํ๋ฉด!
ํ๊ณ ํ์ค์์ฝ! : ์๋๊ฐ ๋๋ฆฌ๊ณ ์์ ๊ฐ์ฒด์ ์ฝํ๋ค!!
- ๐ข ์๋ ด ์๋ ๋งค์ฐ ๋๋ฆผ (ํ์ต ์๊ฐ์ด ์์ญ๋ง ์คํ ํ์)
- ๐ ์์ ๊ฐ์ฒด ํ์ง ์ฑ๋ฅ ์ ํ
- ๐ง Transformer ์ฐ์ฐ๋ ๋ฌธ์ (๊ณ ํด์๋ ์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ด๋ ค์)
๐ข ์๋ ด ์๋ ๋งค์ฐ ๋๋ฆผ
- DETR๋ ํ์ต ์ด๊ธฐ์๋ object query์ ground truth ๊ฐ์ ์๋ฏธ ์๋ ์ฐ๊ฒฐ์ ์ฐพ๋ ๋ฐ ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆผ
- ๊ธฐ์กด ๋ชจ๋ธ(Faster R-CNN ๋ฑ)์ ๋นํด ์๋ ด ์๋๊ฐ ํ์ ํ ๋๋ฆผ
500 epoch๋ผ๋!! ์์ฒญ ๋ง์ง์!?
- COCO dataset ๊ธฐ์ค, 500 epoch ์ด์ ํ์ตํด์ผ ์์ ์ ์ธ ์ฑ๋ฅ ๋๋ฌ
๐ ์ด์ :
- object query๊ฐ ๋๋คํ ์ํ๋ก ์์๋๋ฉฐ, ์ง๋ ํ์ต ์ด์ ๊น์ง ์๋ฏธ ์๋ ์์ธก์ด ์ง์๋จ
- ์ด๊ธฐ์๋ ๋ง์ query๊ฐ background๋ก ๋งคํ๋๋ฉฐ, ํ์ต ์ ํธ๊ฐ ๋ถ์กฑํจ
๐ ์์ ๊ฐ์ฒด ํ์ง ์ฑ๋ฅ ์ ํ
- Transformer๋ global attention์ ๊ธฐ๋ฐ์ผ๋ก ์๋ํ์ง๋ง, ์ด๋ก ์ธํด ์ธ๋ฐํ ๊ตญ์์ ์ ๋ณด(local details)๊ฐ ์ฝํด์ง ์ ์์
- ์์ ๊ฐ์ฒด๋ feature map์์ ์ ํํ๋์ง ์์ query๊ฐ ํด๋น ๊ฐ์ฒด๋ฅผ ์ก์๋ด๊ธฐ ์ด๋ ค์
- ํนํ, ํด์๋๊ฐ ๋ฎ์ feature map ์์์ ์์ ๊ฐ์ฒด๋ ๋ ํฌ๋ฏธํด์ง
๐ ๊ธฐ์กด CNN ๊ธฐ๋ฐ ํ์ง๊ธฐ๋ค์ ์์ ๊ฐ์ฒด ์ฒ๋ฆฌ๋ฅผ ์ํ FPN, multi-scale strategy ๋ฑ์ ํ์ฉํ์ง๋ง
DETR ์ด๊ธฐ ๋ฒ์ ์ ๊ทธ๋ฐ ๋ณด์์ด ๋ถ์กฑํ์
๐ง Transformer ์ฐ์ฐ๋ ๋ฌธ์
- Transformer ๊ตฌ์กฐ๋ self-attention ์ฐ์ฐ์ ๋ณต์ก๋๊ฐ O(Nยฒ)
(N: ์ ๋ ฅ ์ํ์ค ๊ธธ์ด โ ์ฆ, ํฝ์ ์์ ๋น๋ก) - ๊ณ ํด์๋ ์ด๋ฏธ์ง์ผ์๋ก ์ฐ์ฐ๋๊ณผ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ์ด ๊ธ๊ฒฉํ ์ฆ๊ฐ
๐ ๊ฒฐ๊ณผ์ ์ผ๋ก:
- ์ถ๋ก ์๋๊ฐ ๋๋ฆผ
- GPU ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ด ํฌ๊ณ , batch size๋ ์ ํ์
๊ณต๋ถํ๋ฉด์ ๊ถ๊ธ์ฆ!! - DETR์ ViT ๊ด๊ณ๋??
ViT๊ฐ ์ด๋ฏธ์ง๋ฅผ Transformer๋ก ์ ์ฉ์ํจ ๊ฑฐ๋ผ๊ณ ๊ณต๋ถํ๋๋!?
๊ทธ๋ฐ๋ฐ DETR์ด ์ด ViT๋ณด๋ค ๋จผ์ ๋์์,,๊ฒฐ๋ก ์ ViT๋ Transformer๋ฅผ ์ธ์ฝ๋๋ก ์ด ๊ฑฐ๊ณ ,
DETR์ CNN์ผ๋ก ๋ฒกํฐํํ ๊ฒฐ๊ณผ๋ฅผ Transformer์ ๋ฃ์ด ๊ฐ์ฒด ํ์ง๋ฅผ ํ ๊ฑฐ์๋ค!
- ViT(Vision Transformer)๋ DETR ์ดํ ๋ฐํ๋จ (2020.10)
- DETR๋ Transformer๋ฅผ vision์ ์ ์ฉํ ์ต์ด์ ์๋ ์ค ํ๋
- ์ฆ, DETR๋ CNN + Transformer์ ํ์ด๋ธ๋ฆฌ๋, ViT๋ ์์ Transformer ๊ธฐ๋ฐ ๋น์ ๋ชจ๋ธ
- ViT ๋ฑ์ฅ ์ดํ DETR ๊ณ์ด์ ViT๋ฅผ backbone์ผ๋ก ์ฌ์ฉํ๋ ๋ชจ๋ธ๋ค์ด ๋ฑ์ฅ (์: DINOv2)
๐ง ํต์ฌ ์ฐจ์ด ์์ฝ
ํญ๋ชฉ | DETR | ViT |
---|---|---|
๋ฐํ ์๊ธฐ | 2020๋ 5์ (ECCV) | 2020๋ 10์ (arXiv) |
Transformer ์ฉ๋ | Encoder-Decoder ๊ตฌ์กฐ๋ก ๊ฐ์ฒด ํ์ง์ ์ฌ์ฉ | Encoder๋ง ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ๋ถ๋ฅ์ ์ฌ์ฉ |
์ ๋ ฅ ๋ฐฉ์ | CNN backbone์ feature map์ transformer์ ์ ๋ ฅ | ์ด๋ฏธ์ง๋ฅผ patch๋ก ์๋ผ ์ง์ transformer์ ์ ๋ ฅ |
๊ตฌ์กฐ ๋ชฉ์ | ๊ฐ์ฒด ํ์ง (bounding box + class) | ์ด๋ฏธ์ง ์ ์ฒด์ ๋ํ label ๋ถ๋ฅ |
ViT์ ์ํฅ: DETR ๊ตฌ์กฐ์ ๋ฐ์
- ViT์ ๋ฑ์ฅ์ vision ๋ถ์ผ์์ Transformer ๊ธฐ๋ฐ ๋ฐฑ๋ณธ ์ฌ์ฉ์ ๋์คํ์ํด
- ์ดํ DETR ๊ณ์ด ๋ชจ๋ธ๋ค๋ ViT๋ฅผ ๋ฐฑ๋ณธ์ผ๋ก ์ฑํํ๊ธฐ ์์
- ์: DINO + Swin Transformer
- ์: Grounding DINO + CLIP-ViT
- ์: DINOv2 + ViT-L
๐ ViT ๋๋ถ์ DETR ๊ณ์ด์ ๋ ๊ฐ๋ ฅํ ํํ๋ ฅ์ ๊ฐ์ง๊ฒ ๋์๊ณ ,
open-vocabulary detection, grounding, multimodal ๋ถ์ผ๋ก ํ์ฅ ๊ฐ๋ฅํด์ง
๐ฌ ์ ๋ฆฌ ๋ฐ ๊ฐ์ธ ์๊ฒฌ
Transformer ์ ๊ตฌ์กฐ๊ฐ ์ผ๋ง๋ ๋๋จํ์ง ๋ค์๊ธ ๋๋ผ๊ฒ๋ฉ๋๋ค!!
DETR์ฐ๊ตฌ๊ฐ ์ด๋ฏธ์ง ๋ถ์ ์ญ์ CNN์ ์๋์์ Transformer ์๋๋ก์ ๋ฌธ์ ์ฐ ๋ํ์ ์ฐ๊ตฌ์ธ๊ฒ ๊ฐ๋ค์~!
๊ทธ๋ฆฌ๊ณ ! ๊ธฐ์กด Object Detection๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํ์ต๋ ๊ฐ์ฑ๋ง ์ธ์ํ ์ ์์ด ์์ฌ์ด๊ฒ ๊ฐ์ต๋๋ค!!
์ถํ ์ฐ๊ตฌ ์ค์๋ ์ด๋ฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ์ฐ๊ตฌ๋ ์๊ณ , gounding
์ด๋ผ๋ ์ด๋ฆ์ ์ฐ๊ตฌ๋ค์ด๋ผ๊ณ ํฉ๋๋ค
๋ฟ๋ง ์๋๋ผ DETR์ด ViT์ ๊ฒฐํฉํ๋ฉฐ ์ฌ๋ฌ ํ์ ์ฐ๊ตฌ๊ฐ ๋์๋ค๊ณ ํ๋
์์ผ๋ก ์ฐจ๊ทผ์ฐจ๊ทผ ๊ณต๋ถํด๋ด์ผ๊ฒ ์ต๋๋ค!
โ