발표자료 : https://docs.google.com/presentation/d/1KFEG02jlgbZISuvFbilvwaP8PbdQCzAA/edit?usp=sharing&ouid=116507288704586191771&rtpof=true&sd=true

발표영상 : Deformable DETR: Deformable Transformers for End-to-End Object Detection 리뷰

논문링크 : Deformable DETR: Deformable Transformers for End-to-End Object Detection

Implementation : https://github.com/fundamentalvision/Deformable-DETR

오늘 소개드릴 논문은 Deformable DETR: Deformable Transfomers for End-to-End Object Detection입니다. ICLR 2021 accepted paper입니다.



1. Backgorund

Deformable DETR에 대해 소개해드리기에 앞서, 먼저 선행 연구에 대해 소개하도록 하겠습니다.

1-1. Transformer

Transformer는 Input contents와 Target contents간의 관계를 파악하여 attention weight를 계산하는 아키텍쳐이며, 기존 RNN 기반의 Encoder, Decoder 구조에서 RNN 없이 Attnetion만으로 task를 수행합니다. 원래는 NLP task만을 위해 개발되었지만, 최근에는 vision 분야에서 더 활발하게 사용되고 있는 모델입니다. Encoder는 source word(input sentence)를 input으로 받고, Decoder는 target word(output sentence)를 input으로 받아 각각 MultiHead Attention을 수행합니다. 이 때, 각 Head는 서로 다른 sample point로부터 온 source들에 대해 attention task를 수행합니다.

Multi Head Attention은 위와 같이 계산될 수 있습니다. 각 key contents(source word)는 각각 학습 가능한 weight($W^\prime_m$)를 가지며, 해당 weight는 attention weight($A_{mqk}$)와 곱해지게 됩니다. 해당 task는 모든 key contents에 대해 동일하게 수행되며, 이를 모두 더해 query weight($W_m$)와 곱함으로써 특정 Head $m$에 대한 Multi-Head Attention을 계산하게 됩니다.

더 자세한 내용은 논문을 참고해주시기 바랍니다.

Attention Is All You Need : https://arxiv.org/pdf/1706.03762.pdf



1-2. DETR

paper link : End-to-End Object Detection with Transformers

DETR은 위에서 소개한 Transformer를 Object Detection task에 최초로 적용시킨 모델입니다. 이분 매칭 기반의 새로운 Detection 구조를 가지며, 기존 Detection task를 direct set-prediction 문제로 접근하여, fully end-to-end detection을 수행합니다. 즉, DETR 이전의 모델들이 해주었던 많은 hand-crafted components(RPN, NMS …)들이 모두 제거되었다고 할 수 있겠습니다. DETR은 Deformable DETR과 기본적인 흐름이 매우 유사하기 때문에 자세히 짚고 넘어가도록 하겠습니다.

DETR의 전체적인 흐름은 다음과 같습니다.

우선, input image를 CNN backbone Network(Resnet50)에 태워 Feature map을 얻습니다. 이렇게 얻어진 feature map을 transformer의 encoder-decoder에 넣어 object query를 얻은 뒤, 최종적으로 GT box와 Bipartite Matching을 진행해주게 됩니다.

1-2-1) Encoder & Decoder

다음은 DETR의 Encoder와 Decoder를 더 자세히 나타낸 figure입니다.

backbone network에서 얻어진 Feature map은 우선 DETR의 Encoder로 들어가게 됩니다. input으로 들어간 Feature map은 self attention을 수행하게 되는데, 해당 과정에서 image의 pixel간 관계를 학습하게 됩니다. 이후 FFN을 통과하여 최종적으로 attention weight를 출력하게 됩니다.

Decoder는 Object query를 input으로 받습니다. 여기서 object query는 오브젝트와 이분 매칭을 진행하는 slot들이라고 이해하시면 될 것 같습니다. 다시 말해, 하나의 object query는 하나의 object에 대해(일대일 매칭) Bipartite Matching을 해주게 되며, 이 과정에서 no object와 실제 object로 최종 분류됩니다. 자세한 매칭 알고리즘에 대해서는 뒤에서 더 자세히 설명하도록 하겠습니다. 해당 object query는 초기에 random한 값으로 initialization되며, self attetion과 cross attention을 수행하게 됩니다. self attention을 통해 object query는 최적의 매칭(각 object query가 어떤 object에 매칭되어야 할지)에 대해 학습하게 되며, encoder에서 계산된 attention weight와 cross attention을 수행하게 되는데, 이 과정에서 실제 object의 위치에 대해 학습하게 됩니다.

여기서 초기 layer의 self attention은 object query가 random하게 initialize 되었기 때문에 사실상 의미가 없다고 합니다. 그러나 저자는 코드의 간결성을 위해 그냥 남겨두었다고 합니다.

self attention과 cross attention을 마친 object query는 최종적으로 GT box에 대한 class와 bbox 좌표를 predict합니다.


1-2-2) Set prediction

앞서 decoder에서 object query가 예측한 임베딩 값을 바탕으로 실제 GT box와 Set prediction을 수행하게 됩니다. 해당 task는 DETR의 key concept으로, 조금 더 자세히 살펴보도록 하겠습니다.

1-2-2-1) hungarian algorithm

object query와 GT box간의 매칭을 위해서 hungarian algorithm이 사용됩니다. hungarian algorithm이란, 특정한 score를 기준으로 각 query들이 최적의 매칭을 할 수 있게 해주는 알고리즘입니다. DETR의 경우 hungarian algorithm의 score로 match loss를 사용합니다.

1-2-2-2) class loss

match loss는 다시 2개의 항으로 나누어지게 되는데, 첫 번째 항의 $\hat{p}_{\sigma (i)}(c_i)$는 class에 prediction에 대한 cost를 의미합니다. 해당 loss는 object query가 실제 class를 얼마나 잘 예측하고 있는지에 대해 확률값으로 표현됩니다.

1-2-2-3) box loss

bbox의 loss를 계산하는 방법에는 대표적으로 IoU, GIoU등이 있습니다. IoU는 두 bbox A, B에 대해서, A와 B의 합집합 대비 교집합이 차지하는 비율을 수치로 나타낸 loss입니다. 그러나 IoU는 A와 B의 교집합이 존재하지 않을 경우 항상 0이 되기 때문에 box loss로 사용하기에 한계가 있습니다. 따라서 DETR은 GIoU를 box loss로 사용합니다. GIoU는 bbox A, B를 모두 포함하는 최소 크기의 bbox C를 도입함으로써 기존 IoU의 문제를 해결합니다. 위에 나와있는 표는, loss에 대한 ablation table입니다. l1 loss는 AP에 큰 영향을 주지 못하지만, GIoU는 AP에 큰 영향을 주고 있는 모습을 확인할 수 있습니다.

1-2-2-4) bipartite matching

다시 bipartite matching에 대해 살펴보도록 하겠습니다. 이렇게 계산된 loss를 바탕으로 hungarian algorithm을 통해 loss가 최소가 되는 최적의 matching을 찾게 됩니다. 이 과정에서 각 object query들은 각각의 GT box 또는 no object와 일대일 매칭되며, 잘못 예측된 query의 경우 수정됩니다.


1-2-3) Problem

앞서 소개드린 DETR에는 다음과 같은 한계가 존재합니다.

  1. Slow convergence

    Attention weight는, Key의 수가 많아질 수록 ${1} \over {N_k}$로 uniform하게 initialaze됩니다. 일반적으로 obj detection task에서는 key가 image의 pixel이 되므로, key의 수는 매우 커지게 되고 이로 인해 attention weight는 uniform하게 initialize됩니다. 따라서 attention weight가 특정한 object에 focusing하기까지 시간이 매우 오래걸리게 됩니다.

  2. Memory Complexity

    위 수식(좌항)은 DETR의 시간복잡도를 수식으로 표현한 것입니다. 일반적으로 image task에서 pixel(query, key contents)의 수는 channel의 수보다 훨씬 크기 때문에 시간 복잡도는 3번째 항에 의해 지배되어 $O(N_qN_kC)$로 표현됩니다. 즉, Feature map의 scale이 증가할 수록 memory complexity는 quadratic하게 증가합니다. 이로 인해 DETR은 high-resolution feature map을 사용할 수 없다는 한계가 존재합니다.

  3. Small obj.에 대한 preformance 저하

    위에서 언급했듯이 DETR은 Memory 문제로 인해 low resolution feature map만을 사용하게 됩니다. 따라서 small object detection에 대해서는 좋지 않은 performance를 보여줍니다.



2. Deformable DETR

이러한 문제를 해결하기 위해 저자는 Deformable DETR이라는 새로운 방법론을 제시합니다. Deformable DETR에는 다음과 같은 2개의 key concept가 존재합니다.

  1. Deformable Attention

    DETR의 memory complexity 문제를 해결하기 위해, Deformable DETR은 attention 시 모든 pixel을 사용하지 않습니다. 대신 특정 layer를 통해 예측된 reference point 근처의 sampling point들에 대해서만 attention을 수행하게 됩니다.

  2. Multi-scale Feature map

    Deformable Attention을 통해 메모리 문제를 해결함으로써 feature map에 대한 resolution 제한을 완화할 수 있었습니다. 이를 바탕으로 다양한 Scale의 Feature map을 사용함으로써 작은 obj에 대한 performance를 향상시킵니다.

2-1. Architecture

Deformable DETR의 경우, DETR과 전체적인 task는 크게 다르지 않습니다. task는 다음과 같이 크게 3가지로 나뉩니다.

  1. Backbone Network

    DETR과 유사하게 CNN backbone Network에 input image를 태워 Feature map을 뽑아냅니다. 이 때, DETR과 달리 single-scale이 아닌 Multi-scale feature map을 사용하게 됩니다.

  2. Encoder

    backbone에서 뽑아낸 multi-scale feature map을 바탕으로 object가 있음직한 reference point를 예측합니다. 예측된 reference point 근처에서 sampling point를 추출하게 되고, 이 sampling point끼리의 attention weight를 계산합니다(self attention). 계산된 attention weight는 reference point를 개선하는 데 사용되며, 다음 layer에서는 개선된 reference point 근처에서 다시 sampling point들을 추출합니다. 이후에는 다시 위 task를 반복하게 됩니다.

  3. Decoder

    DETR과 동일한 task를 수행합니다. object query의 self attention을 통해 최적의 매칭을 찾고, encoder와 cross attention을 통해 reference point를 수정합니다.



2-2. Deformable Attention

위 figure는 Deformable Attention 과정에 대해 조금 더 자세히 나타낸 것 입니다. input으로 backbone에서 뽑아낸 feature map을 받아, reference point에 대해 sampling offset을 계산합니다. 이 때, sampling offset은 학습 가능하며 해당 offset을 바탕으로 sampling point들이 추출됩니다. 계산된 offset들은 key contents의 weight와 함께 bilinear interpolation(Dai et al. 2017)을 적용해줍니다. 여기까지의 과정은 위 figure에서 빨간색 부분에 해당합니다.

이후 query feature에 대해 attention weight를 계산해주게 되며(파란색 부분), bilinear interpolation output과 aggregation($A_{mqk} \cdot W^ \prime _m x ( p_q+ \Delta p ) $) 해줌으로써 head m에 대한 attention weight를 계산하게 됩니다. 이 task를 각 head에 대해 동일하게 적용한 뒤 Linear layer에 태워줌으로써 최종 output을 계산합니다(노란색 부분).



2-3. Multi-scale Deformable Attention

실제 Deformable DETR은 multi-scale deformable attention을 사용합니다. input으로 multi scale의 feature map을 사용한다는 점을 제외하면 single-scale의 task와 동일합니다. 위 figure는 coco val image에 대해 직접 시각화 해본 multi-scale feature map입니다. 다양한 resolution의 feature map이 사용되는 것을 확인할 수 있습니다.

여기서 주목할 점은 각각 feature map의 resolution이 다르기 때문에 value들은 normalize된다는 것입니다. 따라서 multi-scale deformable attention의 계산식에는 value를 de-normalize 해주는 $\phi_l()$ 함수가 사용됩니다. 나머지 task는 single-scale과 동일합니다.



2-4. Encoder

Deformable DETR의 encoder가 DETR과 다른 점은, attention weight를 계산하는 데 모든 pixel을 사용하지 않는다는 것 입니다. DETR에서는 모든 pixel을 사용하여 attention weight를 계산하였기 때문에 memory complexity 문제가 발생하였고, attention weight가 uniform 하게 initialize되어 수렴해에 도달하기까지 매우 많은 시간이 필요했습니다. 그러나 Deformable DETR의 deformable attention은 특정 reference point 근처의 sampling point에 대해서만 attention weight를 계산하게 됩니다. 아래 figure는 직접 시각화해본 sampling point와 attention weight입니다.

reference point는 layer를 거듭할 수록 더욱 정교하게 수정되며, 이를 바탕으로 최적의 sampling offset을 학습하여 더 효율적인 sampling point를 추출하는 모습을 확인할 수 있습니다. 마지막 Layer에 가까워 질수록, model은 object의 모든 부분을 보는 게 아니라 물체의 가장자리 부분에 초점을 맞춰서 보도록 학습된다는 것을 알 수 있었습니다.



2-5. Decoder

Decoder의 task는 DETR과 거의 동일하게 진행됩니다.

random한 값으로 initialize된 object query에 대해 self-attention을 수행함으로써 최적의 매칭을 찾습니다. 이후에 Encoder에서 계산한 attention weight와 cross-attention을 수행하며 이를 바탕으로 reference point를 수정합니다. 그리고 다음 layer에서는 다시 수정된 reference point 근처에서 sampling point를 추출하여 attention weight를 계산합니다.



3. Variants for Deformable DETR

Deformable DETR은 앞서 설명드린 Deformable attention을 도입하여 momory의 효율성을 증대시켰습니다. 저자는 이러한 메모리 효율로 인해 deformable DETR의 다양한 변형을 시도해 볼 수 있다고 하였으며, 그 구체적인 예시로 다음과 같은 2가지 trick을 제시하였습니다.

  • Iterative Bounding Box Refinement

    Bounding Box가 Decoder Layer를 거칠 때, box의 좌표를 조금씩 수정함으로써 정확도를 향상시킵니다.

  • Two-stage Deformable DETR

    One-stage Deformablle DETR에서, object query는 초기에 random한 값으로 initialize 되었습니다. 그러나 two-stage Deformable DETR에서는, encoder-only의 Deformalbe DETR을 먼저 학습 시켜 region proposal을 얻습니다. 이후 이 값을 decoder의 input으로 넣어 inference를 진행함으로써 정확도를 더 높힙니다.



4. Experiment

4-1. With DETR

Deformable DETR은 기존 DETR대비 훨씬 적은 Epoch으로 더 좋은 performance를 보여주는 모습을 확인할 수 있었습니다. DETR의 경우 AP 43.6을 달성하는 데 총 500epoch(7000시간)이 걸린데 반해, Deformable DETR은 AP 43.8을 달성하는 데 고작 50epoch(325시간)밖에 걸리지 않는 모습을 확인할 수 있습니다.



4-2. Ablation study of FPNs

다음은 FPN에 대해서 Ablation study를 진행한 테이블입니다.

MS attention에 대해 FPN 추가하여도 큰 성능 개선이 없는 것을 확인할 수 있습니다. 이는, 여러 스케일의 feature map에 대한 attention 연산을 통해 모델이 여러 스케일의 이미지 정보를 충분히 반영하였음을 반증합니다.



5. Conclusion

  • DETR은 기존 object detection 문제를 set prediction으로 새롭게 재정의하여 hand-craft components를 완전히 없앤 fully end-to-end detector입니다.

  • 그러나 DETR은 모든 image pixel에 대해 attention 연산을 수행하기 때문에 수렴해에 도달하기 까지 시간이 오래걸리며, low-resolution feature map을 사용하기 때문에 작은 물체에 대한 performance가 떨어집니다.

  • Deformable DETR은 이러한 문제를 해결하기 위해 Multi-scale Deformable Attention을 도입합니다.

  • 확보된 메모리 효율성 덕분에 추가적으로 Iterative Bounding Box Refinement, Two-stage Deformable DETR와 같은 trick을 도입할 수 있게되어 performance를 더 끌어올렸습니다.

  • 결과적으로 Deformable DETR은 기존 DETR의 문제를 해결함과 동시에 더 빠르게, 더 좋은 성능을 낼 수 있게 되었습니다.

Details

다음은 논문의 더 자세한 내용을 담은 해석본 Markdown입니다. 아래 내용을 마크다운 에디터에 넣어서 사용하시면 조금 더 자세한 내용을 확인하실 수 있습니다.



# 0. Abstract DETR은 obj detection에서 좋은 performance를 보여줌과 동시에 많은 hand-desinged componets를 제거함으로써 완전한 end-to-end의 학습을 할 수 있게 되었습니다. 그러나, Trnasformer attention module의 한계로 인해 DETR에는 다음과 같은 2가지 문제가 존재합니다. 1. **Slow convergence** 2. **Limited feature spatial resolution** 본 저자는 이러한 문제를 해결하기 위해 Deformable DETR을 제안합니다. Deformable DETR의 attention module은 reference point를 지정하여, 해당 point 근처에서만 small key sampling을 진행합니다. 이를 통해 기존 DETR의 문제를 상당부분 개선하였으며, small object에 대한 detection performance도 많이 향상시켰다고 합니다.

# 1. Introduction ## 1-1. DETR ### 1-1-1) About DETR DETR 이전의 obj detection 모델은 NMS와 같은 hand-crafted components가 상당부분 존재했습니다. 그러나 2020년 등장한 DETR은, CNN과 Transformer의 encoder-decoder를 결합한 간단한 아키텍쳐를 도입하여 이러한 hand-crafted components를 모두 제거하였습니다. performance는 이전 모델들과 유사하게 유지하면서, Transformer의 강력한 relation modeling 능력을 통해 obj detection 분야에서 완전한 end-to-end를 구현한 최초의 모델이라고 할 수 있겠습니다. ### 1-1-2) Problem of DETR DETR은 Abstract에서도 잠깐 언급했듯이 2가지의 문제점을 가지고 있습니다.
1. **slow cpnvergence** 우선, DETR은 수렴해에 도달하기까지의 시간이 매우 오래걸립니다. DETR은 COCO dataset에 대해 converge까지 약 500 에폭정도가 필요한데, 이는 Faseter R-CNN보다 10~20배 더 느린 수치입니다. 2. **small obj** DETR은 작은 오브젝트에 대해 매우 낮은 performance를 보여줍니다. DETR 이전의 모델들은 주로 output과 가까운 고해상도 feature map에서 small obj를 detect합니다. 하지만, DETR은 이러한 복잡한 feature map을 수용할 수 있는 능력이 없습니다. 정리해보자면, DETR의 attention module은 attention weight와 feature map의 모든 pixel을 cast하여 학습을 진행합니다. 따라서 긴 학습시간은 필수가결적이라고 할 수 있겠습니다. 또한, Transformer의 encoder는 모든 pixel에 대해 quadratic computation을 진행하게 되는데, 이는 매우 많은 연산량과 메모리를 필요로 합니다. 따라서 high-resolution feature map을 계산하는 데 한계가 존재하며, 이는 자연스럽게 small obj에 대한 performance 저하로 이어지게 됩니다. ## 1-2. Deformable DETR

본 저자는 Deformable Convolution(Dai et al., 2017)이라는 방법론을 도입함으로써 DETR의 느린 convergence issue와 high complexity issue를 해결합니다. 즉, Deformable DETR은 Transformer의 관계 모델링 능력과 deformable convolution의 soarse한 공간 샘플링 능력의 결합이라고 할 수 있겠으며, 이를 `deformable attention module`이라 명명하였습니다. Fig.1에서 확인할 수 있듯이 deformable attention module은 모든 픽셀을 attention weight와 match하지 않고, 특정 sampling location 주변의 pixel들만 사용합니다. 이를 통해 FPN의 도움 없이도 multi scale feature를 확장할 수 있었다고 합니다. ### 1-2-1) two-stage Deformable DETR 본 저자는 Deformable DETR의 빠른 convergence와 memory efficiency로 인해, `two-stage Deformable DETR`이라는 variants model을 시도해 볼 수 있었다고 말하고 있습니다. two-stage Deformable DETR은 첫 번쨰 stage에서 region proposal을 생성해내고, 이를 2번째 스테이지인 decoder에 넘겨줘서 iterative하게 bounding box refinement를 해주는 메커니즘을 가지고 있습니다. 즉, decoder에서는 region proposal을 받아 지속적으로 bounding box를 수정하면서 detection performance를 향상시킬 수 있었다고 합니다. ### 1-2-2) Experiments Deformable DETR은 기존 DETR보다 10배 더 적은 에폭을 사용하면서 더 좋은 performance를(특히 작은 물체에 대해서) 기록했다고 합니다. two-stage Deformable DETR을 사용하면 성능을 조금 더 향상시킬 수 있으며, 아래는 공식 깃헙 링크입니다. > links : https://github.com/fundamentalvision/Deformable-DETR

# 3. Revisiting Transformers and DETR ## 3-1. Multi-Head Attention in Transformers ### 3-1-1) Intro Transformer는 기계번역 분야에서 주로 사용되던 attention기반의 네트워크 아키텍쳐입니다. transformer는 input으로 query elements(e.g. output sentence의 target word)와 key elements(e.g. input sentence의 source word)를 받으며, query와 key element의 유사도를 측정하여 attention weight를 계산합니다. `multi-haed attention module`은 계산된 attention weight를 바탕으로 key contents를 adaptive하게 계산합니다. 이 때 모델은 여러개의 attention head를 가지며, 각각의 attention head는 서로 다른 subspace나 position으로부터 온 contents들을 인식합니다. 이러한 attention head들은 선형 결합을 통해 계산되며, 각각 학습 가능한 가중치를 가집니다. 계산식은 다음과 같이 정의될 수 있습니다. $$ MultiHeadAttn(z_q, x) = \sum^M_{m=1}{W_m[\sum_{k \in \Omega_k}A_{mqk} \cdot W^{\prime}_mx_k]} $$ - **Annotation** - $q \in \Omega_q$ query element입니다. representation feature로 $z \in \mathbb{R}^C$를 가집니다. - $k \in \Omega_k$ key element입니다. representation feature로 $x_k \in \mathbb{R}^C$를 가집니다. - $\Omega_q$ & $\Omega_k$ 각각 q와 k의 전체 집합을 의미합니다. - $m$ attention head의 index를 의미합니다. - $Amqk$, $W_m$, $W^\prime_m$ 각각 attention weight, query weight, key weight를 의미합니다. 모든 key contents의 feature에 대해서 Attention weight와 key weight를 곱한 뒤 이를 전부 더하여 query weight와 곱하면, m번째 attention head에서의 feature가 계산됩니다. 또한, 위 수식에는 나와있지 않지만 query와 key elements의 feature간 공간 정보를 구별해주기 위해 position embedding을 사용합니다. 제가 attention 관련 논문을 읽어보지 않아서 key weight, query weight라는 표현이 맞는지는 모르겠는데, 각각 key와 query에 대해 고유하게 사용되는 weight이기 때문에 상기와 같이 표현하였다는 점 참고해주시면 감사하겠습니다. ### 3-1-2) Issue Transformer에는 다음과 같은 2가지 issue가 존재합니다. - **long training schedules** key의 개수($N_k$)가 매우 커지는 경우 attention weight는 $\frac{1}{N_k}$에 점점 수렴하게 되는데, 이렇게 되면 각 gradient의 차이가 모호해지기 때문에 각각 key들을 특정하기 위해 매우 긴 training time이 필요합니다. obj detection에 transformer를 사용하게 되면, key elements는 image의 pixel이 되며, 일반적으로 이미지의 픽셀 개수는 매우 많습니다 따라서 학습 시간이 길어지는 문제가 발생합니다. - **computational and memory complexity** multi-head attention에서 시간 복잡도는 $O(N_qC^2 + N_kC^2 + N_qN_kC^2)$으로 표현될 수 있습니다. 이미지의 경우 dimension(C)에 비해 pixel 수($N_k$ = $N_q$)가 훨씬 많기 때문에 시간 복잡도는 $N_qN_kC^2$에 의해 지배됩니다. 따라서 feature map의 size가 증가함에 따라 복잡도는 quadratic하게 증가하며, 이는 계산 및 메모리 복잡도를 증가시킵니다.

# 4. Method ## 4-1. Deformable Transformers for End-to-End Object Detection ### 4-1-1) Deformable Attention Module

이전 연구에서 transformer를 image에 적용하고자 하는 시도는, transformer가 image feature map의 모든 pixel을 고려하기 때문에 메모리 및 학습 속도 이슈를 발생시켰습니다. 본 저자는 이러한 문제를 다루기 위해 `deformable attention module`을 도입합니다. deformable attention module은 reference point 근처의 소규모 sampling point만을 사용하여 이러한 문제점들을 해결하였습니다. 아래는 feature map $x \in \mathbb{R}^{C \times H \times W}$, query element $q$와 content feature $z_q$, reference point $p_q$에 대한 DeformAttn 계산식입니다. $$ DeformAttn(z_q , {p}_q , x) =\sum^{M}_{m=1}W_m[ \sum^K_{k=1} A_{mlqk} \cdot W^{\prime}_mx ( p_q + ∆p_{mqk}) ] $$ annotation에 대해서 먼저 간단히 소개해 드리겠습니다. 먼저, m과 k는 각각 attention head의 idex와 sampled key의 index를 의미합니다. $\Delta p_{mqk}$와 $A_{mqk}$는 m번째 head 및 k 번째 sampling point에서 추출된 sampling offset과 attention weight를 의미합니다. attention weight는 0~1사이 값을 가지며, 모든 sampling point에서의 합이 1이 되도록 normalize되어 있습니다. sampling offset은 범위 제한이 없으며, $( p_q + ∆p_{mqk})$가 분수 값을 갖기 때문에 bilinear interpolation(Dai et al. 2017)이라는 계산 기법을 사용한다고 합니다($x( p_q + ∆p_{mqk})$). $\Delta p_{mqk}$와 $A_{mqk}$는 둘 다 $z_q$에 대한 linear projection으로 얻어집니다. 실제 구현 과정에서, linear projection operator는 3MK의 채널을 가지며 첫 2MK에서는 $\Delta p_{mqk}$를, 나머지 MK에서는 sofrmax를 통해 $A_{mqk}$를 계산합니다. ### 4-1-2) Multi-scale Deformable Attention Module 대부분 최신 object detection framework들을 multi-scale feature map을 사용하는 경향을 보이고 있으며, 저자가 제안하는 Deformable attention module도 자연스럽게 multi-scale feature map으로 확장될 수 있다고 소개하고 있습니다. multi-scale deformable attention module은 앞서 소개한 single-scale과 유사한 계산식을 갖습니다. $$ MSDeformAttn(z_q , \hat{p}_q , {x^l}^L_{l=1}) =\sum^{M}_{m=1}W_m[ \sum^L_{l=1} \sum^K_{k=1} A_{mlqk} \cdot W^{\prime}_mx^l ( φ_l (p̂_q) + ∆p_{mlqk}) ] $$ 복잡해보이는 수식이지만, 4-1-1의 single-scale과 유사한 구조를 가지고 있습니다. 우선, 몇몇 annotation에 대해 설명드리겠습니다. 우선, reference points($\hat p_q$)의 경우 top-left를 (0,0) bottom-right를 (1,1)로 하여 normalized 되었으며, $φl (p̂q )$는 이를 denormalize하는 function입니다. nulti-scale feature map으로부터 LK개의 sample point를 추출한다는 것을 제외하면 기존 single-feature map과 계산식은 동일합니다. ### 4-1-3) Deformable Transformer Encoder 다음은 Multi-sacle deformable attention의 encoder에서의 적용에 대한 설명입니다. Encoder는 multi-scale deformable attention module을 사용한다는 점을 제외하면 기존 DETR의 encoder와 동일합니다. Encoder에서는 ResNet backbone 모델의 feature map을 input으로 받아 multi-scale feature map을 추출합니다. 이 때 input으로 들어가는 feature map은 input image의 $2^{-5}$~$2^{-3}$(본문에서는 $C_3$~$C_5$로 표현)의 resolution을 갖는 feature map입니다. 또한, encoder에서는 FPN을 사용하지 않고도 좋은 performance를 유지할 수 있었다고 합니다.
encoder의 input과 output은 동일한 resolution을 갖는 multi-scale feature map이며, key/query element는 multi-scale feature map으로부터 추출된 pixel 값들 입니다. 이 때, 각 query pixel에서 reference point는 자기 자신입니다. 또한 각 query pixel이 어떤 feature level에 속하는지 구별하기 위해 positional embedding 외에도 $e_l$이라는 sacle-level embedding을 추가하였으며, fixed encoding과는 다르게 학습 가능하다는 특징이 있습니다.

댓글남기기