liveBook · Manning

Max pooling

As explained in Deep Learning with Python, Third Edition

A two-dimensional pooling layer that downsamples feature maps by taking local maxima.

A ConvNet needs to shrink its feature maps as it builds larger-scale visual patterns. Max pooling does this by taking the largest value in each local window, separately for each channel. Unlike a convolution, it uses a fixed maximum operation rather than a learned kernel. section 8.1.2

A first pooling layer

For MNIST digits, a Conv2D layer produces a 26 × 26 × 64 feature map. MaxPooling2D(pool_size=2) reduces it to 13 × 13 × 64: height and width halve, while the channel count stays at 64. A typical choice is a 2 × 2 window with stride 2. section 8.1 section 8.1.2

Listing 8.1 Instantiating a small ConvNet
import keras
from keras import layers

inputs = keras.Input(shape=(28, 28, 1))
x = layers.Conv2D(filters=64, kernel_size=3, activation="relu")(inputs)
x = layers.MaxPooling2D(pool_size=2)(x)
x = layers.Conv2D(filters=128, kernel_size=3, activation="relu")(x)
x = layers.MaxPooling2D(pool_size=2)(x)
x = layers.Conv2D(filters=256, kernel_size=3, activation="relu")(x)
x = layers.GlobalAveragePooling2D()(x)
outputs = layers.Dense(10, activation="softmax")(x)
model = keras.Model(inputs=inputs, outputs=outputs)

See how two MaxPooling2D layers are placed between Conv2D layers before global average pooling and classification. section 8.1

Why keep the downsampling stages?

  • Later convolution layers can draw on a greater spatial extent of the original image, supporting a hierarchy of features. section 8.1.2 section 20.1.6
  • Feature maps remain manageable as channel counts grow. Without pooling, the MNIST example ends with a 22 × 22 map rather than a 3 × 3 map before global averaging, which can discard much more spatial information. section 8.1.2 section 20.1.6

For larger images, add pooling stages as needed: a 180 × 180 dogs-versus-cats classifier alternates Conv2D and MaxPooling2D until its maps reach 7 × 7 before global average pooling. Check the model summary as you build; spatial dimensions should decrease while feature depth can increase. section 8.2.3

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines channel-wise local maxima and typical window and stride settings, then explains architectural tradeoffs without a mathematical derivation.
Examples
Uses MNIST layer shapes, a no-pooling comparison, and a larger dogs-versus-cats ConvNet.
What it assumes
Assumes familiarity with Dense layers and the Keras Functional API while explaining the pooling operation itself.
What you can do after
Apply it via Keras MaxPooling2D between convolution layers and inspect how feature-map dimensions change.
How it connects
Connects convolution, strided convolution, spatial feature hierarchies, and global average pooling.

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 Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.