DeepLearning/Computer Vision

[Paper Review] Patch-level Representation Learning for Self-supervised Vision Transformers (CVPR'22)

yooj_lee 2023. 1. 26. 02:32
300x250

오늘은 CVPR 2022에서 oral presentation으로 선정된 논문인 Patch-level Representation Learning for Self-supervised Vision Transformers (a.k.a. SelfPatch) 를 리뷰해보도록 하겠습니다.

기존의 SSL ViT 아키텍처가 모두 global representation만을 loss에서 활용된다는 점을 이야기하면서 이러한 부분은 attention의 collapse로 이어지며 representation quality를 떨어뜨린다고 문제를 제기하고 있습니다. 해당 논문은 ViT 아키텍처에서 손쉽게 patch representation을 얻을 수 있음에도 불구하고 이러한 부분은 전혀 활용되지 않고 있다는 점에서 출발하여, ViT에서 내부적으로 process되는 patch representation을 활용하여 self-supervision을 줌으로써 모델이 추가적으로 patch-level로도 더 좋은 feature를 얻을 수 있도록 합니다. 이러한 patch-level self-supervision은 dense prediction task에 특히 효과적이었음을 밝히고 있습니다.
(appendix에서 나오지만, classification에서도 아주 미약하지만 성능 향상이 있긴 했습니다. 다만, 일반적으로 조금 더 local한 representation인 patch-level representation이 dense prediction task에 효과적이라는 건 DenseCL 등 기존의 CL 연구에서 익히 알려져왔던 터라 아무래도 강조를 dense prediction task 쪽으로 둔 것 같습니다)

하기한 내용에서 오류가 있거나 궁금한 점이 있을 시 언제든 댓글 부탁드립니다. (이번 글은 블로그용으로 많이 다듬지를 못해서 조금 두서없을 수 있습니다..양해 부탁드립니다)


Abstract

기존의 pretext task의 경우에는 architecture-agnostic함. 즉, 아키텍처의 특성을 전혀 활용하지 않는 방식의 task였음. 저자들은 vit의 특성인 patch 기반의 representation을 학습하는 내부 구조를 leverage하여 SelfPatch라는 간단하지만 효과적인 pretext task를 설계함. SelfPatch는 각 패치 별로 neighboring patch 중 의미적으로 유사한 패치들을 positive pair로 상정하고 둘을 가깝게 하도록하는 self supervision을 적용. 이러한 task를 통해서 patch 간 보다 유의미한 representation을 추출할 수 있음. 특히, Dense  Prediction(OD, SemSeg, ...) 의 경우에 보다 더 좋은 영향을 끼치게 됨.


1. Introduction

Previous Self-Supervised Learnings

a variety of pretext tasks

  • contrastive learning: SimCLR, MoCo v1 & v2
  • clustering: SwAV
  • pseudo-labeling: DiNO, SimSiam, BYOL

The common nature of their designs is utilizing different augmentations from the same image as the positive pairs
→ learn representations invariant to given augmentations.

These SSL methods have been competitive with or outperformed standard supervised learning (ResNet) in various downstream tasks.

SSL & ViTs

Vision Transformers emerged as an alternative to CNNs with superior performance over CNNs in various visual tasks. (faster throughput and higher accuracy)

Have been several recent attempts to apply existing self-supervision techniques to ViTs. They have shown the effectiveness of ViTs in a self-supervised approach, yet their pretext tasks are architecture-agnostic (which means previous SSL methods with ViTs are not fully utilizing the architectural properties of ViTs)

This might lead to a failure to capture semantically meaningful relations among patches, e.g., collapsed self-attention maps among patches.

image

Figure 1 shows that DINO (current SOTA) has an attention map less related to the given query patch. Also, its attention maps look similar regardless of where the query patch is provided. On the opposite, SelfPatch attends a region that is highly related to the given query patch.

 

Contributions

  1. Paper proposed a simple yet effective SSL scheme for learning patch-level representations called SelfPatch (which can benefit various visual downstream tasks.).
  2. Patch-level SSL scheme, SelfPatch, can be incorporated into any image-level self-supervised ViT for simultaneously learning both global(image-level) and local(patch-level) information.

 

Key idea

  1. to treat semantically similar neighboring patches as positive samples motivated by prior knowledge: adjacent patches often share a common semantic context.
    → 물리적으로 가까우면, 의미적으로도 가까울 가능성이 크다.
  2. 패치 representations 간 cosine similarity를 계산하여 인접 패치를 정해둔 개수만큼 선정하여 positive candidates로 상정. 하지만, False Positive를 어느 정도 필터링했다고 해도 역시 negative sample이 존재할 여지(noisyness)가 있음.
    Aggregation for denoising (by utilizing an additional attention-based aggregation module on the top of ViT).
  3. Minimize the distance between each patch representation and the corresponding summarized one.

 

They are good on...

  • effectiveness of their architecture on a wide range of dense prediction downstream tasks (COCO object detection and instance segmentation, ADE20K semantic segmentation, DAVIS 2017 video object segmentation) → outperforms the current SOTA and other SSL baselines by a large margin.
  • High compatibility of SelfPatch by incorporating various objectives, architectures, and patch sizes.

They highlight the importance of learning patch-level representations during pre-training ViTs in a self-supervised manner.

 


2. Method

ViTs can handle patch-level representations ${f_\theta^{(i)}(\mathrm{x})}$, but the recent SSL schemes use only $f_\theta^{\texttt{[CLS]}}(\mathrm{x})$ (which is only dependent on an image-level feature → architecture-agnostic).

→ Let's adjust the level of features from images to patches within an image.

Note that they set both levels of self-supervision; image & patch.

Image-level self-supervision

image

image-level self-supervision은 어떤 image-level self-supervised scheme이든 상관없으나 selfpatch에서는 dino를 사용함.

Patch-level self-supervision

image

SelfPatch에서는 가까운 패치끼리는 의미적으로도 가깝다는 가정 하에 self-supervision을 설정하고 있음.

training 시 다음의 4가지 과정을 수행함.

1) Find the Neighboring patches
2) Positive Matching
3) Aggregation module
4) Projection head

selfpatch에서 특별한 것은 1,2,3이고, 4는 SelfPatch만의 thing은 아님.

아이디어는 심플함. 1) 주어진 패치 내에서 window size 만큼의 2d neighborhood window를 설정하고 2) 그 안에서 "True positive"를 가져오고 3) 이를 하나로 aggregate하고 4) contrastive loss에 넣기 좋게 projection 수행을 해주는 것.

이후, 쿼리 패치와 주변 패치로부터 얻은 positive neighbors 간의 dissimilarity를 줄이는 방식으로 학습을 수행함.

[Neighboring patches & positive matching]

image

2)에서 true positive를 가져온다는 건 위의 그림에서 그 컨셉을 자세히 알 수 있음. 그림에서 볼 수 있다시피 가까운 패치가 항상 의미적으로 비슷하다고 할 수는 없음. 따라서, 이에 쿼리 패치와의 cosine similarity를 계산하고 이 중 top-k개를 positive candidates로 지정하게 되는데, 이 과정을 논문에서는 "positive matching"이라고 칭하고 있음.

여기서 생각해볼 만한 건 굳이 negative를 찾지 않아도 된다는 점임. (이런 기조는 SimSiam, BYOL, SwAV, DINO 등 쭉 이어져옴. 이런 부분은 mocoV3에도 언급이 되어 있는데, "it is of central importance to learn invariant features by matching positive samples." 라고 되어 있음. )
즉, 논문에서 제안하는 positive matching은 정확히는 positive를 mining하는 과정이라고 할 수 있음. (contrastive learning 혹은 metric learning 분야에서는 negative mining에 좀 더 중점을 두어왔는데 여기서는 positive를 mining한다는 점에서 좀 신선했음. 물론 저자의 의도와는 다를 수 있음..)

[Aggregation]

positive matching을 거친 후에도 여전히 false positive sample이 존재할 수 있음. 따라서, 이러한 fp case를 희석해주기 위해서 class attention을 이용해서 feature aggregation을 해줌. 이러한 aggregation은 image-level의 self-supervision에서도 적용이 된다는 점을 염두에 둘 것.

Aggregation module로는 Touvron et al., 2021의 class attention을 활용.

[Loss]

최종적인 loss의 formulation은 아래와 같다. 참고로, 학습 시 활용되는 두 인코더에는 momentum + online 방식을 활용함.

image

여기서 $g$와 $g'$는 projection head를 가리킴. $\lambda$로 SelfPatch Loss에 대한 가중을 어느 정도 줄 건지를 조절함.

 


3. Experiments

selfpatch는 add-on처럼 기존의 image-level representation만 얻게끔 설계된 method를 좀 더 보완하는 방식임. 따라서, 실험에서 selfpatch를 활용하면 +selfpatch로 표기를 함.

Efficacy on dense prediction tasks

tested on three benchmarks: 1) COCO Object Detection & Instance Segmentation, 2) ADE-20K Semantic Segmentation, 3) DAVIS 2017 Video instance segmentation

image

→ For COCO, SelfPatch showed higher training efficiency and performance

 

image

→ For ADE-20k, SelfPatch improved DINO (DINO itself falls behind the MoBY)

 

image

→ For DAVIS, it improved DINO in a quantitive and qualitative manner. (여기서의 evaluation metric은 자세한 설명은 생략. 큰 값일 수록 더 높은 성능)

 

Ablations

For ablations, this work used ViT-Ti/16 on the MS COCO train2017 dataset for 200 epochs with a batch size of 256 and evaluated the pre-trained models on the DAVIS 2017 benchmark.

[Component Analysis]

제안한 method 내 component에 대한 analysis

image

neighborhood 사이즈, aggregation module의 유무가 아주 영향력이 큼. 이에 비해 positive candidate의 수($k$)는 그렇게 크게 중요하지 않았음.$k$ 자체가 무의미하다기보다는 aggregation의 상쇄효과가 매우 큰 듯함. 

 

[Compatibility Analysis]

1) dino 이외의 다른 아키텍처에도 적용이 잘 되는지? yes

image

첨언하자면, 위의 그림에는 가려놓았지만 실제로 MoBY를 Swin-T backbone이 아닌 ViT backbone을 이용했을 때도 실험을 해봄. 여기서 MoBY는 negative pair를 활용하는 Contrastive Learning 방법론이기 때문에 selfpatch에서도 negative를 넣어줄지 넣어주지 않을지에 대한 실험을 추가적으로 진행함 (아무래도 loss term에서 entropy 항의 분모에 negative를 추가해주는 형태로 진행이 되었을 것 같음). 이때, SelfPatch는 negative pair 없이 positive pair와의 matching 만으로도 좋은 성능을 내주었음 (Negative를 활용할 시 58.9, positive를 활용할 시 58.4)

 

2) vit 내부 patch size에는 얼마나 영향을 많이 받는지? Better with a smaller patch size

image

 

[Hyperparameter Analysis]

loss weight인 $\lambda$에 대해 분석

image

$\lambda$가 0이 아닐 때 (즉, SelfPatch가 유효할 때) 기존 DINO or DINO + Agg. module 일 때 좋은 performance가 나왔다.
→ SelfPatch 유의미하다! ($\lambda$ 값에 대해 좀 더 조절을 많이 해서 실험을 해봤으면 더 좋았을 것 같긴 함. 결론이 결국에는 앞에서 했던 video instance segmentation이랑 크게 다를 게 없어보임)

 


4. Conclusion

Pros

  • ViT 구조를 잘 활용해서 patch-level에서의 contrastive learning을 제안함. 이를 통해 representation의 퀄리티를 높이고, 이에 따라 dense prediction task에 대해 성능을 제고함.
  • 최근 ssl 분야에서 활발히 연구되고 있는 masked image modeling 방법론과 좀 결을 비슷하게 하는 듯함. 다만, 기본적으로 CL 자체가 shape-biased되어 있고 global한 정보를 capture하는 경우가 많은데 이는 vit의 속성을 잘 이용해서 CL에서도 patch-level 정보를 capture하게 되는 게 재밌었음. 최근, ssl 분석 논문을 하나 보고 있는데 거기에서 CL은 global repr (collapse of attention을 여기에서와 같이 똑같이 지적함), MIM은 local repr를 더 잘 학습한다고 report하고 있음. 더 나아가서, 보는 게 다르기 때문에 같이 사용하는 게 좋다. 라고 말하고 있는데, 이게 결국에는 SelfPatch가 하는 것과 동일하다고 생각함!

Cons

  • ViT는 1d-sequence 형태로 들어감에도 불구하고 2d-position을 잘 학습하는 부분이 좋았던 것 같은데 (no inductive bias) 여기서는 2d-neighborhood를 가정하면서 결국에는 inductive bias를 주는 부분이 좀 아쉬웠던 것 같음. 이런 부분은 다른 방식을 좀 생각하기 어려울 것 같긴 함.
  • motivation이 좀 약한 것 같았음. 하나로만 collapse하는 게 왜 안 좋은 건지? 오히려 object를 잘 잡기 때문에 더 좋은 건 아닌지?에 대한 기술을 좀 해볼 수 있을 것 같은데 그러한 부분에 대한 언급이 좀 없어서 아쉬웠음. 개인적인 생각으로는 collapse가 일어나면 안 좋은 점이라기보다는 collapse 없이 각 패치 주변에 대한 정보를 잘 인식하는 쪽으로 patch attention이 diversify되는 건 결국에는 해당 patch 주변을 잘 보면서 물체의 edge를 좀 더 잘 포착한다거나 dense prediction task에 대해 좀 더 유의미한 feature들을 잘 추출할 수 있다고 생각함. 혹은 object-centric한 이미지가 아니라 좀 더 다양한 object가 등장하는 instance segmentation 등의 상황에서 좀 더 효과적일 수 있을 것으로 생각이 듦.
  • 실험 결과가 DINO를 improve하는 것으로만 보여지는 부분들이 좀 아쉬웠음. SOTA 성능을 보여줘야 하는 부분이기에 어쩔 수 없었을 것으로 생각됨.

+) 이건 내 생각은 아니고, open review에서 본 건데 ViT에서 내부적으로 patch를 process하는 아키텍처 특성에 매우 의존적이기 때문에 ViT에서만 활용이 가능하다는 비판이 좀 있었음. 그때 당시엔 그럴 수 있겠다 했는데..생각해보니 resnet에서도 어쨌든 patch feature는 만들어낼 수 있는 거라고 생각함...다만 좀 engineering이 많이 들어가서 귀찮아질 수는 있을 듯함..

300x250