VOOZH about

URL: https://www.geeksforgeeks.org/deep-learning/tf-keras-layers-maxpooling2d-maxpooling-in-tensorflow/

⇱ tf.keras.layers.MaxPooling2D : MaxPooling in TensorFlow - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

tf.keras.layers.MaxPooling2D : MaxPooling in TensorFlow

Last Updated : 23 Jul, 2025

Max pooling is a downsampling technique that slides a window (e.g., 2x2) over the input feature map and extracts the maximum value from each window.

This process achieves two key goals:

  1. Dimensionality Reduction: Reduces computational complexity by shrinking the feature map size.
  2. Translation Invariance: Makes the model robust to small spatial shifts in input features.

In TensorFlow, tf.keras.layers.MaxPooling2D implements max pooling operation. Key parameters include:

  • pool_size: Size of the pooling window (e.g., (2, 2)).
  • strides: Step size of the window (defaults to pool_size if not specified).
  • padding: 'valid' (no padding) or 'same' (pad to retain input size).

Implementation with TensorFlow

Here’s how to implement max pooling using tf.keras.layers.MaxPooling2D:

Output:

Input Shape: (1, 4, 4, 1)
Output Shape: (1, 2, 2, 1)
Pooled Output:
[[ 6. 8.]
[14. 16.]]

Max pooling layer is used to reduce overfitting, improve computational efficiency and enhances translation invariance.

Comment