average pooling operation for 2d spatial data downsamples the input along its spatial dimensions height and width by taking the average value over an input window of size defined by poolsize for each channel of the input the window is shifted by strides along each dimension the resulting output when using the valid padding option has a spatial shape number of rows or columns of outputshape math floorinputshape poolsize strides 1 when inputshape poolsize the resulting output shape when using the same padding option is outputshape math floorinputshape 1 strides 1 args poolsize int or tuple of 2 integers factors by which to downscale dim1 dim2 if only one integer is specified the same window length will be used for all dimensions strides int or tuple of 2 integers or none strides values if none it will default to poolsize if only one int is specified the same stride size will be used for all dimensions padding string either valid or same caseinsensitive valid means no padding same results in padding evenly to the leftright or updown of the input such that output has the same heightwidth dimension as the input dataformat string either channelslast or channelsfirst the ordering of the dimensions in the inputs channelslast corresponds to inputs with shape batch height width channels while channelsfirst corresponds to inputs with shape batch channels height width it defaults to the imagedataformat value found in your keras config file at keraskeras json if you never set it then it will be channelslast input shape if dataformatchannelslast 4d tensor with shape batchsize height width channels if dataformatchannelsfirst 4d tensor with shape batchsize channels height width output shape if dataformatchannelslast 4d tensor with shape batchsize pooledheight pooledwidth channels if dataformatchannelsfirst 4d tensor with shape batchsize channels pooledheight pooledwidth examples strides1 1 and paddingvalid x np array1 2 3 4 5 6 7 8 9 x np reshapex 1 3 3 1 avgpool2d keras layers averagepooling2dpoolsize2 2 strides1 1 paddingvalid avgpool2dx strides2 2 and paddingvalid x np array1 2 3 4 5 6 7 8 9 10 11 12 x np reshapex 1 3 4 1 avgpool2d keras layers averagepooling2dpoolsize2 2 strides2 2 paddingvalid avgpool2dx stride1 1 and paddingsame x np array1 2 3 4 5 6 7 8 9 x np reshapex 1 3 3 1 avgpool2d keras layers averagepooling2dpoolsize2 2 strides1 1 paddingsame avgpool2dx average pooling operation for 2d spatial data downsamples the input along its spatial dimensions height and width by taking the average value over an input window of size defined by pool_size for each channel of the input the window is shifted by strides along each dimension the resulting output when using the valid padding option has a spatial shape number of rows or columns of output_shape math floor input_shape pool_size strides 1 when input_shape pool_size the resulting output shape when using the same padding option is output_shape math floor input_shape 1 strides 1 args pool_size int or tuple of 2 integers factors by which to downscale dim1 dim2 if only one integer is specified the same window length will be used for all dimensions strides int or tuple of 2 integers or none strides values if none it will default to pool_size if only one int is specified the same stride size will be used for all dimensions padding string either valid or same case insensitive valid means no padding same results in padding evenly to the left right or up down of the input such that output has the same height width dimension as the input data_format string either channels_last or channels_first the ordering of the dimensions in the inputs channels_last corresponds to inputs with shape batch height width channels while channels_first corresponds to inputs with shape batch channels height width it defaults to the image_data_format value found in your keras config file at keras keras json if you never set it then it will be channels_last input shape if data_format channels_last 4d tensor with shape batch_size height width channels if data_format channels_first 4d tensor with shape batch_size channels height width output shape if data_format channels_last 4d tensor with shape batch_size pooled_height pooled_width channels if data_format channels_first 4d tensor with shape batch_size channels pooled_height pooled_width examples strides 1 1 and padding valid x np array 1 2 3 4 5 6 7 8 9 x np reshape x 1 3 3 1 avg_pool_2d keras layers averagepooling2d pool_size 2 2 strides 1 1 padding valid avg_pool_2d x strides 2 2 and padding valid x np array 1 2 3 4 5 6 7 8 9 10 11 12 x np reshape x 1 3 4 1 avg_pool_2d keras layers averagepooling2d pool_size 2 2 strides 2 2 padding valid avg_pool_2d x stride 1 1 and padding same x np array 1 2 3 4 5 6 7 8 9 x np reshape x 1 3 3 1 avg_pool_2d keras layers averagepooling2d pool_size 2 2 strides 1 1 padding same avg_pool_2d x
from keras.api_export import keras_export
from keras.layers.pooling.base_pooling import BasePooling


@keras_export(["keras.layers.AveragePooling2D", "keras.layers.AvgPool2D"])
class AveragePooling2D(BasePooling):
    

    def __init__(
        self,
        pool_size,
        strides=None,
        padding="valid",
        data_format="channels_last",
        name=None,
        **kwargs
    ):
        super().__init__(
            pool_size,
            strides,
            pool_dimensions=2,
            pool_mode="average",
            padding=padding,
            data_format=data_format,
            name=name,
            **kwargs,
        )