Main Content

averagePooling1dLayer

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 channels, observations, and time steps), the layer pools over the time dimension.

    • For 1-D image input (data with three dimensions corresponding to the spatial pixels, channels, and observations), the layer pools over the spatial dimension.

    • For 1-D image sequence input (data with four dimensions corresponding to the spatial pixels, channels, observations, and time steps), the layer pools over the spatial dimension.

    Creation

    Description

    example

    layer= averagePooling1dLayer(poolSize)创建了一个一维平均池层和设置PoolSizeproperty.

    example

    layer= averagePooling1dLayer(poolSize,Name=Value)还指定了填充或设置StrideandNameproperties using one or more optional name-value arguments. For example,averagePooling1dLayer(3,Padding=1,Stride=2)creates a 1-D average pooling layer with a pool size of3, a stride of2, and padding of size1on both the left and right of the input.

    Input Arguments

    expand all

    Name-Value Arguments

    Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example:averagePooling1dLayer(2,Padding=1)creates a 1-D max pooling layer with a pool size of 3 and padding of size 1 on the left and right of the layer input.

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

    • "same"— Apply padding such that the output size isceil(inputSize/stride), whereinputSizeis the length of the input. WhenStrideis1, the output is the same size as the input.

    • Nonnegative integersz— Add padding of sizeszto both ends of the input.

    • Vector[l r]of nonnegative integers — Add padding of sizelto the left andrto the right of the input.

    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

    Properties

    expand all

    Average Pooling

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

    The width of the pooling regionsPoolSizemust be greater than or equal to the padding dimensionsPaddingSize.

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

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

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

    Size of padding to apply to each side of the input, specified as a vector[l r]of two nonnegative integers, wherelis the padding applied to the left andris the padding applied to the right.

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

    Data Types:double

    This property is read-only.

    Method to determine padding size, specified as one of the following:

    • “手动”– Pad using the integer or vector specified byPadding.

    • 'same'– Apply padding such that the output size isceil(inputSize/Stride), whereinputSizeis the length of the input. WhenStrideis1, the output is the same as the input.

    To specify the layer padding, use thePaddingname-value argument.

    Data Types:char

    Value used to pad input, specified as0or"mean".

    When you use thePaddingoption to add padding to the input, the value of the padding applied can be one of the following:

    • 0— Input is padded with zeros at the positions specified by thePaddingproperty. The padded areas are included in the calculation of the average value of the pooling regions along the edges.

    • "mean"— Input is padded with the mean of the pooling region at the positions specified by thePaddingoption. The padded areas are effectively excluded from the calculation of the average value of each pooling region.

    Layer

    Layer name, specified as a character vector or a string scalar. ForLayerarray input, thetrainNetwork,assembleNetwork,layerGraph, anddlnetworkfunctions automatically assign names to layers with name''.

    Data Types:char|string

    This property is read-only.

    Number of inputs of the layer. This layer accepts a single input only.

    Data Types:double

    This property is read-only.

    Input names of the layer. This layer accepts a single input only.

    Data Types:cell

    This property is read-only.

    Number of outputs of the layer. This layer has a single output only.

    Data Types:double

    This property is read-only.

    Output names of the layer. This layer has a single output only.

    Data Types:cell

    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) convolution1dLayer(11,96) reluLayer averagePooling1dLayer(3) convolution1dLayer(11,96) reluLayer globalMaxPooling1dLayer fullyConnectedLayer(10) softmaxLayer classificationLayer]
    layers = 10x1 Layer array with layers: 1 '' Sequence Input Sequence input with 12 dimensions 2 '' 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 '' 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 10 fully connected layer 9 '' Softmax softmax 10 '' Classification Output crossentropyex

    Algorithms

    expand all

    Version History

    Introduced in R2021b