In addition to convolutional layers, convolutional neural networks often use another type of layer called a pooling layer. Pooling layers are used to reduce the dimensionality of a convolutional network as layers of convolutions are added, which reduces overfitting. They have the added benefit of making the feature detectors somewhat more robust.
Pooling layers divide a matrix into non-overlapping sections, and then typically take the maximum value (in the case of max pooling) in each region. Alternatively, an average can be employed; however, it is rarely used at this time. The following figure illustrates this technique:
Pooling layers are quite easy to implement in Keras, as we'd expect. The following code can be used for pooling the layers:
from keras.layers import MaxPooling2D
pool1 = MaxPooling2D(pool_size=(2, 2), name="pool_1")
Here, we're defining the pooling window as 2 x 2.