Transformer와 같은 self-attention based architecture는 natural language processing (NLP) 분야에서 좋은 성능을 보여주고 있다. 주요한 접근법은 large text corpus로 pre-training한 모델을 task-specific dataset에 대해 fine-tuning하는 것이다. Transformer의 computational efficiency와 scalability 덕분에 100B parameter가 넘는 size의 모델을 훈련시킬 수 있었다.
그러나 computer vision 분야에서는 여전히 convolutional architecture가 사용되고 있다. NLP 분야에서의 성공에 영감을 받아 CNN-like architecture와 self-attention을 결합하려는 시도가 계속되어 왔지만, large-scale image recognition 분야에서는 classic ResNet-like architecture가 여전히 state of the art인 상황이다.
본 논문에서는 NLP 분야에서 Transformer의 성공에 영감을 받아 image에 standard Transformer를 직접적으로 적용시키는 실험을 진행해 보았다. 그러기 위해 image를 patch로 나누고 Transformer의 input으로 넣기 위해 linear embedding을 적용시켰다. 이때 image patch는 NLP application에서 token과 같이 작용한다.
ImageNet과 같은 mid-sized dataset으로 훈련시켰을 때, 이 모델은 ResNet보다 몇 퍼센트 정도 낮은 정도의 정확도를 가졌다. Transformer는 일반적으로 충분하지 않은 양의 data로 학습되었을 때 잘 일반화되지 않는 경향을 보였고 결과도 그리 좋지 않았는데, 이로부터 ViT가 CNN보다 낮은 inductive bias를 갖는다는 것을 알 수 있었다.
반면, Model이 더욱 많은 dataset (14M-300M images)으로 훈련되었을 경우 picture에 변화가 발생했다. 본 모델인 Vision Transformer (ViT)는 충분한 scale에 대해 pre-trained되었을 경우 낮은 inductive bias로 인한 성능 저하를 해소시키며 훌륭한 결과를 도출해냈다. Public ImageNet-21k dataset이나 in-house JFT-300M dataset에 대해 pre-trained되었을 때 ViT는 multiple image recognition에 있어 state of the art를 기록했다.
Transformer는 machine translation 분야에서 제안된 이후 많은 NLP task에서 state of the art를 달성했다. 대표적인 예시로는 large Transformer-based model을 large corpora에 대해 pre-training시키고 주어진 task에 대해 fine-tuning하는 모델인 BERT와 GPT가 있다.
이후 단락에서는 self-attention을 image에 적용시킨 연구들에 대해 소개한다.
본 모델은 최대한 original Transformer의 구조를 따르도록 디자인하였다.
본 모델의 전체적인 구조를 그림으로 그리면 Figure 1과 같다.
Figure 1: Model overview.
Standard Transformer는 token embedding의 1D sequence를 input으로 받는다. 2D image를 다루기 위해서 우리는 image $\mathbf x \in \mathbb R^{H \times W \times C}$를 flattened 2D patch의 sequence인 $\mathbf x_p \in \mathbb R^{N \times (P^2 \cdot C)}$로 reshape한다. 여기서 $(H, W)$는 original image의 resolution, $C$는 channel의 수, $(P, P)$는 image patch의 resolution이고, $N=HW/P^2$은 patch의 개수로 Transformer에서 input sequence length의 역할을 한다. Transformer는 size $D$의 latent vector를 사용하기 때문에 trainable linear projection을 이용하여 patch를 flatten하고 $D$ dimension으로 mapping한다. (Eq. 1)