What do Vision Transformers Learn? A Visual Exploration

Amin Ghiasi, Hamid Kazemi, Eitan Borgnia, Steven Reich, Manli Shu +3 more
12/13/2022
cs.CV
transformer-attention

Official code: hamidkazemi22/vit-visualization (195 stars, Shell, last commit 2023-10-12).

Abstract

Vision transformers (ViTs) are quickly becoming the de-facto architecture for computer vision, yet we understand very little about why they work and what they learn. While existing studies visually analyze the mechanisms of convolutional neural networks, an analogous exploration of ViTs remains challenging.

Show full abstract

In this paper, we first address the obstacles to performing visualizations on ViTs. Assisted by these solutions, we observe that neurons in ViTs trained with language model supervision (e.g., CLIP) are activated by semantic concepts rather than visual features. We also explore the underlying differences between ViTs and CNNs, and we find that transformers detect image background features, just like their convolutional counterparts, but their predictions depend far less on high-frequency information. On the other hand, both architecture types behave similarly in the way features progress from abstract patterns in early layers to concrete objects in late layers. In addition, we show that ViTs maintain spatial information in all layers except the final layer. In contrast to previous works, we show that the last layer most likely discards the spatial information and behaves as a learned global pooling operation. Finally, we conduct large-scale visualizations on a wide range of ViT variants, including DeiT, CoaT, ConViT, PiT, Swin, and Twin, to validate the effectiveness of our method.

View on arXivView PDF

Code Implementations(1)

19515Shell, PythonOct 1, 20223 years ago

Similar Papers

Cite this paper

@article{ghiasi2022what,
  title  = {What do Vision Transformers Learn? A Visual Exploration},
  author = {Amin Ghiasi and Hamid Kazemi and Eitan Borgnia and Steven Reich and Manli Shu and Micah Goldblum and Andrew Gordon Wilson and Tom Goldstein},
  year   = {2022},
  eprint = {2212.06727},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2212.06727}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2212.06727.svg)](https://codeofpaper.com/paper/2212.06727)

Discussion