Skip to content
StackDecode
AI & ML Atlas
Deep LearningarchitectureAnimated walkthrough

Vision Transformer (ViT)

Applies a transformer to an image cut into patches.

The idea

An image is split into fixed-size patches (such as 16×16), each patch is flattened and linearly projected to a token, position embeddings are added, and a standard transformer encoder processes the sequence. A special class token gathers the information for classification. With enough data it matches or beats CNNs.

Watch it run

The pipeline lights up one step at a time. Use the controls to pause or step through it.

  1. 1Cut the image into patches.
  2. 2Flatten and project each patch to an embedding.
  3. 3Add position embeddings and a class token.
  4. 4Run the transformer encoder.
  5. 5Classify from the class token.
1/5

Step by step

  1. 1Cut the image into patches.
  2. 2Flatten and project each patch to an embedding.
  3. 3Add position embeddings and a class token.
  4. 4Run the transformer encoder.
  5. 5Classify from the class token.

Where it is used

Image classification, backbones for detection and segmentation.

Watch out for

Needs more data than CNNs because it has fewer built-in image assumptions.

Related