On the journey of

[논문읽기] BEiT : BERT Pre-training of Image Transformers 본문

Experiences & Study/VQA

[논문읽기] BEiT : BERT Pre-training of Image Transformers

dlrpskdi 2023. 10. 17. 07:48

Original Paper ) BEiT: https://arxiv.org/abs/2106.08254

 

BEiT: BERT Pre-Training of Image Transformers

We introduce a self-supervised vision representation model BEiT, which stands for Bidirectional Encoder representation from Image Transformers. Following BERT developed in the natural language processing area, we propose a masked image modeling task to pre

arxiv.org

Contribution
  • BERT의 Masked Language Modeling에서 착안한 Maksed Image Modeling 제안, VAE 관점의 이론적인 설명을 제시했다.
  • BEiT를 이용한 pretrain후 downstream task에 대해 fine-tuning 실험을 진행하였다.
  • self-supervised BEiT의 semantic regions와 object boundaries에 대한 self-attention 메커니즘이 human annotation없이 학습이 되었다.
Introduction
  • Vision Transformers는 CNN 보다 많은 데이터를 필요로 하는 것이 실험(경험)이 쌓이면서 밝혀지고 있다. 이 문제를 해결하기 위하여 self-supervised pre-training 하는 것이 large-scale image data에서 성능을 높이기 위한 유망한 해결책으로 제시되고 있다.
  • 또한 contrastive learning, self-distillation같은 몇가지 방법들이 같이 탐구되고 있다.
  • BERT에서 text tokens의 일부 비율을 masking후 이 corrupted text로 부터 reconstruct하는것처럼 MLM(Masked language learning)에서 영감을 받아 MIM(masked image modeling)을 제안한다.

Methods

기본적인 구조는 ViT와 같다.

2.1.1 Image Patch

이미지 x를 PxP 크기의 N개의 패치로 나누어 Flatten 후에 input으로 쓰인다.

P = 16, N=14 즉 14x14=196 개의 16x16 patches로 나누어 사용한다.

 

2.1.2 Visual Token

h = 14 X 14 = 196

w = 16X16X32 = 8192

Discrete VAE

https://nowolver.tistory.com/191

 

[논문읽기] VQ-VAE (Neural Discrete Representation Learning)

Original paper ) https://arxiv.org/abs/1711.00937 Neural Discrete Representation Learning Learning useful representations without supervision remains a key challenge in machine learning. In this paper, we propose a simple yet powerful generative model that

nowolver.tistory.com

nlp에서 vocab → embedding후 embedding 벡터를 통해 다음 단어를 예측하듯이 visual token(= codebook embeddings)를 사용한다.

그림출처: https://medium.com/@dhartidhami/learning-word-embeddings-9f15533645b3

 

Learning Word Embeddings

Let’s formalize the problem of learning a good word embedding.

medium.com

Blockwise Masking

span BERT의 아이디어를 가져옴. 마스킹 될 이미지 패치를 랜덤하게 하지 않고 위의 알고리즘을 거쳐서 충분하게 40%의 마스킹 비율을 가지고 마스킹을 실시한다.

Experiments
  • image classification

ViT 계열, Contrastive learning (Moco), Knowledge Distillation(DINO) 들과 비교해봤을때 BEiT의 성능이 가장 뛰어났다.

  • semantic segmantation

: Supervised Pre-training을 진행했을때보다 오려 BEiT로 self supervised learning 한 것이 성능이 더 좋았다.

마이너스와 플러스는 각각 BEiT에서 명시된 방법을 빼거나 더하고 진행했다는 의미이다.

  1. Blockwise masking방법을 빼고 Random masking을 진행했을때 성능은 조금 떨어졌다.
  2. Visual token을 쓰지 않고 masked pixels에서 원본 이미지를 바로 reconstruct하는 작업 (Denoising Auto Encoder)을 진행하였을 때 성능이 조금 떨어졌다.
  3. 2번 방법에 Blockwise 대신 Random patch를 했을 때 성능이 많이 떨어졌다.
  4. Knowledge Distillagtion방법으로 visual token을 recover 했을 때 ImageNet(classification)에서는 성능이 비슷했고 ADE20K(segmentation)에서는 성능이 조금 떨어졌다.
Related Work: self-supervised visual representation learning

 

Conclusion
  • ViT + BERT + VQ-VAE 기존 방법들을 합쳤다
  • Human-annotated data 없이도 스스로 얻어진 semantic 영역을 조금 구별해낸다.
Reference

https://youtu.be/zwv7wg1DDuo

https://www.youtube.com/watch?v=uCWhUayAwOY&t=1104s

codes

https://github.com/microsoft/unilm/blob/master/beit/semantic_segmentation/backbone/beit.py

https://github.com/leondgarse/keras_cv_attention_models/blob/2b30f2942cd908670cc2999f00e00aae766486d4/keras_cv_attention_models/beit/beit.py#L268

https://github.com/huggingface/transformers/blob/v4.23.1/src/transformers/models/beit/modeling_beit.py#L620