Pooling Layer in CNN Explained: Max Pooling vs Average Pooling

Pooling Layer in CNN Explained: Max Pooling vs Average Pooling

Understand how pooling reduces dimensions and improves deep learning models.

Author
Nguyen Bao Huy
06:29:00 28/04/2026
3 min read
0 comments

Pooling layer is used in CNNs to reduce the spatial dimensions (width and height) of the input feature maps while retaining the most important information. It involves sliding a two-dimensional filter over each channel of feature map and summarizing the features within the region covered by filter.

For a feature map with dimensions nh×nw×nc​, the dimensions of the output after a pooling layer are:

Figure 1. Dimension formula after apply pooling
Figure 1. Dimension formula after apply pooling
Note: Number of channels remains unchanged.
Figure 2. Formula with padding
Figure 2. Formula with padding

Why are Pooling Layers Important?

  • Dimensionality Reduction: Faster computation, fewer parameters
  • Translation Invariance: Small shifts in image don’t affect output
  • Overfitting Control: Acts as regularization
  • Feature Hierarchy: Helps focus on high-level patterns

Example: Even if a cat moves slightly in an image, pooling ensures the model still recognizes it.

Types of Pooling Layers

1. Max Pooling

Max pooling selects the maximum element from the region of the feature map covered by the filter. Thus, the output after max-pooling layer would be a feature map containing the most prominent features of the previous feature map.

Max pooling layer preserves the most important features (edges, textures, etc.) and provides better performance in most cases

Figure 3. Max pooling
Figure 3. Max pooling

Max Pooling in Keras:

python
from tensorflow.keras.layers import MaxPooling2D
import numpy as np

# Example input feature map
feature_map = np.array([
    [1, 3, 2, 9],
    [5, 6, 1, 7],
    [4, 2, 8, 6],
    [3, 5, 7, 2]
]).reshape(1, 4, 4, 1)

# Applying max pooling
max_pool = MaxPooling2D(pool_size=(2, 2), strides=2)
output = max_pool(feature_map)

print(output.numpy().reshape(2, 2))

Output:

javascript
[[6 9]
 [5 8]]

2. Average Pooling

Average pooling computes the average of the elements present in the region of feature map covered by the filter. Thus, while max pooling gives the most prominent feature in a particular patch of the feature map, average pooling gives the average of features present in a patch.

Average pooling provides a more generalized representation of the input. It is useful in the cases where preserving the overall context is important.

Figure 4. Average Pooling
Figure 4. Average Pooling

Average Pooling using Keras:

python
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import AveragePooling2D

feature_map = np.array([
    [1, 3, 2, 9],
    [5, 6, 1, 7],
    [4, 2, 8, 6],
    [3, 5, 7, 2]
], dtype=np.float32).reshape(1, 4, 4, 1)  # Convert to float32

# Applying average pooling
avg_pool = AveragePooling2D(pool_size=(2, 2), strides=2)
output = avg_pool(feature_map)
print(output.numpy().reshape(2, 2))

Output:

javascript
[[3.75 4.75]
 [3.5  5.75]]

3. Global Pooling

Global pooling reduces each channel in the feature map to a single value, producing a 1×1×nc1×1×nc​ output. This is equivalent to applying a filter of size nh×nwnh​×nw​.

There are two types of global pooling:

  • Global Max Pooling: Takes the maximum value across the entire feature map.
  • Global Average Pooling: Computes the average of all values in the feature map.

Global Pooling using Keras:

python
from tensorflow.keras.layers import GlobalMaxPooling2D, GlobalAveragePooling2D

feature_map = np.array([
    [1, 3, 2, 9],
    [5, 6, 1, 7],
    [4, 2, 8, 6],
    [3, 5, 7, 2]
], dtype=np.float32).reshape(1, 4, 4, 1) 

# Applying global max pooling
gm_pool = GlobalMaxPooling2D()
gm_output = gm_pool(feature_map)

# Applying global average pooling
ga_pool = GlobalAveragePooling2D()
ga_output = ga_pool(feature_map)

print("Global Max Pooling Output:", gm_output.numpy())
print("Global Average Pooling Output:", ga_output.numpy())

Output:

javascript
 Global Max Pooling Output: [[9]]
Global Average Pooling Output: [[4.4375]]

How Pooling Layers Work?

  1. Define a Pooling Window (Filter): The size of the pooling window (e.g., 2x2) is chosen, along with a stride (the step size by which the window moves). A common choice is a 2x2 window with a stride of 2, which reduces the feature map size by half.
  2. Slide the Window Over the Input: The pooling operation is applied to each region of the input feature map covered by the window.
  3. Apply the Pooling Operation: Depending on the type of pooling (max, average, etc.), the operation extracts the required value from each window.
  4. Output the Downsampled Feature Map: The result is a smaller feature map that retains the most important information.

Key Hyperparameters

  • Filter Size (f): Larger = more compression
  • Stride (s): Larger = faster reduction
  • Padding: Ensures edge coverage

Advantages of Pooling Layer

  1. Dimensionality Reduction: Reduces feature map size, lowering computation and helping prevent overfitting.
  2. Translation Invariance: Detects features even if their position shifts in the image.
  3. Feature Selection: Retains important features (max pooling) or captures overall context (average pooling).

Limitations of Pooling Layers

  1. Information Loss: Pooling reduces spatial resolution, which can lead to a loss of important fine details.
  2. Over-smoothing: Excessive pooling may blur out crucial features.
  3. Hyperparameter Tuning: The choice of pooling size and stride affects performance and requires careful tuning.

First Lesson

You are at the beginning of this curriculum.

Latest Tutorial

More chapters coming soon to this topic.

Author avatar

Nguyen Bao Huy

Lead Fullstack & AI Solutions Engineer

Specializing in Next.js App Router, React 19, TypeScript, and modern design systems. Passionate about creating seamless user experiences.

Discussion

0

No comments yet

Be the first to share your thoughts, question a concept, or provide additional tips!

Leave a Reply

Share your insights, questions, or solutions with the developer community.

Your avatar
0 / 500 characters