Main Content

globalAveragePooling3dLayer

3-D global average pooling layer

Since R2019b

Description

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

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

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

  • For 3-D image sequence input (data with six dimensions corresponding to the pixels in three spatial dimensions, the channels, the observations, and the time steps), the layer pools over the spatial dimensions.

  • For 2-D image sequence input (data with five dimensions corresponding to the pixels in two spatial dimensions, the channels, the observations, and the time steps), the layer pools over the spatial and time dimensions.

Creation

Description

layer = globalAveragePooling3dLayer creates a 3-D global average pooling layer.

example

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

Properties

expand all

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 "".

The GlobalAveragePooling3DLayer object stores this property as a character vector.

Data Types: char | string

This property is read-only.

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

Data Types: double

This property is read-only.

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

Data Types: cell

This property is read-only.

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

Data Types: double

This property is read-only.

Output names, returned as {'out'}. This layer has a single output only.

Data Types: cell

Examples

collapse all

Create a 3-D global average pooling layer with the name 'gap1'.

layer = globalAveragePooling3dLayer('Name','gap1')
layer = 
  GlobalAveragePooling3DLayer with properties:

    Name: 'gap1'

Include a 3-D global average pooling layer in a Layer array.

layers = [ ...
    image3dInputLayer([28 28 28 3])
    convolution3dLayer(5,20)
    reluLayer
    globalAveragePooling3dLayer
    fullyConnectedLayer(10)
    softmaxLayer]
layers = 
  6x1 Layer array with layers:

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

Tips

  • In an image classification network, you can use a globalAveragePooling3dLayer before the final fully connected layer to reduce the size of the activations without sacrificing performance. The reduced size of the activations means that the downstream fully connected layers will have fewer weights, reducing the size of your network.

  • You can use a globalAveragePooling3dLayer towards the end of a classification network instead of a fullyConnectedLayer. Since global pooling layers have no learnable parameters, they can be less prone to overfitting and can reduce the size of the network. These networks can also be more robust to spatial translations of input data. You can also replace a fully connected layer with a globalMaxPooling3dLayer instead. Whether a globalMaxPooling3dLayer or a globalAveragePooling3dLayer is more appropriate depends on your data set.

    To use a global average pooling layer instead of a fully connected layer, the number of channels in the input of the global average pooling layer must match the number of classes in the classification task.

Algorithms

expand all

Version History

Introduced in R2019b

expand all