Pooling aggregates convolutional outputs and reduces their spatial size before later layers. In a CNN, this can shrink the model substantially and may improve generalization. section 7.1.1
A practical pooling workflow includes:
- Place a MaxPooling2D layer after convolution, commonly with a (2, 2) pool and same padding. section 7.1.1
- Inspect the model summary to compare parameter counts; adding pooling reduced the demonstrated model to roughly one-quarter its previous size. section 7.1.1
- Change the pooling size, kernel size, or number of convolutional layers and rerun training to observe architectural effects. section 7.1.2
Pooling in a CNN
A convolutional model can place BatchNormalization and MaxPooling2D((2, 2), padding="same") between Conv2D and Flatten. The resulting model has fewer trained parameters and shows improving validation accuracy in the demonstrated experiment. section 7.1.1
Pooling in an autoencoder
An encoder can apply MaxPool2D after each convolution, progressively shrinking a 28×28 input until a final pooling layer forms the latent view. UpSampling2D then expands that representation in the decoder. section 8.1.2
Listing 7.6 EDL_7_1_Keras_CNN.ipynb: Adding pooling
model = models.Sequential() model.add(layers.Conv2D(64, (3, 3), activation='relu', padding="same", input_shape=(28, 28, 1))) #1 model.add(layers.BatchNormalization()) #2 model.add(layers.MaxPooling2D((2, 2), padding="same")) #3 model.add(layers.Flatten()) model.add(layers.Dense(128, activation='relu')) model.add(layers.Dense(10)) model.summary() ... ================================================================= Total params: 1,607,946 Trainable params: 1,607,818 #4 Non-trainable params: 128 _________________________________________________________________
Inspect the complete Keras CNN listing, including convolution, batch normalization, MaxPooling2D, flattening, dense layers, and the model summary. section 7.1.1







