2024.12.10 - [Study/SOTA paper] - DETR : Inference code review
DETR : End-to-End Object Detection with Transformers
Carion, Nicolas, et al. "End-to-end object detection with transformers." European conference on computer vision. Cham: Springer International Publishing, 2020.
1. Introduction
object detection target : each object of interet에 대해 bounding box와 category labels prediction
현재 기술들은 proposals, anchors, grid of window centers를 기반으로 regression, classification problem 정의
transformer를 기반으로 한 encoder-decoder architecture 채택
self-attention 메커니즘은 중복 예측 제거와 같은 제약 조건을 해결하기에 적합
DEtection TRansformer(DETR)은 모든 object를 한 번에 예측
bipartite matching을 활용한 loss function으로 end-to-end train
2. Related work
2.1. Set Prediction
Directly하게 set prediction하기 위한 canonical Deep Learning Model이 없다.
set prediction을 하기 위해 multilabel classification이 있다. 이는 near-duplicates 문제를 해결하지 못했다.
이 문제를 해결하기 위해 non-maximal suppression(NMS)와 같은 방법론이 사용되었고, 이는 post processing 작업이 필수적이다.
하지만, 직접적인 set prediction 방식은 post processing을 요구하지않고 global inference 방식이 필요하다. 이를 위해 auto-regressive sequence model과 같은 RNN 계열 model이 사용됐다.
NMS란?
object에 대해 여러 score의 bounding box가 생성된다. 이때, 최적의 bbox를 제외하고 나머지 bbox를 제거하는 방법
그리고 set prediction이기에 예측 순서에 따라 loss function이 일정해야된다.
본 논문에서는 Hungarian algorithm 기반으로 loss function 구성하였다.
그에 따라서 ground truth와 prediction에 대한 Partite matching 가능하다.
그러나 우리는 이전 연구와 달리, RNN 사용하지 않고 parallel decoing 지원하는 Transformer를 사용한다.
2.2. Transformers and Parallel Decoding
attention은 input sequence 전체의 정보를 집계한다.
attention기반 model의 이점은 global computations과 perfect memory 제공. 이는 긴 sequence 작업에서 RNN보다 더 적합하다.
결론적으로, parallel decoding과 Transformer를 결합하여 set prediction에 필요한 global computations와 cost of compute 간의 적절한 balance를 제공한다.
2.3. Object dection
현대 object detection방법은 초기 추정값을 기준으로 예측을 수행한다.
Two-stage detectors는 proposals 기준으로 box를 예측하고
single-stage방법들은 anchors 또는 grid에 위치한 가능한 객체 중심을 기준으로 예측한다.
본 모델은 이와 같은 수작업으로 설계된 과정을 제거하고, 절대적 box prediction을 통해 단순화한다.
Proposal이란?
Image를 분할하여 예측함으로써 여러 label을 예측하는 방식
anchors란?
사전 정의된 Bbox로써 이미지에 수백, 수천개의 anchor box를 생성하고 이를 통해 anchor안에 object가 포함될 가능성을 계산, 따라서 이에 있어서 NMS 문제가 발생해서 post processing 필요
Set-based loss
몇 detctors는 bipartite matching loss를 사용하기는 한다.
그러나, 해당들은 convolutional or fully-connected layers로만 modeling
수작업으로 NMS post-processing으로 성능을 높여준다.
즉, Set-based loss를 사용함에도 여전히 manually하게 처리해야 성능을 높일 수 있다.
Recurrent detectors
본 연구와 가장 유사한 접근 방식또한 biparitite matching loss와 CNN activation을 기반으로 encoder-decoder architecture를 사용하여 직접적으로 bbox set을 생성한다.
하지만, 이러한 접근 방식들은 소규모의 데이터셋에서만 평가되며, 기준과는 비교 되지않았다.
또한, RNN을 기반으로하여 Transformer와는 다르다.
3. The DETR model
(1) predicted와 ground truth boxes간의 unique mathcing하는 set prediction loss
(2) single pass로 object set prediction, 그들의 relation model
3.1. Object detection set prediction loss
decoder를 통해 single pass에서 고정 크기 N개의 prediction set을 추론한다.
여기서 N은 image에 포함된 객체보다 훨씬 큰 값
어려운 점 (class,position,size)를 ground truth와 비교하여 점수를 매기는 것
본 논문에서 loss는 predicted와 ground truth간의 최적의 nipartite matching을 생성한 후, bounding box loss를 최적화한다.
N이 image 내 객체수보다 크다고 가정, 실제 객체 집합 y를 N 크기의 집합으로 확장 및 공집합으로 채운다.
L은 pair-wise matching cost이기에 predected와 ground truth가 잘 matching될 수록 값이 낮다.
optimal assignment는 Hungarian Algorithm을 사용하여 효율적으로 compute
matching cost
class, bbox 잘맞추면 loss가 줄어드는 형태
Hungarian Loss
Box Loss
여기서 lambda는 hyperparameter,
초기 추정값 없이 bbox를 directly prediction
L1 loss와 Generalizaed IoU loss를 선형 결합해서 정의했다.
3.2. DETR Architecture
backbone : CNN - input image에 대해 compact feature representation하는 featrue extraction
transformer Encoder-Decoder : feature map에서 object간의 global context learning
FFN : 최종 class 및 box에 대한 예측 생성
backbone
1. 일반적으로 feature map을 2048*(H0/32)*(W0/32)로 변환
Encoder
2. feature map을 1x1 convolution을 통해 weight-wised sum하여 channel dim을 d로 줄이고, d*H*W로 변환
3. 차원 1D로 변경, d*HW차원의 feature map으로 변환
4. encoder는 multi-head self-attention과 FFN으로 구성된 표준 구조 (attention layer input에 고정된 positional encoding을 추가)
Decoder
5. d 크기의 N개의 embeding input을 받아서, multi-head self-attention 및 encoder-decoder attention을 통해 변환
6. N개의 객체를 병렬로 decoding
7. Decoder Input은 학습된 위치 임베딩(object queries)이며, 각 attention layer input에 추가
8. Decoder Output은 FFN에 의해 class lable, bbox 좌표 변환
FFN
9. 3개의 MLP로 구성, activation function ReLU, hidden dim d 사용
10. 최종 출력으로써 bbox 중심 좌표 및 크기(정규화된 값), calss lable(softmax 사용)
이 때, class가 공집합이면 해당 객체가 감지되지 않음
Auxiliary decoding losses
각 decoder layer 이후에 FFN과 Hungarian loss 추가, 모든 FFN은 매게변수 공유
Decoder Layer에서 FFN의 입력값을 정규화하기위해 sharing layer norm 사용
4. Experiments
dataset COCO사용, 약 12만개의 train data, 5천개의 validation data
평균적으로 이미지 존재 instance 7개, 최대 63개
backbone Resnet
optimizer : AdamW
learning rate : transformer 10^(-4), backbone 10^(-5)
weight decay : 10^(-4)
결론적으로, object에 대해 post processing없이 single task라는 매력
하지만 small object에 대해서는 상대적으로 안좋은 탐지 성능을 보임
요즘, SOTA를 보면 DETR기반이 많음.
+
backbone에서 나온 feature map을 weight-wised sum하여 channel을 d로 줄여서,
d*H*W로 변환하고 1D차원으로 d*HW로 변환해도 되는 이유는
transformer self-attention은 입력 시퀀스의 각 token이 다른 모든 token과의 관계를 학습할 수 있다.
따라서, 1D차원으로 줄여도 된다.
HW 크기의 token들을 Self-Attention 수행하기에 학습 시간이 오래 걸릴 것이다.
실제 논문에서 coco dataset train에서 500epoch 이상이 필요하다고 말한다.
image size에 따라 multi-scale처리하지않고, 결론적으로 ResNet을 통해 하나의 Feature map을 추출하고 Transformer 학습하는 방식이므로, 다양한 scale image에 대해 정확도가 떨어질 것 이다.
'Study > computer vision' 카테고리의 다른 글
RT-DETR : DETRs Beat YOLOs on Real-time Object Detection (0) | 2024.12.11 |
---|---|
DETR : Inference code review (0) | 2024.12.10 |
[ResNet] Skip connection 제대로 이해 (1) | 2024.12.07 |
pose estimation occlusion problem related works (1) | 2024.11.29 |
[VGGNet] Very Deep Convolutional Networks for Large-Scale Image Recognition (0) | 2024.08.12 |