[DETR] End-to-End Object Detection with Transformers

HyungSeop Lee·2024년 4월 30일
0

Paper Info

  • 제목 : End-to-End Object Detection with Transformers
  • 저자 : Nicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, Sergey Zagoruyko
  • 학회 : European conference on computer vision. Cham: Springer International Publishing, 2020.

Abstract

  • object detection을 직접적인 set prediction problem(?)으로 간주하는 새로운 방법을 제시.

  • 우리 방식은 detection pipeline을 간소화하여,
    비효율적으로 encoding되어 많은 사전 지식이 필요한 NMS 또는 anchor generation과 같은 구성 요소들을 명시적으로 제거했다.

  • 이 새로운 framework인 DEtection TRansformer 또는 DETR의 주요 구성 요소
    unique prediction을 강제하는 set-based global loss와 transformer의 encoder-decoder architecture이다.

    • 학습된 object qeuries의 고정된 작은 set이 주어진 경우,
      DETR은 object 간의 관계와 global image context에 대해 추론하여
      직접적으로 최종 set of prediction을 parallel하게 출력한다. (?)
  • 이 새로운 model은 개념적으로 간단하며 다른 modern detector들과 달리 specialized library가 필요하지도 않다.


1. Introduction

  • (기존 detector들의 문제점, 복잡함)
    object detection의 목표는 관심 대상 object마다
    bounding box와 category label의 set을 예측하는 것임.
    현대의 detector들은 이러한 set prediction task를 간접적으로 다룸.
    이는 large set of proposal, anchors, or window centers에 대한 regression 및 classification 문제를 정의함으로써 이루어짐.
    이들의 성능은 near-duplicate prediction을 축소하는 후처리 단계, anchor set 설계, 그리고 target box를 anchor에 할당하는 heuristic에 의해 크게 영향을 받는다.

  • 이러한 pipeline을 단순화하기 위해,
    우리는 direct set prediction approach를 제안한다.
    이러한 end-to-end 철학은 번역이나 음성 인식과 같은 복잡한 구조화된 예측 작업에서 상당한 발전을 이끌어냈지만,
    object detection에서는 아직까지 이루어지지 않았다.
    이전 시도들은 다른 형태의 사전 지식을 추가하거나, baseline model에 경쟁력을 갖추지 못함.
    이 논문은 이 간극을 줄이고자 함.

  • 우리는 object detection을 direct set prediction problem으로 간주하여 training pipeline을 간소화한다.
    우리는 sequence prediction을 위한 architecture인 transformer에 기반한 encoder-decoder architecture를 채택했다.
    Transformer의 self-attention mechanism은 sequence 내 요소 간의 모든 쌍별 상호작용(pairwise interaction)을 명시적으로 modeling하여,
    duplicate prediction을 제거하는 등 set prediction의 특정 제약 조건에 특히 적합한 architecture를 만든다.

  • 우리의 DETR은 한 번에 모든 object를 예측하며,
    predicted object와 ground-truth object 간의 bipartite matching(이분 매칭)을 수행하는
    set loss function으로 end-to-end training
    된다.
    DETR은 spatial anchors or NMS와 같이 사전 지식이 필요한
    hand-designed components들을 제거함으로써 detection pipeline을 간소화
    함.
    대부분의 기존 detection 방식들과 달리, DETR은 customized layer가 필요하지 않으며,
    표준 CNN과 transformer class를 포함하는 모든 framework에서 쉽게 재현할 수 있다.

  • 이전의 direct set prediction 연구들과 비교하여 DETR의 주요 특징은
    matching loss function(non-autoregression)과 parallel decoding을 가진 transformer의 결합이다.
    반면 이전 연구들은 RNN과의 autoregressive decoding with RNN에 초점이 맞춰져있다.
    우리의 matching loss function은 ground-truth object에 고유하게 할당하고,
    predicted object의 permutation에 invariant하므로 우리는 그것들을 병렬로 결과를 낼 수 있다. (?)

  • 우리는 DETR을 경쟁력 있는 Faster R-CNN과 비교하여 평가했다.
    DETR은 large object에 대해 좋은 성능을 보이지만, small object에 대해서는 성능이 낮다.
    그러나 우리는 미래의 연구가 FPN 개발이 Faster R-CNN에 대해 한 것처럼 이 측면은 개선될 수 있을 것이라 기대함.


2. Related Work

  • 우리의 연구는 여러 domain에 대한 사전 연구들에 기초하여 구성되었다 :
    • set prediction을 위한 bipartite matching losses
    • transformer에 기반한 encoder-decoder architectures
    • parallel decoding
    • object detection methods.

2.1 Set Prediction

  • set prediction :
    object detection model이 각 object에 대하여 set of bounding boxes와 category labels을 prediction하는 task를 말함.

  • set을 직접적으로 예측하기 위한 정석적인 DL model은 존재하지 않음.
    기본적인 set prediction task는 multilabel calssification이다.
    이렇나 작업의 첫번째 어려움은 near-duplicates를 피하는 것이다.
    대부분 현대 detector들은 이를 해결하기 위해 Non-Maximal Suppression과 같은 후처리를 하지만,
    직접적인 set prediction은 후처리가 필요하지 않는다.
    이들은 중복을 피하기 위해 모든 prediction된 요소 간의 상호 작용을 modeling하는 global inference 방법이 필요.

  • 일반적인 접근 방식은 RNN과 같은 auto-regressive sequence model을 사용하는 것이다.
    이러한 model에서 loss function은 prediction의 permutation에 invariant해야 한다.(?)
    보통 이를 위한 해결책은 Hungarian algorithm을 기반으로 한 loss function을 설계하는 것임.
    우리는 bipartite matching loss approach를 따른다.
    그러나 이전 연구들과는 달리, 우리는 autoregressive model에서 벗어나 parallel decoding을 사용하는 transformer를 사용함. (?)

    • bipartite matching이란 ? (참고자료)
      출력 개수를 NN(image에 존재할 수 있는 object의 최대 개수만큼 설정)으로 고정시키고,
      ground-truth와 유사한 prediction은 더 유사하게,
      background prediction은 더욱 background prediction으로 하는 방법.
      ground truth가 2개 있다면, 그 2가지 prediction은 더욱 더 ground truth를 따라가도록 학습됨
      그리고 순서도 상관 없기 때문에 set prediction에 적합.

    • hungarian algorithm이란? (참고자료)
      assignment problem을 해결하는 optimal solution임.
      hungarian algorithm으로 bipartite matching을 수행.

2.2 Transformers and Parallel Decoding

  • transformer는 초기에 auto-regressive model로 사용되었다.
    초기 sequence-to-sequence model을 따라 각각의 output token을 한 번에 생성한다.
    그러나 output length에 비례하여 증가하는 inference cost과 배치하기 어려운 문제로 인해,
    parallel sequence generation이 개발되었다.
    우리는 또한 comutational cost와 set prediction에 필요한 global computation을 수행하는 능력 사이의 적절한 trade-off를 위해 transformer와 parallel decoding을 결합했다.
    • parallel decoding이란? (참고자료)
      원래는 autoregressive decoding 방법으로, 이전의 sequence를 받아서 현 sequence를 생성했음.
      parallel decoder는 non-autoregressive하게 병렬적으로 output을 생성함.

2.3 Object detection

(skip)


3. The DETR model

  • direct set prediction을 위한 두가지 중요한 구성이 있다.
    1. a set prediction loss that forces unique matching between predicted and ground truth boxes
    2. an architecture that predicts(in a single pass) a set of object and models their relation.

3.1 Object detection set prediction loss

  • DETR은 decoder의 single pass를 통해 fixed-size NN개의 prediction set을 출력함.
    NN은 한 image에서 일반적으로 가지는 object의 개수보다 큰 값으로 설정함.
    (예를 들어,
    coco2017 dataset에서 한 image에 object 개수가 가장 많은 image가 11개라고 가정했을 때,
    NN은 11 이상의 값으로 설정해야 함.
    그래야 bipartite matching이 가능하기 때문)

  • 우리의 loss는 ground truth object와 predicted object 간의
    optimal bipartite matching을 만들어 내고,
    object-specific(bounding box) losses를 optimize한다.
    (이분 매칭을 통해 matching된 bbox들끼리만 loss를 구한다는 의미인듯)

    Lmatch(yi,y^σ(i))L_{match}(y_i, \hat{y}_{\sigma(i)})
    ground truth yiy_i와 prediction with index σ(i)\sigma(i) 사이의 pair-wise matching cost이다.
    이 optimal assignment는 Hungarian algorithm에 의해 효율적으로 계산된다.
    matching cost는 (class prediction)과 (predicted와 GT boxes의 similarity)를 둘 다 고려한다.
    ➡️ GT set의 각 ii번째 element는 yi=(ci,bi)y_i = (c_i, b_i)로 볼 수 있다.
    (cic_i는 target class label)
    (bi[0,1]4b_i \in [0, 1]^4는 GT box의 중심 좌표 x,yx,y 와 image size에 대해 상대적인 height,widthheight, width)
    ➡️ prediction set의 index σ(i)\sigma(i) 에 대해서, 우리는
    probability of class를 cic_i = p^σ(i)c(i)\hat{p}_{\sigma(i)}c(i) ,
    the predicted box를 b^σ(i)\hat{b}_{\sigma(i)}
    라고 정의함.

    위 notation으로 우리는 Lmatch(yi,y^σ(i))=1{ci}L_{match}(y_i, \hat{y}_{\sigma(i)}) = -1_{\{c_i \ne \varnothing\}}p^σ(i)c(i)+1{ci}Lbox(bi,b^σ(i))\hat{p}_{\sigma(i)}c(i) + 1_{\{c_i \ne \varnothing\}}L_{box}(b_i, \hat{b}_{\sigma(i)})라고 정의할 수 있다.
    ➡️ first step : Lmatch(yi,y^σ(i))L_{match}(y_i, \hat{y}_{\sigma(i)})를 가장 작도록 만드는 optimal assignment인 σ^\hat{\sigma}를 찾아 bipartite matching을 하는 것임.
    ➡️ second step : matching을 완료했다면,
    이제 matching된 optimal assignment인 σ^\hat{\sigma}의 모든 쌍과 실제 GT에 대한
    loss function을 계산해야 함.

    == class가 유사하도록, bbox가 잘 맞도록 학습을 시켜야 함.
    loss function은 일반적인 object detectors들에서 사용하는 loss와 유사하게 정의됨.
    다음과 같이 (class prediction에 대한 negative log-likelihood)와 (GIoU()LossGIoU() LossL1LossL1 Loss가 선형결합된 LboxL_{box})가
    선형 결합되어 다음의 LHungarianL_{Hungarian} loss를 정의함 : (code와 대조하면 다음과 같음...)
    추가로, self.?은 paper에서 얘기하고 있는 hyper-parameter들임.

3.2 DETR architecture

  • 전체적인 DETR architecture는 매우 간단하고 Figure 2.에 나와있다.
    DETR은 다음의 3가지 주요 구성요소를 갖는다 :

    1. a CNN backbone to extract a compact feature representation
    2. an encoder-decoder transformer
    3. a simple feed forward network(FFN) that makes the final detection prediction.
  • 최근 detector들과는 달리, DETR은 100몇 줄의 code로 구현될 수 있다.
    DETR에 대한 inference code는 PyTorch로 50줄 미만으로 수행될 수 있다.

  • (Multi-head attention recap...)

Backbone

(위 그림에서 설명됨)

Transformer encoder

(위 그림에서 설명됨)

Transformer decoder

  • NN개의 input embedding들은 다른 결과를 만들어 내기 위해 달라야 한다.
    이러한 input embedding들은 object queries라고 부르는 학습된 positional encoding이다.

  • NN개의 object queries들은 decoder에 의해 output embedding으로 변환된다.
    N개의 object queries들은 각각 독립적으로 feed forward network에 의해 box coordinates와 class label로 decode된다.
    결과적으로 NN개의 final prediction이 만들어진다.

  • 이 embedding들에 대해 self- 그리고 encoder-decoder attention을 사용하여,
    model은 각 object들 간의 pair-wise relations을 이용하여
    전체 object를 고려하면서 전체 image를 context로 사용한다.

Prediction feed-forward networks(FFNs)

  • final prediction은 ReLU와 hidden dimension이 dd인 3-layer perceptron과 linear projection layer로 계산된다.
    FFN은 input image에 대한 상대적으로 정규화된 box coordinates, height와 width를 예측하고,
    linear layer는 softmax function을 사용하여 class label을 예측한다.

  • 우리는 보통 image에서 관심 대상 object의 실제 수보다 훨씬 큰 NN개의 bounding box로 고정 크기의 set을 예측한다.
    따라서 추가로 특별한 class label \varnothing는 해당 slot 내에서 object가 detection되지 않았음을 나타내기 위해 사용된다.
    이 class는 standard object detection approach에서 "background" class와 유사한 역할을 함.

Auxiliary decoding losses

  • 우리는 training 동안에 decoder에서 auxiliary losses를 사용하는 것이 유용한 것을 알아냄.
    특히 각 class의 올바른 object 수를 출력하는 데 도움이 되었다.

  • 우리는 각 decoder layer 뒤에 prediction FFNs 및 Hungarian loss를 추가했다.
    모든 prediction FFN은 그들의 parameter를 공유한다.
    다른 decoder layer에서 prediction FFNs로의 input을 정규화하기 위해 추가로 공유된 layer-norm을 사용했다.


4. Experiments

  • 우리는 DETR이 COCO에 대한 quantitative evaluation에서
    Faster R-CNN과 비교했을 때의 경쟁력 있는 결과를 달성한 것을 보여줄 것임.

  • 그리고 나서 우리는 architecture와 loss에 대한 ablation study를 제공할 것임.

  • 마지막으로, DETR이 용도가 많고 extensible model이라는 것을 보여주기 위해,
    우리는 panoptic segmentation에 대한 결과도 보여줄 것임.

Dataset

  • 118k training image와 5k validation images로 이루어져 있는
    COCO 2017 detection과 panoptic segmentation dataset을 experiments에 사용했다.

  • 평균적으로 각 imagedpsms 7개의 instance가 있고,
    training set에 한 image에 최대 63개의 instance가 있다.

  • 특별히 명시하지 않으면,
    multiple threshold에 대한 integral metric인 bbox AP를 AP로서 보고할 것이다.

  • Raster R-CNN과의 비교를 위해 우리는 last training epoch의 validation AP를 보고할 것이고,
    ablations을 위해서 우리는 마지막 10개의 epoch의 validation results에 대한 중앙값(median)을 보고할 것이다.

Technical details

  • AdamW setting the initial transformer's learning rate to 10410^{-4}, the backbone's to 10510^{-5}, and weight decay to 10410^{-4}.
    All transformer weights are initialized with Xavier init, and the backbone is with ImageNet-pretrained ResNet model from TORCHIVISION with frozen batchnorm layers.

  • 우리는 두 개의 다른 backbone을 사용하여 결과를 보고할 것임 :

    • ResNet-50 ➡️ DETR
    • ResNet-101 ➡️ DETR-R101
  • [21]에 따라,
    우리는 backbone의 마지막 stage에 dilation(팽창)을 추가하고
    이 stage의 첫번째 convolution의 stride를 제거함으로써 feature resolution을 증가시켰다.
    이에 대응하는 model은 각각 다음과 같이 부를 것임.

    • DETR-DC5
    • DETR-DC5-R101
      (Dilated C5 stage)

      이 modification은 resolution을 두 배로 높이며, 이로 인해 small object의 성능이 향상되지만,
      encoder의 self-attention에서 16배 더 많은 비용이 발생하여 전체적으로 계산 비용이 2배 증가함.
      이러한 model과 Faster R-CNN의 FLOPs의 전체 비교는 Figure 1.에 있음.
  • 우리는 scale augmentation을 사용하여
    input image의 shortest side를 최소 480 최대 800 pixel이 되도록 resizeing하며,
    longest side는 최대 1333 pixel이 되도록 했다. [50]

  • encoder의 self-attention을 통해 global relationship을 학습하는 데 도움을 주기 위해 training 중에는 random crop augmentation을 사용하여 약 1 AP 향상시켰다.
    구체적으로 training image는 0.5의 확률로 random rectangular patch로 crop하고, 이를 다시 800-1333으로 resize한다.

  • Transformer는 default dropout을 0.1로 train된다.
    inference 시 일부 slot은 empty class를 predict한다.
    AP를 optimize하기 위해서, 우리는 이러한 slot의 prediction을 두 번째로 높은 점수의 class로 override했다.
    이는 빈 slot을 filtering하는 것과 비교하여 AP를 2점 향상시킴.
    다른 hyper parameter들은 A.4에서 볼 수 있다.

  • ablation experiment를 위해서
    우리는 300 epoch training schedule을 사용하며,
    200 epoch 후 learning rate를 10배로 감소시켰다.
    16개의 V100 GPU에서 300 epoch 동안 baseline model을 training시키는 데에 3일이 걸리며,
    GPU당 4개의 image 사용(총 batch size는 64)

  • Faster R-CNN과 비교하기 위해 사용된 더 긴 schedule의 경우 400 epoch 후 learning rate를 감소시킴.
    이 training schedule은 1.5점 AP가 증가됨.

4.1 Comparison with Faster R-CNN

(skip)

4.2 Ablations

Importance of positional encodings

  • 두가지 동류의 positional encoding이 있다 :
    1. spatial positional encodings
    2. output positional encoding(object queries)
  • 우리는 다양한 combinations에 대한 실험(fixed and learned encodings)을 진행했다.

궁금한 부분, 이해가 안되는 부분

  • "우리의 matching loss function은 ground-truth object에 고유하게 할당하고,
    predicted object의 permutation에 invariant하므로 우리는 그것들을 병렬로 결과를 낼 수 있다."
    • matching loss가 뭔데?
    • 예측된 object의 permutation에 invariant(불변)하다는게 뭔데?
    • 병렬로 결과를 낼 수 있다는게 뭔데?
  • NN개의 object queries가 정확히 뭔지 모르겠음. 어떻게 만들어지는지?
profile
model compression

0개의 댓글