Main Content

averagePooling1dLayer

R2026b

1-D average pooling layer

    Description

    A 1-D average pooling layer performs downsampling by dividing the input into 1-D pooling regions, then computing the average of each region.

    The dimension that the layer pools over depends on the layer input:

    • For time series and vector sequence input (data with three dimensions corresponding to the "C" (channel), "B" (batch), and "T" (time) dimensions), the layer pools over the "T" (time) dimension.

    • For 1-D image input (data with three dimensions corresponding to the "S" (spatial), "C" (channel), and "B" (batch) dimensions), the layer pools over the "S" (spatial) dimension.

    • For 1-D image sequence input (data with four dimensions corresponding to the "S" (spatial), "C" (channel), "B" (batch), and "T" (time) dimensions), the layer pools over the "S" (spatial) dimension.

    Creation

    Description

    layer = averagePooling1dLayer(poolSize) creates a 1-D average pooling layer and sets the PoolSize property.

    example

    layer = averagePooling1dLayer(poolSize,Name=Value) specifies options using one or more name-value arguments. For example, averagePooling1dLayer(3,Stride=2) creates a 1-D average pooling layer with a pool size of three and a stride of two.

    example

    Input Arguments

    expand all

    Width of the pooling regions, specified as a positive integer.

    The width of the pooling regions must be greater than or equal to the PaddingSize values.

    This argument sets the PoolSize property.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Name-Value Arguments

    expand all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: averagePooling1dLayer(3,Stride=2) creates a 1-D average pooling layer with a pool size of three and a stride of two.

    Padding to apply to the input, specified as one of the following:

    • "same" — Apply padding such that the output size is ceil(inputSize/stride), where inputSize is the length of the input. When Stride is 1, the output is the same size as the input.

    • Nonnegative integer sz — Add padding of size sz to both ends of the input.

    • Vector [l r] of nonnegative integers — Add padding of size l to the left and r to the right of the input.

    This argument sets the PaddingSize and PaddingMode properties.

    Example: Padding=[2 1] adds padding of size 2 to the left and size 1 to the right.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string

    Step size for traversing the input, specified as a positive integer.

    If the stride size is less than the pooling window size, then the pooling regions overlap.

    This argument sets the Stride property.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Value used to pad input, specified as one of these:

    • 0 — Pad the input with zeros.

    • "mean" — Pad the input with the mean of the pooling region.

    Specify the padding approach using the Padding name-value argument.

    The layer includes the padded areas when it calculates of the average value of the pooling regions along the edges. Using the mean value as the padding value reduces the effect of the padding values on the calculated average values.

    This argument sets the PaddingValue property

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string

    Layer name, specified as a character vector or a string scalar. For Layer array input, the trainnet and dlnetwork functions automatically assign names to unnamed layers.

    This argument sets the Name property.

    Data Types: char | string

    Properties

    expand all

    Average Pooling

    This property is read-only after object creation. To set this property, use the corresponding positional input argument when you create the AveragePooling1DLayer object.

    Width of the pooling regions, represented as a positive integer.

    The width of the pooling regions must be greater than or equal to the padding dimensions PaddingSize.

    Data Types: double

    Step size for traversing the input, specified as a positive integer.

    If the stride size is less than the pooling window size, then the pooling regions overlap.

    Data Types: double

    Size of padding to apply to each side of the input, specified as a vector [l r] of two nonnegative integers, where l is the padding applied to the left and r is the padding applied to the right. To use the same value for both the left and right sizes, you can also specify a scalar value.

    When you create a layer, use the Padding name-value argument to specify the padding size.

    Data Types: double

    This property is read-only.

    Method to determine padding size, represented as one of these:

    • 'manual' – Pad using the integer or vector specified by the Padding name-value argument.

    • 'same' – Apply padding such that the output size is ceil(inputSize/Stride), where inputSize is the length of the input. When Stride is 1, the output is the same as the input.

    When you create a layer, use the Padding name-value argument to specify the method to determine padding size.

    Value used to pad input, specified as one of these:

    • 0 — Pad the input with zeros.

    • 'mean' — Pad the input with the mean of the pooling region.

    Specify the padding approach using the Padding name-value argument.

    The layer includes the padded areas when it calculates of the average value of the pooling regions along the edges. Using the mean value as the padding value reduces the effect of the padding values on the calculated average values.

    Data Types: double | char

    Layer

    Layer name, specified as a character vector. For Layer array input, the trainnet and dlnetwork functions automatically assign names to unnamed layers.

    Data Types: char

    This property is read-only.

    Number of inputs to the layer, represented as 1. This layer has a single input only.

    Data Types: double

    This property is read-only.

    Input name, represented as {'in'}. This layer has a single input only.

    This property is read-only.

    Number of outputs from the layer, represented as 1. This layer has a single output only.

    Data Types: double

    This property is read-only.

    Output name, represented as {'out'}. This layer has a single output only.

    Examples

    collapse all

    Create a 1-D average pooling layer with a pool size of 3.

    layer = averagePooling1dLayer(3)
    layer = 
      AveragePooling1DLayer with properties:
    
                Name: ''
    
       Hyperparameters
            PoolSize: 3
              Stride: 1
         PaddingMode: 'manual'
         PaddingSize: [0 0]
        PaddingValue: 0
    
    

    Include a 1-D average pooling layer in a layer array.

    layers = [
        sequenceInputLayer(12,MinLength=40)
        convolution1dLayer(11,96)
        reluLayer
        averagePooling1dLayer(3)
        convolution1dLayer(11,96)
        reluLayer
        globalMaxPooling1dLayer
        fullyConnectedLayer(10)
        softmaxLayer]
    layers = 
      9×1 Layer array with layers:
    
         1   ''   Sequence Input           Sequence input with 12 channels
         2   ''   1-D Convolution          96 11 convolutions with stride 1 and padding [0  0]
         3   ''   ReLU                     ReLU
         4   ''   1-D Average Pooling      Average pooling with pool size 3, stride 1, and padding [0  0]
         5   ''   1-D Convolution          96 11 convolutions with stride 1 and padding [0  0]
         6   ''   ReLU                     ReLU
         7   ''   1-D Global Max Pooling   1-D global max pooling
         8   ''   Fully Connected          Fully connected layer with output size 10
         9   ''   Softmax                  Softmax
    

    Algorithms

    expand all

    Extended Capabilities

    expand all

    Version History

    Introduced in R2021b