liveBook · Manning

Downsampling

As explained in Build a Text-to-Image Generator (from Scratch)

Downsampling is the reduction of the spatial resolution of a representation.

Downsampling reduces a representation's spatial resolution. In image models, convolutional and pooling layers shrink feature maps while extracting increasingly abstract patterns such as edges, textures, and shapes. section 6.2 section 6.5

Trace downsampling through an encoder–decoder architecture:

  • Process the input through convolutional blocks that detect patterns and pooling or strided operations that reduce height and width. section 6.5
  • Increase feature depth as spatial dimensions decrease, producing a compact representation with more abstract information. section 5.2
  • Pass the smallest, most condensed feature maps through the bottleneck before reconstruction. section 6.5
  • Recover spatial resolution with upsampling and preserve fine detail through skip connections from the downsampling path. section 6.5

A 16× latent reduction

A VQGAN encoder applies four strided convolutions, each halving resolution. A 384×384 image therefore becomes a 24×24 latent grid containing 576 feature vectors, each with 256 channels. section 11.5.2

Listing 5.5 Importing a U-Net model from the diffusers library
import diffusers, torch

device="cuda" if torch.cuda.is_available() else "cpu"
model=diffusers.UNet2DModel(sample_size=32,  #1
                    in_channels=1,
                    out_channels=1,layers_per_block=2,
    block_out_channels=(128,128,256,512),  #2
    down_block_types=("DownBlock2D","DownBlock2D",  #3
                      "AttnDownBlock2D","DownBlock2D",),
    up_block_types=("UpBlock2D","AttnUpBlock2D",  #4
                "UpBlock2D","UpBlock2D",),).to(device)

Inspect a diffusion U-Net configuration that separates downsampling blocks from upsampling blocks and increases feature channels across encoder stages. section 5.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Explains sequential encoder reduction, channel growth, bottleneck processing, and detail recovery, but does not derive pooling or convolution mathematics.
Examples
Uses diffusion U-Net feature maps and VQGAN’s 384×384-to-24×24 latent encoding as concrete reduction examples.
What it assumes
Assumes familiarity with image tensors and neural-network layers while introducing feature maps, spatial dimensions, channels, and encoder–decoder paths.
What you can do after
Evaluate how encoder stages trade spatial detail for compact, abstract feature representations in diffusion and VQGAN architectures.
How it connects
Connects convolutional layers, pooling, strided convolutions, U-Net, encoder–decoder architecture, bottlenecks, upsampling, and skip connections.

Also explained in

Compare how 5 books explain downsampling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.