Skip to content

Vision Transformer is a robust learnerVision Transformers are Robust Learners

arXiv· arXiv:2105.07581· Sayak Paul, Pin-Yu ChenCarted; IBM ResearchIndexed by this site · 27 days ago· Originally publishedEvaluation

Quick read

Analysis and theory

Based on the paper PDF (AI-generated); refer to the original

The authors compare ViT with BiT on 6 ImageNet robustness benchmarks, the authors claim ViT is comprehensively more robust, and they use 6 attribution experiments to explain why.

Questions
Vision Transformer (ViT) achieves SOTA on standard image recognition, but its robustness to common corruptions, perturbations, distribution shifts, and natural adversarial examples lacks systematic evaluation and attribution. The authors want to answer whether ViT is more robust than CNN, and why.
Methods
Systematically compare ViT with BiT of comparable parameter count and pretraining setup and with the ResNet50V2 baseline on 6 ImageNet robustness benchmarks, then design 6 attribution experiments: the role of attention, the role of pretraining, image masking, Fourier spectrum sensitivity, DCT energy spectrum of adversarial perturbations, and the loss landscape under PGD.
Experiments and results
The authors report that ViT outperforms comparable BiT on ImageNet-C (mCE 45.45% vs. BiT 58.27%), ImageNet-P, ImageNet-R, ImageNet-A, ImageNet-O, and ImageNet-9; the exceptions are contrast corruption and the ImageNet-9 foreground fragility detection (ViT 20.02% lower than ResNet-50's 22.3%).
Limitations and future work
The authors note that ViT performs poorly on contrast corruption and leave it for future research; there are differences in training configurations between ViT and BiT (Dropout, optimizer), and the authors did not study the relationship between these factors and robustness; unexplainable spurious attention regions appear in Grad-CAM, which the authors say may point to future research.
Experimental setupViT B-16、ViT B-32 et al. · ImageNet-C、ImageNet-P et al. · top-1 accuracy、mCE et al.
Evaluated models
ViT B-16ViT B-32ViT L-16ViT L-32ViT S/16BiT m-r50x1BiT m-r50x3BiT m-r101x1BiT m-r101x3BiT m-r152x4EfficientNetV2 (GC)ResNet-L (GE)ResNet-M (GE)ResNet-S (GE)ResNet18 (SK)ResNet34 (SK)Wide (4x) ResNet-50 (SK)
Benchmarks
ImageNet-CImageNet-PImageNet-RImageNet-AImageNet-OImageNet-9
Metrics
top-1 accuracymCEmFRmT5DAUPRBG-Gap
AI summaryThe paper systematically evaluates the robustness of Vision Transformer (ViT) under common corruptions and perturbations, distribution shifts, and natural adversarial examples, and compares it with the SOTA convolutional neural network Big-Transfer (BiT) on six ImageNet robust classification datasets. The authors state that, under conditions of fewer parameters and similar dataset and pretraining combinations, ViT achieves 28.10% top-1 accuracy on ImageNet-A, which is 4.3 times that of comparable BiT variants. Through six systematically designed experiments, including image masking, Fourier spectrum sensitivity, and discrete cosine energy spectrum distribution analysis, the paper explains from quantitative and qualitative perspectives the sources of ViT's stronger robustness. Code for reproducing the experiments is available at https://git.io/J3VO0。

The paper systematically evaluates the robustness of Vision Transformer (ViT) under common corruptions and perturbations, distribution shifts, and natural adversarial examples, and compares it with the SOTA convolutional neural network Big-Transfer (BiT) on six ImageNet robust classification datasets. The authors state that, under conditions of fewer parameters and similar dataset and pretraining combinations, ViT achieves 28.10% top-1 accuracy on ImageNet-A, which is 4.3 times that of comparable BiT variants. Through six systematically designed experiments, including image masking, Fourier spectrum sensitivity, and discrete cosine energy spectrum distribution analysis, the paper explains from quantitative and qualitative perspectives the sources of ViT's stronger robustness. Code for reproducing the experiments is available at https://git.io/J3VO0。

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Whether ViT is more robust than CNN, and why it is more robust, previously lacked systematic robustness evaluation and attribution.

    Core question: How robust is the Vision Transformer (ViT) to common corruptions, perturbations, distribution shifts, and natural adversarial examples, and where does the robustness come from.

    • Problem setting: the authors note that Transformers have become a general architecture across modalities and achieve SOTA standard accuracy on vision tasks, but their robustness evaluation and attribution remain largely unexplored.
    • Gaps in existing work: the authors state that several works (Bhojanapalli et al. 2021; Shao et al. 2021; Mahmood et al. 2021) have begun to study ViT robustness, but with relatively limited scope.
    • Core observation and hypothesis: attention has been shown to help vision networks achieve better empirical robustness (Hendrycks et al. 2021), and attention is a core component of ViT, so the authors raise the question of whether ViT is inherently more robust; the authors give an affirmative answer to the first question and provide empirical evidence.
    • What the paper proposes: systematically compare ViT with a SOTA CNN (Big-Transfer, BiT) on 6 different ImageNet robustness datasets, and design 6 experiments (image masking, Fourier spectrum sensitivity, discrete cosine energy spectrum distribution, etc.) to attribute ViT's robustness both quantitatively and qualitatively.
    • Comparison setting: the baseline is ResNet50V2 pretrained on ImageNet-1k (some results cite already-reported ResNet-50 numbers); the main comparison object is BiT, because ViT and BiT share similar pretraining strategies (e.g., ImageNet-21k, longer pretraining schedules), facilitating comparison under similar parameter counts, FLOPs, and data scale.
  2. What related research exists?

    Related work falls into three groups: vision Transformer models, ViT variants, and concurrent ViT robustness research.

    Transformers on vision tasks

    • Parmar et al. (2018)—according to the authors, the earliest use of Transformer for image super-resolution (an image generation task).
    • Image-GPT (Chen et al. 2020)—unsupervised pretraining from pixels with a Transformer, but its transfer performance is inferior to supervised pretraining.
    • ViT (Dosovitskiy et al. 2021)—keeps the original Transformer architecture as unchanged as possible for image classification; because it has fewer inductive biases, it requires pretraining on larger datasets (e.g., ImageNet-21k) and stronger regularization.

    Variants of ViT

    • DeIT (Touvron et al. 2020)—proposes a distillation strategy, reaching 85.2% top-1 on ImageNet-1k without external data.
    • T2T-ViT (Yuan et al. 2021)—proposes a new tokenization method to capture more local structure, reaching 83.3% top-1 on ImageNet-1k; LV-ViT (Jiang et al. 2021)—proposes a token labeling training objective, reaching 85.4%.
    • CLIP (Radford et al. 2021) and Swin Transformers (Liu et al. 2021)—also apply Transformers to image recognition; this paper focuses only on ViT.

    Concurrent ViT robustness research

    • Shao et al. (2021)—finds ViT is more robust than CNN to adversarial input perturbations, with the main gain coming from learning more generalizable high-frequency features, and that convolutional layers hinder adversarial robustness.
    • Bhojanapalli et al. (2021)—studies ViT's robustness relative to ResNet on adversarial examples, natural adversarial examples, and common corruptions, and finds ViT is robust to removing almost any single layer.
    • Mahmood, Mahmood, and Van Dijk (2021)—studies ViT's adversarial robustness through white-box, black-box, and transfer attacks, and finds that model ensembles can achieve robustness to black-box adversaries without sacrificing clean accuracy.

    Baselines and benchmarks: the comparison baselines are BiT (Kolesnikov et al. 2020) and ResNet50V2 (He et al. 2016); on ImageNet-C/P, reported numbers from Noisy Student Training (Xie et al. 2020) and DeepAugment+AugMix (Hendrycks et al. 2020; Hendrycks* et al. 2020) are also referenced. The benchmarks are ImageNet-C, ImageNet-P (Hendrycks and Dietterich 2019), ImageNet-R (Hendrycks et al. 2020), ImageNet-A, ImageNet-O (Hendrycks et al. 2021), and ImageNet-9 (Xiao et al. 2021).

    The authors position the paper's differences as: (i) benchmarking on a fuller spectrum of ImageNet robustness benchmarks, which the authors call the most comprehensive robustness performance benchmark to date; (ii) designing 6 new experiments to verify ViT's robustness relative to BiT and ResNet.

  3. How does the paper address this problem?

    First systematically compare ViT and BiT on 6 benchmarks, then use 6 attribution experiments to explain the source of the robustness.

    The overall approach has two steps: first, compare ViT and BiT on 6 ImageNet robustness benchmarks under similar parameter counts/FLOPs/pretraining settings; then design 6 experiments to attribute the robustness from the perspectives of attention, pretraining, frequency spectrum, etc.

    Problem setting and comparison objects

    • ViT core mechanism: multi-head self-attention (MHSA), Attention(Q, K, V) = Softmax(QK⊤ / √d) V, i.e., computing attention scores over three linear projections—Query, Key, Value—and taking a weighted sum; after stacking h heads, the MHSA output is obtained via a linear transformation.
    • Reason for choosing the comparison object: BiT is a scaled-up ResNet (replacing Batch Normalization with Group Normalization and Weight Standardization) and shares a similar pretraining strategy with ViT (ImageNet-21k/JFT-300, long schedules), making it suitable for comparison under similar parameters and FLOPs.
    • Known configuration differences: the authors state that ViT uses Dropout and is trained with Adam, while BiT does not use Dropout and is trained with SGD with momentum; this paper uses only the public BiT and ViT models and does not study the relationship between these differences and robustness.

    Benchmarks and metrics

    • 6 benchmarks (Table 2): ImageNet-C (common corruptions, taking the highest severity level 5 among 19 corruptions), ImageNet-P (common perturbations, 10 types), ImageNet-R (semantic shift), ImageNet-O (out-of-distribution detection), ImageNet-A (natural adversarial examples), ImageNet-9 (background dependence).
    • Metrics: ImageNet-C uses mCE (averaging the top-1 error rate over 15 corruptions and 5 severity levels, normalized by AlexNet's mCE); ImageNet-P uses mFR and mT5D; ImageNet-O uses AUPR; ImageNet-9 uses top-1 accuracy and BG-Gap (the difference between Mixed-Same and Mixed-Rand); the rest use top-1 accuracy.

    Six attribution experiments (Section 4)

    1. Role of attention: compare various ImageNet-1k models with attention modules (GC, GE, SK blocks) against ViT S/16 on ImageNet-A/R/O; and visualize with Attention Rollout and Grad-CAM (Appendix C, E).
    2. Role of pretraining: compare the same ViT B/16 after pretraining on ImageNet-1k versus ImageNet-21k respectively; Appendix D compares BiT-s (ImageNet-1k pretraining), BiT-m, and ViT variants on ImageNet-A.
    3. Image masking: randomly take 1000 images from the ImageNet-1k validation set, use Cutout to randomly occlude square regions at four ratios {5,10,20,50}%, and compare the average top-1 of BiT (m-r101x3) and ViT (L-16); the authors state these two variants were chosen because their parameter counts are comparable and because random occlusion (rather than fixed regions) allows ViT to use global information.
    4. Fourier spectrum sensitivity: following the method of Yin et al. (2019), generate Fourier basis vectors of different frequencies and add them to 1000 random validation images, record the error rates to generate heatmaps, and report the P10/P25/P50/P90/P95 quantiles of the error matrix.
    5. Energy spectrum of adversarial perturbations: use DeepFool (step size 50) to generate perturbations for ResNet-50, BiT-m r50x3, and ViT B-16 on 1000 validation images, and compute the energy spectrum via DCT; the authors state that smaller BiT and ViT variants are used here due to computational constraints; the hypothesis is that ViT's perturbations will spread across the entire spectrum, whereas CNN's perturbations concentrate in low-frequency regions.
    6. Loss landscape: apply multi-step PGD attacks (l∞ budget ε=0.002, pixels normalized to [−1,1]) on 100 validation images that both models classify correctly, and compare how the classification loss of ViT (L-16) and BiT-m (r101x3) changes with the number of attack steps; Appendix J implements PGD with Adam (learning rate 1e-3) and visualizes the perturbations.
  4. What experiments did the paper conduct?

    On 6 benchmarks, ViT is mostly better than comparable BiT, and 6 attribution experiments support that attention and pretraining are the source; contrast corruption is the exception.

    Experimental setup

    • Models tested: ViT B-16, B-32, L-16, L-32 (S/16 additionally used for Table 7); BiT m-r50x1, m-r50x3, m-r101x1, m-r101x3, m-r152x4 (Appendix D additionally includes the BiT-s series); baseline ResNet50V2 (some results cite reported ResNet-50 numbers). All reported ViT and BiT variants are pretrained on ImageNet-21k and fine-tuned on ImageNet-1k (Table 1).
    • Benchmarks: 6 in total—ImageNet-C, P, R, A, O, 9 (Table 2); the paper does not give the number of samples per benchmark.
    • Metrics: mCE, mFR, mT5D (lower is better), AUPR, top-1 accuracy, BG-Gap.
    • Reference methods: on ImageNet-C/P, reported numbers from Noisy Student Training, DeepAugment+AugMix, and AugMix are cited; the authors note that these methods use additional data or are specifically designed for corruption resistance.
    • Sample sizes: the masking and Fourier experiments each use 1000 random validation images, and the loss landscape experiment uses 100; the paper does not report the number of repetitions.

    Main results

    According to Table 3 and Table 4 (ImageNet-C/P, lower is better):

    Swipe horizontally to read the table

    ModelImageNet-C mCEImageNet-P mFRImageNet-P mT5D
    ResNet-5076.75882
    BiT m-r101x358.2749.9976.71
    DeepAugment+AugMix53.6——
    AugMix—37.4NA
    ViT L-1645.4533.06450.15
    Noisy Student Training28.3——
    • The authors state that ViT consistently outperforms BiT on all ImageNet-C variants (Figure 1), even surpassing DeepAugment+AugMix, which is specifically designed for corruption resistance, but not Noisy Student Training, which uses additional data and training.
    • Exception: ViT performs poorly on contrast corruption (Figure 2; in Table 12, ViT L-32's contrast top-1 is 8.76%, lower than all BiT variants), which the authors leave for future research.
    • Other benchmarks (Figures 3–5; the main text does not give all specific numbers): the authors state that ViT adapts better to domain on ImageNet-R; on ImageNet-A, ViT L-16's top-1 is 4.3 times that of BiT-m r101x3 (the abstract gives ViT as 28.10%); on ImageNet-O, ViT's AUPR is better than BiT's.

    ImageNet-9 background robustness

    • What was measured: ImageNet-9 and its Mixed-Same and Mixed-Rand variants (Table 5), as well as foreground fragility detection (Table 6).
    • Results: ViT L-16 is higher than BiT-m r101x3 on Original (96.67%), Mixed-Same (88.49%), and Mixed-Rand (81.68%) (94.32/81.19/76.62%), but its BG-Gap is 6.81, higher than BiT's 4.57 (ResNet-50 is 7.3). On foreground fragility detection, ViT L-16 is 20.02%, higher than BiT's 3.78%, but lower than ResNet-50's 22.3%.
    • Authors' interpretation: the authors state that ViT has better background robustness and is significantly better than BiT on foreground detection; for ViT being worse than ResNet-50, the authors speculate that it may stem from ViT's simple image patch tokenization limiting its ability to handle important local structure.

    The role of attention and pretraining

    • Attention model comparison (Table 7): models with GC/GE/SK blocks and ViT S/16 are almost all better than ResNet-50 (2.14/25.25/16.76) on ImageNet-A/R/O, e.g., EfficientV2 (GC) is 7.39/32.70/20.34 and ViT S/16 is 6.40/26.11/22.50; the authors state that adding some form of attention is generally a good design choice, and note that these models differ from ViT in training configuration (especially regularization).
    • Pretraining (Table 8): for the same ViT B/16, ImageNet-21k pretraining gives 21.75/41.82/54.61 on ImageNet-A/R/O, higher than ImageNet-1k pretraining's 8.63/28.21/26.25. Appendix D (Table 11): ViT's improvement over comparable BiT-m on ImageNet-A ranges from +22.5 (ViT B-16) to +7.63 (ViT B-32) percentage points.

    Masking, spectrum, and loss landscape

    • Masking (Table 9): at occlusion ratios 0/0.05/0.1/0.2/0.5, ViT L-16 top-1 is 83/82.3/81.4/77.9/60.4 and BiT m-r101x3 is 79/76/75/72.4/52; the authors state ViT is consistently better, and note that the ViT used is shallower than BiT, arguing that attention may be the main source of this gain.
    • Fourier sensitivity (Figure 6, Table 10): the authors state that ViT and BiT have low sensitivity in most regions, and ResNet50V2 loses consistency in the high-frequency region; the error matrix quantiles (P10/P25/P50/P90/P95) are 6.7/7/7.6/13.1/15.1 for ViT L-16, 13.9/14.8/16.4/23/24.9 for BiT, and 21.8/30.2/40.4/58.9/63.6 for ResNet-50.
    • Energy spectrum and loss landscape (Figures 7, 8): the authors state that perturbations attacking ViT are spread across almost the entire spectrum, whereas BiT's and ResNet-50's perturbations are concentrated in the low-frequency region; under PGD, ViT's classification loss grows more slowly with attack steps than BiT's, which the authors state validates the hypothesis that ViT has a smoother loss landscape with respect to input perturbations.

    Other ablations and analyses

    • Per-corruption top-1 on ImageNet-C (Table 12): ViT L-16 is higher than BiT-m r101x3 on 14 of 15 corruptions, except contrast (18.85 vs 17.34; see Figure 2 in the main text for the exception).
    • Unnormalized corruption error on ImageNet-C (Table 13): ViT L-16 is 43.57 on contrast, close to BiT's 45.49.
    • Per-perturbation flip rate and top-5 distance on ImageNet-P (Tables 14, 15): ViT L-16 is lower than BiT-m r101x3 on all 10 perturbations.
    • Appendices C/E: Grad-CAM shows ViT's attention is more global, while BiT's is more local and centered; the authors note that some spurious attention regions are hard to explain and may point to future research.
  5. What are some points that can be further explored?

    The authors point out unresolved issues such as contrast corruption and training configuration differences; the experiments cover only public ViT/BiT and ImageNet-family benchmarks.

    Limitations noted by the authors and future directions

    • contrast corruption: ViT performs poorly on contrast corruption, which the authors say leaves room for future research—investigating why this is so, since contrast changes are common in real-world scenarios (Section 3.2).
    • Training configuration differences not studied: ViT uses Dropout and Adam, while BiT uses no Dropout and uses SGD; later ViT variants also used Sharpness-Aware Minimization and stronger regularization, and the authors explicitly state that this paper does not study the relationship between these factors and robustness (Section 3.2).
    • Relationship between regularization and robustness: In Table 7, the training configurations (especially regularization) of the attention models and ViT differ, and the authors state that exploring how regularization affects robustness is not a question this paper aims to answer (Section 4.1).
    • Spurious attention regions: In Grad-CAM there are some less interpretable spurious attention regions (e.g., the image predicted as centipede), which the authors say may lead to future research (Appendix C).
    • Interpretation boundary of masking results: Regarding the visualization results of masking ratio and prediction confidence in Appendix H, the authors explicitly state that these should not be regarded as conclusive.

    Scope of experiments

    • The models tested are the public ViT (B-16/B-32/L-16/L-32, plus S/16) and BiT (5 variants of the m series, the s series in Appendix D) and the ResNet50V2 baseline, all pretrained on ImageNet-21k and fine-tuned on ImageNet-1k (Table 1).
    • The benchmarks are 6 ImageNet-family datasets (Table 2); ImageNet-C uses the highest severity level 5, and the ImageNet-P metric is not normalized with AlexNet (Appendix G).
    • The adversarial experiments use only DeepFool (energy spectrum, step size 50) and PGD (loss landscape, ε=0.002); the energy spectrum experiment uses the smaller BiT-m r50x3 and ViT B-16 due to computational constraints (Section 4.5).
    • The masking and Fourier experiments each use 1000 random validation images, and the loss landscape uses 100; the paper does not report the number of repetitions or statistical significance tests.
    • The paper does not report the number of samples for each benchmark; some numbers for ResNet-50 are directly cited from previous reports (Section 3.2 footnote).
  6. Summarize the main content of the paper

    The authors evaluate ViT robustness on 6 ImageNet benchmarks and attribute it with 6 experiments; the authors state that ViT is more robust than comparable BiT.

    An evaluation and attribution study on Vision Transformer robustness. The authors aim to answer two questions: whether ViT is more robust than SOTA CNN, and where the robustness comes from.

    • Approach: on 6 benchmarks—ImageNet-C, P, R, A, O, and 9—compare ViT with BiT of comparable pretraining strategy and parameter count and with the ResNet50V2 baseline; then design 6 attribution experiments (the role of attention, the role of pretraining, random masking, Fourier spectrum sensitivity, DCT energy spectrum of adversarial perturbations, PGD loss landscape).
    • Main results: ViT L-16 has mCE 45.45% on ImageNet-C (BiT m-r101x3 is 58.27%, Table 3); mFR 33.064% vs 49.99% on ImageNet-P (Table 4); ViT top-1 on ImageNet-A is 28.10%, 4.3 times that of comparable BiT (abstract); ViT outperforms BiT on all ImageNet-9 variants (Table 5).
    • Exceptions: ViT performs poorly on contrast corruption (ViT L-32 only 8.76% in Table 12); on foreground fragility detection ViT L-16 (20.02%) is lower than ResNet-50 (22.3%) (Table 6).
    • Attribution conclusions (in the authors' voice): the authors argue that the attention mechanism and large-scale pretraining are the two main sources of robustness; ViT is more stable to random masking, less sensitive to Fourier spectrum perturbations, its adversarial perturbations spread across the entire spectrum, and its loss landscape is smoother.
    • Implications: the authors state that using Transformers can be orthogonal to known robustness-enhancement techniques, and that their analysis tools can be used to benchmark and study future image classification models; the shortcoming on contrast corruption and the influence of training configuration differences are left for future research.
Read originalarxiv.org