[Paper Review] Discrete Representations Strengthen Vision Transformer Robustness
This paper proposes Dr. ViT, a Vision Transformer variant that enhances robustness by replacing standard continuous pixel tokens with discrete tokens from a vector-quantized VQ-GAN encoder. By combining discrete tokens with residual pixel embeddings, the model learns more invariant, shape-aware representations, improving performance by up to 12% across seven ImageNet robustness benchmarks without sacrificing ImageNet accuracy.
Vision Transformer (ViT) is emerging as the state-of-the-art architecture for image recognition. While recent studies suggest that ViTs are more robust than their convolutional counterparts, our experiments find that ViTs trained on ImageNet are overly reliant on local textures and fail to make adequate use of shape information. ViTs thus have difficulties generalizing to out-of-distribution, real-world data. To address this deficiency, we present a simple and effective architecture modification to ViT's input layer by adding discrete tokens produced by a vector-quantized encoder. Different from the standard continuous pixel tokens, discrete tokens are invariant under small perturbations and contain less information individually, which promote ViTs to learn global information that is invariant. Experimental results demonstrate that adding discrete representation on four architecture variants strengthens ViT robustness by up to 12% across seven ImageNet robustness benchmarks while maintaining the performance on ImageNet.
Motivation & Objective
- To address Vision Transformer's over-reliance on local textures and poor generalization to distribution shifts.
- To improve robustness without compromising in-domain performance on ImageNet.
- To explore whether discrete tokenization can promote learning of global, shape-invariant features in ViT.
- To develop a plug-and-play input-layer modification that enhances robustness across ViT variants.
- To demonstrate that discrete representations, previously used in generation, can improve generalization in classification.
Proposed method
- Replace standard continuous pixel embeddings with discrete tokens from a VQ-GAN encoder, which quantizes image patches into codebook indices.
- Use a learned codebook to map image patches into discrete visual words, preserving structural and shape information.
- Concatenate the discrete token embeddings with original pixel embeddings to retain local detail, especially for small objects.
- Train the ViT with both discrete and continuous representations using standard optimization (Adam, cosine decay) and data augmentation (RandAug, Mixup).
- Use a lightweight VQ-encoder for small models and a larger one for ViT-B, with codebook sizes of 1,024 (ImageNet) and 8,192 (ImageNet-21K).
- Apply average pooling on final features for ViT-B and fine-tune on higher-resolution inputs (384×384, 512×512) for improved generalization.
Experimental results
Research questions
- RQ1Can discrete tokenization improve Vision Transformer robustness to distribution shifts?
- RQ2Does replacing continuous pixel tokens with discrete representations encourage ViT to learn more shape-invariant features?
- RQ3How does the combination of discrete and continuous tokens affect performance on in-distribution and out-of-distribution benchmarks?
- RQ4Can this method be applied across different ViT architectures without architectural changes?
- RQ5Does the use of discrete tokens lead to better attention patterns that reflect global context rather than local texture?
Key findings
- Dr. ViT improves robustness on Stylized-ImageNet by up to 12%, and on ImageNet-Sketch and ImageNet-C by up to 10% compared to standard ViT.
- The method achieves state-of-the-art performance on four out of seven ImageNet robustness benchmarks without using dataset-specific data augmentation.
- Adding discrete tokens improves attention patterns, making models more sensitive to global structure and less to local texture, as shown in visualization comparisons.
- The discrete-only variant performs poorly on small models (e.g., ViT-Ti), but performance improves significantly when combined with pixel embeddings.
- Training ViT-B for 800 epochs instead of 300 yields an additional 0.1–1% accuracy gain on ImageNet, indicating benefits of longer training with discrete tokens.
- The approach is orthogonal to existing robustness techniques and can be integrated into any ViT-based architecture with minimal modification.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.