AveragePooling1DLayer - 1-D average pooling layer - MATLAB (original) (raw)

1-D average pooling layer

Since R2021b

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:

Creation

Syntax

Description

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

example

`layer` = averagePooling1dLayer(`poolSize`,[Name=Value](#namevaluepairarguments)) also specifies the padding or sets the Stride and Name properties 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 of 3, a stride of 2, and padding of size 1 on both the left and right of the input.

example

Name-Value Arguments

expand all

Specify optional pairs of arguments asName1=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,Padding=1) creates a 1-D average 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:

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 regions PoolSize must be greater than or equal to the padding dimensions PaddingSize.

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, where l is the padding applied to the left and r is the padding applied to the right.

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, specified as one of the following:

To specify the layer padding, use the Padding name-value argument.

Data Types: char

Value used to pad input, specified as 0 or"mean".

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

Layer

Data Types: char | string

This property is read-only.

Number of inputs to the layer, stored as 1. This layer accepts a single input only.

Data Types: double

This property is read-only.

Input names, stored as {'in'}. This layer accepts a single input only.

Data Types: cell

This property is read-only.

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

Data Types: double

This property is read-only.

Output names, stored as {'out'}. 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,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 dimensions
 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          10 fully connected layer
 9   ''   Softmax                  softmax

Algorithms

expand all

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 layer pools the input by moving the pooling regions along a single dimension.

Layers in a layer array or layer graph pass data to subsequent layers as formatted dlarray objects. The format of a dlarray object is a string of characters in which each character describes the corresponding dimension of the data. The format consists of one or more of these characters:

For example, you can represent vector sequence data as a 3-D array, in which the first dimension corresponds to the channel dimension, the second dimension corresponds to the batch dimension, and the third dimension corresponds to the time dimension. This representation is in the format "CBT" (channel, batch, time).

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

Layers in a layer array or layer graph pass data to subsequent layers as formatted dlarray objects. The format of a dlarray object is a string of characters in which each character describes the corresponding dimension of the data. The format consists of one or more of these characters:

For example, you can represent vector sequence data as a 3-D array, in which the first dimension corresponds to the channel dimension, the second dimension corresponds to the batch dimension, and the third dimension corresponds to the time dimension. This representation is in the format "CBT" (channel, batch, time).

You can interact with these dlarray objects in automatic differentiation workflows, such as those for developing a custom layer, using a functionLayer object, or using the forward and predict functions withdlnetwork objects.

This table shows the supported input formats of AveragePooling1DLayer objects and the corresponding output format. If the software passes the output of the layer to a custom layer that does not inherit from the nnet.layer.Formattable class, or aFunctionLayer object with the Formattable property set to 0 (false), then the layer receives an unformatted dlarray object with dimensions ordered according to the formats in this table. The formats listed here are only a subset. The layer may support additional formats such as formats with additional "S" (spatial) or"U" (unspecified) dimensions.

Input Format Output Format
"SCB" (spatial, channel, batch) "SCB" (spatial, channel, batch)
"CBT" (channel, batch, time) "CBT" (channel, batch, time)
"SCBT" (spatial, channel, batch, time) "SCBT" (spatial, channel, batch, time)

In dlnetwork objects, AveragePooling1DLayer objects also support these input and output format combinations.

Input Format Output Format
"SC" (spatial, channel) "SC" (spatial, channel)
"CT" (channel, time) "CT" (channel, time)
"SCT" (spatial, channel, time) "SCT" (spatial, channel, time)

Extended Capabilities

expand all

Usage notes and limitations:

Usage notes and limitations:

Version History

Introduced in R2021b