liveBook · Manning

Patch

As explained in Deep Learning with Python, Third Edition

A local subregion of an image that is extracted and treated as one sequence element in ViT processing.

A patch is a local image subregion treated as one unit of processing. Convolutions extract patches from feature maps and apply the same transformation at each location, helping models detect spatially repeated patterns such as edges and textures. section 8.1.1

Patches as image sequence elements

A Vision Transformer splits an image into a one-dimensional sequence of patches, flattens each patch into a vector, and processes the resulting sequence. This lets the Transformer model relationships between distant image regions. section 9.6

Use these distinctions when interpreting patches:

  • Treat a convolution patch as a spatial window whose transformed responses remain arranged in a feature map. section 8.1.1
  • Treat a ViT patch as a flattened sequence element rather than as a permanently two-dimensional feature-map location. section 9.6
  • Treat an image patch in a multimodal model as a possible soft token after an image encoder converts it to a vector. section 16.4.2

Gemma image representation

Gemma’s image encoder cuts an image into 256 patches and encodes them as a 256 × 2560 sequence. The resulting vectors can be spliced into the text sequence as 256 image soft tokens. section 16.4.2

Figure 8.1 Images can be broken into local patterns such as edges, textures, and so on.
visual hierarchy hires

Use the image-pattern illustration to connect local patches with visual features such as edges and textures. section 8.1.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines patches as extracted local regions and flattened sequence elements, but defers detailed Transformer mechanics and patch-generation code.
Examples
Uses convolution windows, flattened ViT image sequences, and Gemma’s sequence of 256 image patches.
What you can do after
Evaluate/understand how image regions become convolution inputs, ViT sequence elements, or multimodal soft tokens.
How it connects
Connects convolution, feature maps, Vision Transformers, Transformers, image encoders, and soft tokens.

Also explained in

Compare how 5 books explain patch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.