Keras - Layers - Pooling Layers


Pooling layers are used to downsample. They are generally used with convolutional layers to reduce the size of the feature space

MaxPooling*D

Max pooling uses passes the max value over a window to the next layer. There are three different pooling layer dimensions:

  • Conv1D: Ex: temporal data
  • Conv2D: Ex spatial data (images)
  • Conv3D: Ex 3D data (spatial or spatio-temporal)
tf.keras.layers.MaxPooling2D(
    pool_size=(2, 2), 
    strides=None, 
    padding="valid", 
    data_format=None, 
    **kwargs
)
  • Pool Size: Size of the window
  • Strides: How far the window moves after each pooling step (int or tuple of ints)
  • Padding:
    • 'valid': No padding. output_shape = (input_shape - pool_size + 1) / strides)
    • 'same': Output will have the same height/width dimensions as input. output_shape = input_shape / strides
  • Data Format: 'channels_last' or 'channels_first'
AveragePooling*D

Average pooling passes the average value over a window to the next layer. There are three different pooling layer dimensions:

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

Args same as MaxPooling

Other

There are also GlobalMaxPooling and GlobalAveragePooling varients that don't use a window, but the entire input.