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.