liveBook · Manning

Pooling

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

A pooling layer aggregates values within local spatial windows to produce a reduced or transformed feature representation.

Pooling aggregates values inside local spatial windows to reduce feature-map dimensions and produce more compact representations. In convolutional networks, it improves computational efficiency while preserving prominent features. section 6.5 section 6.2.3

A max-pooling operation proceeds in four stages:

  • Divide the image or feature map into local windows, such as 2 × 2 or 3 × 3 patches. section 6.2.3
  • Set the stride to determine how far the window moves between operations; a stride of 2 advances two pixels horizontally and vertically. section 6.2.3
  • Select the largest value in each window and use it as that window’s output. section 6.2.3
  • Place the reduced feature map in the contracting path, where repeated convolution and pooling blocks capture increasingly abstract features. section 6.2.2

Max pooling in PyTorch

For a 4 × 4 single-channel tensor, torch.nn.MaxPool2d(2) applies a 2 × 2 window with stride 2 and produces [[2, 4], [5, 7]]. section 6.2.3

Figure 6.5 A numerical example of how max pooling works, with a kernel size of 2 × 2 and a stride equal to 2

Inspect the numerical window-by-window calculation behind 2 × 2 max pooling with stride 2. section 6.2.3

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

How deep it goes
Explains windows, kernels, strides, maxima, and a PyTorch calculation, but does not develop pooling gradients or padding.
Examples
Uses a 4 × 4 tensor, 2 × 2 windows, stride 2, and the output [[2, 4], [5, 7]].
What it assumes
Assumes basic images, feature maps, convolutional layers, and tensor shapes while teaching pooling windows and strides explicitly.
What you can do after
Apply it via PyTorch’s MaxPool2d layer to downsample image tensors and verify the resulting values.
How it connects
Connects pooling with convolutional layers, U-Net encoder-decoder paths, bottlenecks, transposed convolutions, skip connections, and average pooling.

Also explained in

Compare how 8 books explain pooling →

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.