Computer Vision Lab Algorithms Pooling

Pooling

Shrinking the feature map by taking the maximum or the mean in each window.

In the browserConvolution and neural networksNeural networks

This content was prepared automatically from documented sources and its human scientific review is not yet complete. If you find an error, let us know.

Mathematical formula

y_{ij} = \max_{(m,n)\in R_{ij}} x_{mn}\quad\text{or}\quad \frac{1}{|R_{ij}|}\sum_{(m,n)\in R_{ij}} x_{mn}

Explanation

It reduces the dimensions and the compute and gives some invariance to small shifts. Global average pooling turns each channel into a single number before the classification layer.

Detailed explanation

Intuition

Pooling summarises each small window with a single value: the maximum (max) or the mean (average). So it shrinks the map, reduces compute in the following layers, enlarges the receptive field, and gives some invariance to small shifts: if a pattern moves by a pixel within the window, the maximum may stay the same.

How it works step by step

  1. Choose the window size and the stride (usually 2×2 with a stride of 2, which halves the resolution).
  2. For each window: compute the maximum or the mean for each channel separately.
  3. Global pooling: a window the size of the whole map, which turns C\times H\times W into a vector C.

Mathematical formulation

y_{ij} = \max_{(m,n)\in R_{ij}} x_{mn}\quad\text{or}\quad y_{ij} = \frac{1}{|R_{ij}|}\sum_{(m,n)\in R_{ij}} x_{mn}

The gradient of max pooling passes only to the element that was the maximum in the window; the gradient of average pooling is distributed equally over all the elements.

Computational complexity

O(HWC), with no learnable parameters.

Advantages

  • Reduces compute and memory.
  • Global pooling lets the network accept any input size, and reduces overfitting compared with huge fully connected layers.

Limitations

  • It discards precise spatial information, which matters for segmentation and detection.
  • Many modern architectures replace it with a learnable strided convolution.

When do you use it?

In classical convolutional classifiers; and global average pooling at the end of most modern classifiers before the linear layer.

Code example (PyTorch)

import torch.nn as nn
pool = nn.MaxPool2d(kernel_size=2, stride=2)
gap = nn.AdaptiveAvgPool2d(1)   # global pooling

Applications

Convolutional networks for classification.

Limitations

It loses precise spatial information.

References

  1. I. Goodfellow, Y. Bengio, A. Courville (2016).Deep Learning. MIT Press. www.deeplearningbook.org
  2. V. Dumoulin, F. Visin (2016).A guide to convolution arithmetic for deep learning. arXiv:1603.07285. doi:10.48550/arXiv.1603.07285

Experiments that use this algorithm

Related models

Related lessons

Try it in convolution and neural networks