Denoising Vision Transformers

Jiawei Yang, Katie Z. Luo, Jiefeng Li, Kilian Q. Weinberger, Yonglong Tian, Yue WangarXiv 2024

Abstract: We study a crucial yet often overlooked issue inherent to Vision Transformers (ViTs): feature maps of these models exhibit grid-like artifacts, which hurt the performance of ViTs in downstream dense prediction tasks such as semantic segmentation, depth prediction, and object discovery. We trace this issue down to the positional embeddings at the input stage. To mitigate this, we propose a two-stage denoising approach, termed Denoising Vision Transformers (DVT). In the first stage, we separate the clean features from those contaminated by positional artifacts by enforcing cross-view feature consistency with neural fields on a per-image basis. This per-image optimization process extracts artifact-free features from raw ViT outputs, providing clean feature estimates for offline applications. In the second stage, we train a lightweight transformer block to predict clean features from raw ViT outputs, leveraging the derived estimates of the clean features as supervision. Our method, DVT, does not require re-training the existing pre-trained ViTs, and is immediately applicable to any Vision Transformer architecture. We evaluate our method on a variety of representative ViTs (DINO, DeiT-III, EVA02, CLIP, DINOv2, DINOv2-reg) and demonstrate that DVT consistently improves existing state-of-the-art general-purpose models in semantic and geometric tasks across multiple datasets.

Introduction

Vision Transformers (ViTs) have become the standard architecture for many computer vision tasks. However, a persistent problem plagues their internal representations: grid-like artifacts that appear in feature maps. These artifacts are not semantically meaningful; instead, they represent a form of structured noise that correlates with the patch grid. While these patterns may not significantly impact global image classification, they are highly detrimental to dense prediction tasks—such as semantic segmentation, depth estimation, and object discovery—where precise local feature coherence is essential.

Overview of the DVT pipeline showing artifact removal and performance gains across dense prediction tasks.

The Source of Grid Artifacts

The root cause of these artifacts is traced to the positional embeddings (PE) injected at the input stage. PE provides the spatial context necessary for Transformers to process images as sequences of patches. However, because these embeddings are additive and independent of image content, they introduce a spatial bias that propagates through the network. The authors demonstrate this through a "zero-tensor" test: feeding a black image into a ViT results in a feature map that clearly displays the grid artifacts, confirming they are an inherent architectural byproduct rather than a response to image content.

Methodology: Denoising Vision Transformers (DVT)

To mitigate these artifacts without the prohibitive cost of retraining large-scale models, we propose Denoising Vision Transformers (DVT), a two-stage denoising framework.

Stage 1: Per-Image Denoising via Neural Fields

The first stage leverages the observation that while semantic content moves with image transformations (like cropping or flipping), positional artifacts remain anchored to the fixed grid coordinates. By enforcing cross-view feature consistency using a neural field (specifically an InstantNGP-based coordinate network), we decompose the raw ViT output into a clean semantics field and a shared artifact field. This optimization process provides high-quality estimates of clean features for each image.

Stage 2: Generalizable Denoiser

To make the denoising process efficient for real-time inference, we train a lightweight "Generalizable Denoiser." This component consists of a single Transformer block that learns to predict clean features directly from the raw, noisy ViT outputs, using the Stage 1 estimates as supervision. This denoiser is "plug-and-play," adding minimal computational overhead (~8% parameter increase) and requiring no changes to the original ViT weights.

Analysis of the origin of artifacts in positional embeddings and the architecture of the DVT transformer block.

Experimental Results

We evaluated DVT across a variety of models (DINOv2, CLIP, EVA02, etc.) and tasks.

  • Semantic Segmentation: DVT consistently improves mIoU. Notably, a DINOv2-Base model equipped with DVT (84.84 mIoU on VOC2012) can outperform the much larger DINOv2-Giant model (83.0 mIoU).
  • Object Discovery: DVT significantly enhances object discovery performance. For instance, the CorLoc score for DINOv2 on VOC2007 improved from 30.8 to 58.0, nearly doubling the performance by clarifying object boundaries previously obscured by noise.
  • Depth Estimation: Geometric tasks also benefit, with DVT reducing absolute relative error across all tested architectures on the NYUv2 dataset.

Conclusion

Denoising Vision Transformers (DVT) provides an effective, efficient, and architecture-agnostic solution to the problem of grid artifacts in ViTs. By isolating the noise introduced by positional embeddings, DVT enables existing pre-trained models to achieve significantly higher performance in dense prediction tasks. Our findings suggest that future ViT designs should reconsider the naive application of positional embeddings to avoid these artifacts at the source.

Summary updated

BibTeX
@misc{yang2024denoising,
  author = {Jiawei Yang and Katie Z. Luo and Jiefeng Li and Kilian Q. Weinberger and Yonglong Tian and Yue Wang},
  title = {{Denoising Vision Transformers}},
  year = {2024},
  eprint = {2401.02957},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.02957},
}
Figure