AveragePooling2DLayer - Average pooling layer - MATLAB (original) (raw)

Description

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

Creation

Syntax

Description

`layer` = averagePooling2dLayer([poolSize](#mw%5F6c1dba0c-f907-4e99-8690-dc113e301ffe)) creates an average pooling layer and sets the PoolSize property.

`layer` = averagePooling2dLayer([poolSize](#mw%5F6c1dba0c-f907-4e99-8690-dc113e301ffe),[Name=Value](#namevaluepairarguments)) sets optional properties using one or more name-value arguments.

example

Input Arguments

expand all

Dimensions of the pooling regions, specified as a vector of two positive integers [h w], where h is the height and w is the width. When creating the layer, you can specify poolSize as a scalar to use the same value for both dimensions.

If the stride dimensions Stride are less than the respective pooling dimensions, then the pooling regions overlap.

The padding dimensions PaddingSize must be less than the pooling region dimensions poolSize.

Example: [2 1] specifies pooling regions of height 2 and width 1.

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: averagePooling2dLayer(2,Stride=2) creates an average pooling layer with pool size [2 2] and stride[2 2].

Step size for traversing the input vertically and horizontally, specified as a vector of two positive integers [a b], where a is the vertical step size and b is the horizontal step size. When creating the layer, you can specify Stride as a scalar to use the same value for both dimensions.

If the stride dimensions Stride are less than the respective pooling dimensions, then the pooling regions overlap.

The padding dimensions PaddingSize must be less than the pooling region dimensionsPoolSize.

Example: [2 3] specifies a vertical step size of 2 and a horizontal step size of 3.

Input edge padding, specified as one of these values:

Example: Padding=1 adds one row of padding to the top and bottom, and one column of padding to the left and right of the input.

Example: Padding="same" adds padding so that the output has the same size as the input (if the stride equals 1).

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 name, specified as a character vector or a string scalar. For Layer array input, the trainnet and dlnetwork functions automatically assign names to layers with the name "".

This argument sets the Name property.

Data Types: char | string

Properties

expand all

Average Pooling

Dimensions of the pooling regions, specified as a vector of two positive integers[h w], where h is the height andw is the width. When creating the layer, you can specifyPoolSize as a scalar to use the same value for both dimensions.

If the stride dimensions Stride are less than the respective pooling dimensions, then the pooling regions overlap.

The padding dimensions PaddingSize must be less than the pooling region dimensions PoolSize.

Example: [2 1] specifies pooling regions of height 2 and width 1.

Step size for traversing the input vertically and horizontally, specified as a vector of two positive integers [a b], where a is the vertical step size and b is the horizontal step size. When creating the layer, you can specify Stride as a scalar to use the same value for both dimensions.

If the stride dimensions Stride are less than the respective pooling dimensions, then the pooling regions overlap.

The padding dimensions PaddingSize must be less than the pooling region dimensions PoolSize.

Example: [2 3] specifies a vertical step size of 2 and a horizontal step size of 3.

Size of padding to apply to input borders, specified as a vector[t b l r] of four nonnegative integers, where t is the padding applied to the top, b is the padding applied to the bottom, 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 pair argument to specify the padding size.

Example: [1 1 2 2] adds one row of padding to the top and bottom, and two columns of padding to the left and right of the input.

Method to determine padding size, specified as "manual" or"same".

The software automatically sets the value of PaddingMode based on the Padding value you specify when creating a layer.

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:

Note

Padding property will be removed in a future release. UsePaddingSize instead. When creating a layer, use thePadding name-value argument to specify the padding size.

Size of padding to apply to input borders vertically and horizontally, specified as a vector [a b] of two nonnegative integers, where a is the padding applied to the top and bottom of the input data and b is the padding applied to the left and right.

Example: [1 1] adds one row of padding to the top and bottom, and one column of padding to the left and right of the input.

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 an average pooling layer with the name avg1.

layer = averagePooling2dLayer(2,Name="avg1")

layer = AveragePooling2DLayer with properties:

        Name: 'avg1'

Hyperparameters PoolSize: [2 2] Stride: [1 1] PaddingMode: 'manual' PaddingSize: [0 0 0 0] PaddingValue: 0

Include an average pooling layer in a Layer array.

layers = [ ... imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer averagePooling2dLayer(2) fullyConnectedLayer(10) softmaxLayer]

layers = 6×1 Layer array with layers:

 1   ''   Image Input           28×28×1 images with 'zerocenter' normalization
 2   ''   2-D Convolution       20 5×5 convolutions with stride [1  1] and padding [0  0  0  0]
 3   ''   ReLU                  ReLU
 4   ''   2-D Average Pooling   2×2 average pooling with stride [1  1] and padding [0  0  0  0]
 5   ''   Fully Connected       10 fully connected layer
 6   ''   Softmax               softmax

Create an average pooling layer with nonoverlapping pooling regions.

layer = averagePooling2dLayer(2,'Stride',2)

layer = AveragePooling2DLayer with properties:

        Name: ''

Hyperparameters PoolSize: [2 2] Stride: [2 2] PaddingMode: 'manual' PaddingSize: [0 0 0 0] PaddingValue: 0

The height and width of the rectangular regions (pool size) are both 2. The pooling regions do not overlap because the step size for traversing the images vertically and horizontally (stride) is also 2.

Include an average pooling layer with nonoverlapping regions in a Layer array.

layers = [ ... imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer averagePooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer]

layers = 6×1 Layer array with layers:

 1   ''   Image Input           28×28×1 images with 'zerocenter' normalization
 2   ''   2-D Convolution       20 5×5 convolutions with stride [1  1] and padding [0  0  0  0]
 3   ''   ReLU                  ReLU
 4   ''   2-D Average Pooling   2×2 average pooling with stride [2  2] and padding [0  0  0  0]
 5   ''   Fully Connected       10 fully connected layer
 6   ''   Softmax               softmax

Create an average pooling layer with overlapping pooling regions.

layer = averagePooling2dLayer([3 2],'Stride',2)

layer = AveragePooling2DLayer with properties:

        Name: ''

Hyperparameters PoolSize: [3 2] Stride: [2 2] PaddingMode: 'manual' PaddingSize: [0 0 0 0] PaddingValue: 0

This layer creates pooling regions of size [3 2] and takes the average of the six elements in each region. The pooling regions overlap because Stride includes dimensions that are less than the respective pooling dimensions PoolSize.

Include an average pooling layer with overlapping pooling regions in a Layer array.

layers = [ ... imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer averagePooling2dLayer([3 2],'Stride',2) fullyConnectedLayer(10) softmaxLayer]

layers = 6×1 Layer array with layers:

 1   ''   Image Input           28×28×1 images with 'zerocenter' normalization
 2   ''   2-D Convolution       20 5×5 convolutions with stride [1  1] and padding [0  0  0  0]
 3   ''   ReLU                  ReLU
 4   ''   2-D Average Pooling   3×2 average pooling with stride [2  2] and padding [0  0  0  0]
 5   ''   Fully Connected       10 fully connected layer
 6   ''   Softmax               softmax

Algorithms

expand all

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

The dimensions 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 describe 2-D image data that is represented as a 4-D array, where the first two dimensions correspond to the spatial dimensions of the images, the third dimension corresponds to the channels of the images, and the fourth dimension corresponds to the batch dimension, as having the format "SSCB" (spatial, spatial, channel, batch).

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 AveragePooling2DLayer 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
"SSCB" (spatial, spatial, channel, batch) "SSCB" (spatial, spatial, channel, batch)
"SCBT" (spatial, channel, batch, time) "SCBT" (spatial, channel, batch, time)
"SSCBT" (spatial, spatial, channel, batch, time) "SSCBT" (spatial, spatial, channel, batch, time)
"SSB" (spatial, spatial, batch) "SSB" (spatial, spatial, batch)
"SSC" (spatial, spatial, channel) "SSC" (spatial, spatial, channel)
"SCT" (spatial, channel, time) "SCT" (spatial, channel, time)
"SSCT" (spatial, spatial, channel, time) "SSCT" (spatial, spatial, channel, time)
"SBT" (spatial, batch, time) "SBT" (spatial, batch, time)
"SSBT" (spatial, spatial, batch, time) "SSBT" (spatial, spatial, batch, time)

References

[1] Nagi, J., F. Ducatelle, G. A. Di Caro, D. Ciresan, U. Meier, A. Giusti, F. Nagi, J. Schmidhuber, L. M. Gambardella. ''Max-Pooling Convolutional Neural Networks for Vision-based Hand Gesture Recognition''. IEEE International Conference on Signal and Image Processing Applications (ICSIPA2011), 2011.

Extended Capabilities

expand all

Usage notes and limitations:

Usage notes and limitations:

Version History

Introduced in R2016a