Kun Yuan, Shaopeng Guo, Ziwei Liu, Aojun Zhou, Fengwei Yu, Wei Wu
Motivated by the success of Transformers in natural language processing (NLP) tasks, there emerge some attempts (e.g., ViT and DeiT) to apply Transformers to the vision domain. However, pure Transformer architectures often require a large amount of training data or extra supervision to obtain comparable performance with convolutional neural networks (CNNs). To overcome these limitations, we analyze the potential drawbacks when directly borrowing Transformer architectures from NLP. Then we propose a new \textbf{Convolution-enhanced image Transformer (CeiT)} which combines the advantages of CNNs in extracting low-level features, strengthening locality, and the advantages of Transformers in establishing long-range dependencies. Three modifications are made to the original Transformer: \textbf{1)} instead of the straightforward tokenization from raw input images, we design an \textbf{Image-to-Tokens (I2T)} module that extracts patches from generated low-level features; \textbf{2)} the feed-froward network in each encoder block is replaced with a \textbf{Locally-enhanced Feed-Forward (LeFF)} layer that promotes the correlation among neighboring tokens in the spatial dimension; \textbf{3)} a \textbf{Layer-wise Class token Attention (LCA)} is attached at the top of the Transformer that utilizes the multi-level representations. Experimental results on ImageNet and seven downstream tasks show the effectiveness and generalization ability of CeiT compared with previous Transformers and state-of-the-art CNNs, without requiring a large amount of training data and extra CNN teachers. Besides, CeiT models also demonstrate better convergence with $3\times$ fewer training iterations, which can reduce the training cost significantly\footnote{Code and models will be released upon acceptance.}.
| Task | Dataset | Metric | Value | Model |
|---|---|---|---|---|
| Image Classification | Stanford Cars | Accuracy | 94.1 | CeiT-S (384 finetune resolution) |
| Image Classification | Stanford Cars | Accuracy | 93.2 | CeiT-S |
| Image Classification | Stanford Cars | Accuracy | 93 | CeiT-T (384 finetune resolution) |
| Image Classification | Stanford Cars | Accuracy | 90.5 | CeiT-T |
| Image Classification | CIFAR-10 | Percentage correct | 99.1 | CeiT-S (384 finetune resolution) |
| Image Classification | CIFAR-10 | Percentage correct | 99 | CeiT-S |
| Image Classification | CIFAR-10 | Percentage correct | 98.5 | CeiT-T |
| Image Classification | Oxford-IIIT Pets | Accuracy | 94.9 | CeiT-S (384 finetune resolution) |
| Image Classification | Oxford-IIIT Pets | Accuracy | 94.6 | CeiT-S |
| Image Classification | Oxford-IIIT Pets | Accuracy | 94.5 | CeiT-T (384 finetune resolution) |
| Image Classification | Oxford-IIIT Pets | Accuracy | 93.8 | CeiT-T |
| Image Classification | Flowers-102 | Accuracy | 98.6 | CeiT-S (384 finetune resolution) |
| Image Classification | Flowers-102 | Accuracy | 98.2 | CeiT-S |
| Image Classification | Flowers-102 | Accuracy | 97.8 | CeiT-T (384 finetune resolution) |
| Image Classification | Flowers-102 | Accuracy | 96.9 | CeiT-T |
| Image Classification | iNaturalist 2019 | Top-1 Accuracy | 82.7 | CeiT-S (384 finetune resolution) |
| Image Classification | iNaturalist 2019 | Top-1 Accuracy | 78.9 | CeiT-S |
| Image Classification | iNaturalist 2019 | Top-1 Accuracy | 77.9 | CeiT-T (384 finetune resolution) |
| Image Classification | iNaturalist 2019 | Top-1 Accuracy | 72.8 | CeiT-T |
| Image Classification | CIFAR-100 | Percentage correct | 91.8 | CeiT-S |
| Image Classification | CIFAR-100 | Percentage correct | 91.8 | CeiT-S (384 finetune resolution) |
| Image Classification | CIFAR-100 | Percentage correct | 89.4 | CeiT-T |
| Image Classification | CIFAR-100 | Percentage correct | 88 | CeiT-T (384 finetune resolution) |
| Image Classification | ImageNet | GFLOPs | 12.9 | CeiT-S (384 finetune res) |
| Image Classification | ImageNet | GFLOPs | 4.5 | CeiT-S |
| Image Classification | ImageNet | GFLOPs | 3.6 | CeiT-T (384 finetune res) |
| Image Classification | ImageNet | GFLOPs | 1.2 | CeiT-T |