liveBook · Manning

Max pooling

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

Max pooling is a spatial downsampling operation that retains the maximum activation within each local window.

Max pooling is a spatial downsampling operation that divides an image or feature map into local windows and retains the largest value from each window. It reduces height and width while preserving prominent features, making it useful in convolutional networks and U-Net down blocks. section 6.2.3 section 6.3.1

Process each pooling operation as follows:

  • Choose a kernel size, such as 2 × 2 or 3 × 3, to define each local window. section 6.2.3
  • Move the window by the configured stride; a stride of 2 advances two pixels horizontally and vertically. section 6.2.3
  • Select the maximum value inside every window and place it in the downsampled feature map. section 6.2.3
  • With nn.MaxPool2d(2), a U-Net down block reduces input width and height by half. section 6.3.1

A 4 × 4 tensor with 2 × 2 pooling

Applying torch.nn.MaxPool2d(2) with the default stride to a 4 × 4 input produces [[2, 4], [5, 7]]. Each output value is the largest value in one non-overlapping 2 × 2 region. 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

Use the numerical figure to trace each 2 × 2 window, its selected maximum, and the resulting downsampled output. section 6.2.3

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

How deep it goes
Explains windows, kernel size, stride, numerical output, and PyTorch usage, but does not develop pooling internals.
Examples
Demonstrates a 4 × 4 tensor, 2 × 2 windows, stride 2, and the output tensor [[2, 4], [5, 7]].
What it assumes
Assumes familiarity with images, tensors, and convolutional layers while teaching kernel size, stride, windows, and maxima.
What you can do after
Apply it via PyTorch's nn.MaxPool2d(2) and verify its output on image tensors.
How it connects
Connects max pooling to convolutional layers, feature maps, U-Net down blocks, transposed convolution, and residual networks.

Also explained in

Compare how 10 books explain max 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.