liveBook · Manning

Vision Transformer

As explained in Generative AI in Action

A vision transformer is a Transformer-based neural model that processes images by converting image regions into a sequence of representations and applying attention.

A Vision Transformer (ViT) applies Transformer architecture to visual data. It suits flexible, sequence-based image tasks and image recognition, but requires significant computational resources. section 4.1 section 4.1.3

Instead of comparing every pixel with every other pixel, ViT divides an image into small patches, commonly 16 × 16 pixels. It flattens those patches, adds positional embeddings, and feeds the resulting sequence into a Transformer encoder. section 4.1.3

A ViT processes an image through three practical stages:

  • Projects flattened image patches into vectors that form a linear input sequence. section 4.1.3
  • Uses global self-attention to learn relationships among different image regions simultaneously. section 4.1.3
  • Applies multi-head attention and normalization layers before assigning an output class such as Bird, Ball, or Car. section 4.1.3
  • Scales attention cost quadratically with the number of input patches, making patch selection and compute capacity important considerations. section 4.1.3
Figure 4.6 Vision transformer (ViT) architecture [2]
figure

Inspect the architecture diagram to connect patch projection, the Transformer encoder, attention layers, normalization, and output classes. section 4.1.3

Classifying an image

An image is divided into 16 × 16 regions. Each region becomes a vector with positional information, and the encoder learns relationships across the full sequence before selecting a class such as Bird, Ball, or Car. section 4.1.3

How Generative AI in Action covers it

How deep it goes
Explains patch tokenization, positional embeddings, global attention, encoder layers, and quadratic cost without mathematical derivation.
Examples
Uses 16 × 16 image patches and Bird, Ball, and Car class labels to illustrate visual classification.
What it assumes
Builds on Transformer architecture and attention mechanisms while defining their adaptation from sequential text or speech to images.
What you can do after
Evaluate/understand how ViTs convert images into patch sequences and trade global attention against computational cost.
How it connects
Links Transformer architecture with attention mechanisms, positional embeddings, image recognition, and Transformer encoders.

Also explained in

Compare how 7 books explain Vision Transformer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.