After convolution, pooling reduces the spatial dimensions of feature maps. Two purposes: cheaper computation in subsequent layers, and a degree of spatial invariance — the exact position of a feature matters less.
MaxPooling2D takes the max value in each pool window. Most common; preserves the strongest activations. AveragePooling2D takes the mean — used in some architectures, generally weaker for classification.
GlobalAveragePooling2D is the modern replacement for Flatten + Dense. It averages each entire feature map down to a single value: (batch, h, w, channels) → (batch, channels). ResNet, EfficientNet, MobileNet all use this — dramatically fewer parameters than Flatten, and it acts as a structural regularizer.
Modern alternative: instead of Conv → MaxPool, use Conv with stride=2 for learned downsampling. The network decides how to combine spatial info, rather than applying a fixed max operation.
Code
Pooling 종류들·python
from keras import layers
# MaxPooling — most common
max_pool = layers.MaxPooling2D(pool_size=2, strides=2)
# Input (batch, 32, 32, 64) → Output (batch, 16, 16, 64)
avg_pool = layers.AveragePooling2D(pool_size=2)
# GlobalAveragePooling2D — modern replacement for Flatten
# Input (batch, 8, 8, 256) → Output (batch, 256)
global_avg = layers.GlobalAveragePooling2D()
global_max = layers.GlobalMaxPooling2D()
# Flatten — only when GlobalAvgPool isn't appropriate
flat = layers.Flatten()
# Input (batch, h, w, c) → Output (batch, h*w*c)