Different Pooling Layers for CNN

Jacob Heyman
2 min readMar 27, 2021

A quick guide pooling layers when building a CNN

What are Pooling Layers

Pooling layers are an essential component of to a convoluted neural nets architecture. Pooling layers act to subsample the input image. Subsampling the image helps alleviate the computational load of the CNN and can help with overfitting the model. Pooling layers operate similarly to convolutional layers where the neurons are correlated to the output of neurons from the previous layer. Pooling layers differ from convolutional layers by having no weighted values. The pooling acts only to aggregate values with varying aggregation functions. When building a CNN two options for pooling are Maxpooling, AveragePooling. Each of these functions comes with their own unique properties.

MaxPooling

Maxpooling aggregates data by finding the max value of the pooling layers pool size. The of the pooling window is dictated by the pool size and the strides for the window to be shifted. By sampling for the max values in the image, we are defining features with the highest contrast. This can be an invaluable tool for training the model to be invariant for specific features (able to identify key features in various locations of an image).

tf.keras.layers.MaxPooling2D(
pool_size=(2, 2), strides=None, padding="valid", data_format=None, **kwargs
)

Above is the default code for instantiating maxpooling for a 2D image. The pool size, number of strides and padding can all be customized for your particular CNN.

AveragePooling

Where Maxpooling finds the maximum values of the pooling layer, average pooling finds the average values. The averaged layers may not be as defined as Maxpooling layers, but Averagepooling can be advantageous for its ability to better preserve feature localization.

tf.keras.layers.AveragePooling2D(
pool_size=(2, 2), strides=None, padding="valid", data_format=None, **kwargs
)

Code for average pooling is very similar to the maxpooling code above.

--

--