End-to-End Object Detection with Transformers
End-to-End Object Detection with Transformers
- Link : https://arxiv.org/abs/2005.12872
๐ก ์ด ๋ ผ๋ฌธ์ ์ฅ์ ์?
- ๊ธฐ์กด์ ๊ฐ์ฒด ํ์ง(Object detection) ๊ธฐ์ ๊ณผ ๋น๊ตํ์ ๋ ๋งค์ฐ ๊ฐ๋จํ๋ฉฐ ๋ํ ๊ฒฝ์๋ ฅ ์๋ ์ฑ๋ฅ์ ๋ณด์ธ๋ค.
๐ก ๋ ผ๋ฌธ์ด ์ ์ํ ๊ฒ์?
- DEtection TRansformer, DETR์ Bipartite matching loss function(์ด๋ถ ๋งค์นญ ์์ค ํจ์)๋ฅผ ์ ์ํ๊ณ , Transformer๋ฅผ ์ด์ฉํ object detection task๋ฅผ ์ํํ๋ค.
Overall training procedure
- Extract feature map by CNN backbone
- CNN์ backbone network๋ก ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์ features๋ฅผ ์ถ์ถํ๋ค.
- Add Positional Encoding
- ์ด๋ฏธ์ง์์ ์๋์ ์ธ ์์น ์ ๋ณด๋ฅผ ๋ด๊ธฐ ์ํด positional encoding์ ์ถ๊ฐํ์ฌ encoder๋ก ๋ค์ด๊ฐ๋ค.
- Generate Object queires
- Output encoder memory by Transformer encoder
- Output embedding by Transformer decoder
- Class prediction by Class head
- Bounding box prediction by Bounding box head
- Match prediction with ground truth by Hungarian Matcher
- Compute losses
Background
- ๊ธฐ์กด object detection์ ์ฃผ๋ก pre-defined anchor์ ์ฌ์ฉํ๋ค. ์ด๋ ์ด๋ฏธ์ง ๋ด ๊ณ ์ ๋ ์ง์ ๋ง๋ค ๋ค์ํ scale, aspect ratio๋ฅผ ๊ฐ์ง anchor๋ฅผ ์์ฑํ๊ณ , anchor ๊ธฐ๋ฐ์ผ๋ก ์์ฑํ ์์ธก bounding box์ ground truth๋ฅผ ๋งค์นญํ๋ค. ์ด๋ ground truth์์ IoU๊ฐ์ด ํน์ threshold ์ด์์ผ ๊ฒฝ์ฐ positive sample๋ก ๊ฐ์ฃผํ๋ฉฐ, positive sample์ ๋ํด์๋ง bounding box regression์ ์ํํ๋ค. ์ด์ฒ๋ผ ํ๋์ ground truth์ ๋ํด ๋ค์์ bounding box๊ฐ ๋งค์นญ๋๋, ์์ธก bounding box์ ground truth ๊ฐ์ many-to-one ๊ด๊ณ๊ฐ ์ฑ๋ฆฝํ๋ค.
Bipartite Matching
- ๊ธฐ์กด object detection ๋ฐฉ๋ฒ๋ค์ ๋๋ฌด ๋ณต์กํ๋ฉฐ ๋ค์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฉํ๋ค. ๋ํ, bounding box์ ํํ, bounding box๊ฐ ๊ฒน์น ๋์ ์ฒ๋ฆฌ ๋ฐฉ๋ฒ๊ณผ ๊ฐ์ prior knowledge(์ฌ์ ์ง์)๊ฐ ์๊ตฌ๋๋ค. ์๋ฅผ ๋ค์ด, ํ์งํ๊ณ ์ ํ๋ object๊ฐ ๊ธฐ์ฐจ์ ๊ฐ์ด ๊ธด ๋ฌผ์ฒด์ผ ๊ฒฝ์ฐ bounding box๋ฅผ ๊ธธ๊ฒ ์ค์ ํ๋ค๋๊ฐ ํ๋ ๊ฒ์ด๋ค.
- ๋ํ, ํ๋์ ground truth๋ฅผ ์์ธกํ๋ ๋ค์์ bounding box๊ฐ ์กด์ฌํ๊ธฐ ๋๋ฌธ์ ์ด๋ฌํ near-duplicateํ ์์ธก, redundantํ ์์ธก์ ์ ๊ฑฐํ๊ธฐ ์ํด NMS(Non Maximum Supppresion)๊ณผ ๊ฐ์ post-processing ๊ณผ์ ์ด ๋ฐ๋์ ํ์ํ๋ค.
- ์ด ๋ ผ๋ฌธ์์๋ ์ด๋ฌํ ๋ฌธ์ ๋ฅผ bipartite matching(์ด๋ถ ๋งค์นญ)์ ํตํด set prediction problem์ ์ง์ ์ ์ผ๋ก ํด๊ฒฐํ๋ค. ์ฌ๊ธฐ์ set์ ์ํ์์ ๋งํ๋ ์งํฉ์ด๋ค. ์งํฉ์ ์ค๋ณต๋๋ ์์๊ฐ ์๊ณ , ์์์ ์์ ๋ํ ์๊ด์ด ์๋ค.
- ์ด๋ฏธ์ง์์ ํ์งํ object์ ๊ฐ์๋ฅผ ๊ณ ์ ํด๋๋ฉด, ์ด๋ถ ๋งค์นญ์ ์ํํ ์ ์๋ค.
- ์ด๋, Hungarian algorithm์ ์ฌ์ฉํ์ฌ loss๊ฐ ๊ฐ์ฅ ์๊ฒ ๋์ค๋๋ก, ground-truth์ prediction์ฌ์ด์ ์ด๋ถ ๋งค์นญํ๋ค.
Generalized Intersection over Union, GIoU
- GIoU loss๋ ๋ box ์ฌ์ด์ IoU๊ฐ์ ํ์ฉํ loss๋ก scale-invariant(์ฒ๋ ๋ถ๋ณ)ํ๋ค๋ ํน์ง์ด ์๋ค.
- GIoU๋ฅผ ๊ตฌํ๊ธฐ ์ํด์๋ predicted box $b_{\sigma(i)}$์ ground truth box $\hat{b_i}$๋ฅผ ๋๋ฌ์ธ๋ ๊ฐ์ฅ ์์ box $B(b_{\sigma(i)},\hat{b})$๋ฅผ ๊ตฌํ๋ค. ์ด๋, predicted box์ ground truth box๊ฐ ๋ง์ด ๊ฒน์น ์๋ก $B(b_{\sigma(i)},\hat{b})$๊ฐ ์์์ง๋ฉฐ, ๋ box๊ฐ ๋ฉ์ด์ง์๋ก $B(b_{\sigma(i)},\hat{b})$๊ฐ ์ปค์ง๋ค.
-
$IoU(b_{\sigma(i)},\hat{b})$๋ ๋ box ์ฌ์ด์ IoU๋ฅผ ์๋ฏธํ๋ฉฐ, $\frac{ B(b_{\sigma(i)},\hat{b} \setminus b_{\sigma(i)}\cup \hat{b_i} }{ B(b_{\sigma(i)},\hat{b} }$๋ $B(b_{\sigma(i)},\hat{b})$์์ predicted box์ ground truth box๋ฅผ ํฉํ ์์ญ์ ๋บ ์์ญ์ ํด๋นํ๋ค. GIoU๋ -1์์ 1 ์ฌ์ด์ ๊ฐ์ ๊ฐ์ง๋ฉฐ, GIoU loss๋ฅผ ์ฌ์ฉํ ๋๋ 1-GIoU ํํ๋ก ์ฌ์ฉํ๋ค. -
$L_{box}(b_{\sigma(i)},\hat{b})=\lambda_{iou}L_{iou}(b_{\sigma(i)},\hat{b})+\lambda_{L1} ย b_{\sigma(i)}-\hat{b} ย 1$, $\lambda{iou},\lambda_{L1}$์ ๋ term ์ฌ์ด๋ฅผ ์กฐ์ ํ๋ scalar hyperparameter
Transformer
DETR์์ ์ฌ์ฉํ๋ Transformer์ NLP task์์ ์ฌ์ฉํ๋ Transformer๋ ์ฐจ์ด์ ์ด ์๋ค.
- Transformer๋ encoder์์ ๋ฌธ์ฅ์ ๋ํ embedding์ ์ ๋ ฅ๋ฐ๋ ๋ฐ๋ฉด, DETR์ ์ด๋ฏธ์ง feature map์ ๋ฐ๋๋ค.
- Transformer๋ decoder์ target embedding์ ์ ๋ ฅํ๋ ๋ฐ๋ฉด, DETR์ object queries๋ฅผ ์ ๋ ฅํ๋ค.
- Transformer๋ decoder์์ ์ฒซ ๋ฒ์งธ attention ์ฐ์ฐ ์ masked multi-head attention์ ์ํํ๋ ๋ฐ๋ฉด, DETR์ multi-head self-attention์ ์ํํ๋ค.
- Transformer๋ decoder ์ดํ ํ๋์ head๋ฅผ ๊ฐ์ง๋ ๋ฐ๋ฉด, DETR์ ๋ ๊ฐ์ head๋ฅผ ๊ฐ์ง๋ค.
Encoder
- Encoder๋ $d \times HW$ํฌ๊ธฐ์ ์ฐ์์ฑ์ ๋ ๋ feature map์ ์ ๋ ฅ์ผ๋ก ๋ฐ๋๋ค. ์ด๋ $d$๋ image feature๋ฅผ ์๋ฏธํ๊ณ $HW$๋ ๊ฐ๊ฐ์ ํฝ์ ์์น ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ค.
- Encoder์ self-attention map์ ์๊ฐํํด๋ณด๋ฉด ๊ฐ๋ณ ์ธ์คํด์ค๋ฅผ ์ ์ ํ ๋ถ๋ฆฌํ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
Decoder
- Decoder๋ $N$๊ฐ์ object query(ํ์ต๋ ์์น ์๋ฒ ๋ฉ)๋ฅผ ์ด๊ธฐ ์ ๋ ฅ์ผ๋ก ์ด์ฉํ๋ค. ์ธ์ฝ๋๊ฐ global attention์ ํตํด ์ธ์คํด์ค๋ฅผ ๋ถ๋ฆฌํ ๋ค์ ๋์ฝ๋๋ ๊ฐ ์ธ์คํด์ค์ ํด๋์ค์ ๊ฒฝ๊ณ์ ์ ์ถ์ถํ๋ค.
Reference
-
https://www.youtube.com/watch?v=hCWUTvVrG7E&t=1207s
-
https://herbwood.tistory.com/26
Leave a comment