✳ BETWEEN QUESTIONS ML STUDY ATLAS

A QUESTION-LED LESSON

Vision Transformers: Can an Image Become a Sequence?

A transformer reads tokens. What if those tokens describe pieces of an image?

Patch the image

A vision transformer can divide an image into fixed-size patches, flatten each patch and project it into an embedding. Position information helps the model distinguish their locations.

Apply attention

The resulting patch embeddings can be processed by transformer blocks. A classification model can use a special token or another pooling strategy to produce an image-level prediction. Each colored tile is one image patch. Smaller patches create more patch tokens for the same image.

INTERACTIVE EXPLORATION

Count image patches

For a 32 × 32 image, choose a patch size that divides both sides.

A trade-off

The number of patches affects computation and information available to the model. Our experiment counts patches for a divisible image size; it does not run a transformer.

Check your understanding

How many 16 × 16 patches are in a 32 × 32 image?

Four: two per side.

Keep exploring

How does a transformer work? ↗What is an image grid? ↗

Further reading

Source and further reading ↗