Vision Transformers
Table of contents
▪ Image Patches and Tokens
A Vision Transformer (ViT) divides an image into patches and maps each patch to a feature vector, or token. Positional embeddings preserve information about where patches occur. The original ViT also introduces a class token whose final representation supports image classification.
▪ Self-Attention
Self-attention lets each token combine information from other tokens. Transformer blocks alternate attention and feed-forward processing to refine the representations. Patch size and image resolution determine the number of tokens and influence computation and spatial detail.
▪ Architecture and Training
ViT describes a network architecture, rather than a single training objective or vision task. A classifier can use a global representation, while other methods use the patch features. DINOv2 provides an example of training ViT backbones through self-supervision. A useful first exercise is to trace the tensor shapes from image patches to final features.
▪ References
- Dosovitskiy et al. An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale.
- Google Research. Vision Transformer implementation.