GlobalAveragePooling2DLayer - 2-D global average pooling layer - MATLAB (original) (raw)

2-D global average pooling layer

Description

A 2-D global average pooling layer performs downsampling by computing the mean of the height and width dimensions of the input.

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

Creation

Syntax

Description

`layer` = globalAveragePooling2dLayer creates a global average pooling layer.

`layer` = globalAveragePooling2dLayer('Name',name) sets the optional Name property.

example

Properties

expand all

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 global average pooling layer with the name gap1.

layer = globalAveragePooling2dLayer(Name="gap1")

layer = GlobalAveragePooling2DLayer with properties:

Name: 'gap1'

Include a global average pooling layer in a Layer array.

layers = [ ... imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer globalAveragePooling2dLayer 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 Global Average Pooling   2-D global average pooling
 5   ''   Fully Connected              10 fully connected layer
 6   ''   Softmax                      softmax

Tips

Algorithms

expand all

A 2-D global average pooling layer performs downsampling by computing the mean of the height and width dimensions of the input.

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

Global pooling layers remove the "T" (time) dimension when the pool over the "T" (time) dimension. Global pooling layers do not remove the "S" (spatial) dimension when the pool over the "S" (spatial) 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 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 GlobalAveragePooling2DLayer 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) "SCB" (spatial, channel, batch)
"SSCBT" (spatial, spatial, channel, batch, time) "SSCBT" (spatial, spatial, channel, batch, time)
"SSC" (spatial, spatial, channel) "SSC" (spatial, spatial, channel)
"SSB" (spatial, spatial, batch) "SSB" (spatial, spatial, batch)

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

Input Format Output Format
"SCT" (spatial, channel, time) "SC" (spatial, channel)
"SSCT" (spatial, spatial, channel, time) "SSCT" (spatial, spatial, channel, time)
"SBT" (spatial, batch, time) "SB" (spatial, batch)
"SSBT" (spatial, spatial, batch, time) "SSBT" (spatial, spatial, batch, time)

GlobalAveragePooling2DLayer objects support complex-valued input and outputs. (since R2024a) The layer applies the same underlying operation to complex-valued input as it does to real-valued input and outputs complex-valued data where applicable.

Extended Capabilities

expand all

Usage notes and limitations:

Refer to the usage notes and limitations in the C/C++ Code Generation section. The same limitations apply to GPU code generation.

Version History

Introduced in R2019b

expand all

GlobalAveragePooling2DLayer objects support complex-valued input and outputs. The layer applies the same underlying operation to complex-valued input as it does to real-valued input and outputs complex-valued data where applicable.