MaxPooling3DLayer - 3-D max pooling layer - MATLAB (original) (raw)

Description

A 3-D max pooling layer performs downsampling by dividing three-dimensional input into cuboidal pooling regions, then computing the maximum of each region.

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

Creation

Syntax

Description

`layer` = maxPooling3dLayer([poolSize](#mw%5Ff274cb4b-efa6-484e-a511-56b05df6257f)) creates a 3-D max pooling layer and sets the PoolSize property.

`layer` = maxPooling3dLayer([poolSize](#mw%5Ff274cb4b-efa6-484e-a511-56b05df6257f),[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 three positive integers [h w d], where h is the height,w is the width, and d is the depth. When creating the layer, you can specify poolSize as a scalar to use the same value for all three 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 1] specifies pooling regions of height 2, width 1, and depth 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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: maxPooling3dLayer(2,Stride=3) creates a 3-D max pooling layer with pool size [2 2 2] and stride [3 3 3].

Step size for traversing the input in three dimensions, specified as a vector[a b c] of three positive integers, where a is the vertical step size, b is the horizontal step size, andc is the step size along the depth direction. When creating the layer, you can specify Stride as a scalar to use the same value for step sizes in all three directions.

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 1] specifies a vertical step size of 2, a horizontal step size of 3, and a step size along the depth of 1.

Input edge padding, specified as one of these values:

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

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

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

Max Pooling

Dimensions of the pooling regions, specified as a vector of three positive integers[h w d], where h is the height,w is the width, and d is the depth. When creating the layer, you can specify PoolSize as a scalar to use the same value for all three 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 1] specifies pooling regions of height 2, width 1, and depth 1.

Step size for traversing the input in three dimensions, specified as a vector[a b c] of three positive integers, where a is the vertical step size, b is the horizontal step size, andc is the step size along the depth direction. When creating the layer, you can specify Stride as a scalar to use the same value for step sizes in all three directions.

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 1] specifies a vertical step size of 2, a horizontal step size of 3, and a step size along the depth of 1.

Size of padding to apply to input borders, specified as 2-by-3 matrix[t l f;b r k] of nonnegative integers, where t and b are the padding applied to the top and bottom in the vertical direction, l and r are the padding applied to the left and right in the horizontal direction, and f and k are the padding applied to the front and back along the depth. In other words, the top row specifies the prepadding and the second row defines the postpadding in the three dimensions.

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

Example: [1 2 4; 1 2 4] adds one row of padding to the top and bottom, two columns of padding to the left and right, and four planes of padding to the front and back 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 argument value you specify when creating a layer.

The MaxPooling3DLayer object stores this property as a character vector.

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 max pooling 3-D layer with nonoverlapping pooling regions.

layer = maxPooling3dLayer(2,Stride=2)

layer = MaxPooling3DLayer with properties:

       Name: ''
 NumOutputs: 1
OutputNames: {'out'}

Hyperparameters PoolSize: [2 2 2] Stride: [2 2 2] PaddingMode: 'manual' PaddingSize: [2×3 double]

The height, width, and depth of the cuboidal regions (pool size) are 2. The step size for traversing the images (stride) is 2 in all dimensions. The pooling regions do not overlap because the stride is greater than or equal to the corresponding pool size in all dimensions.

Include a max pooling layer with nonoverlapping regions in a Layer array.

layers = [ ... image3dInputLayer([28 28 28 3]) convolution3dLayer(5,20) reluLayer maxPooling3dLayer(2,Stride=2) fullyConnectedLayer(10) softmaxLayer]

layers = 6×1 Layer array with layers:

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

Create a max pooling 3-D layer with overlapping pooling regions and padding for the top and bottom of the input.

layer = maxPooling3dLayer([3 2 2],'Stride',2,'Padding',[1 0 0])

layer = MaxPooling3DLayer with properties:

       Name: ''
 NumOutputs: 1
OutputNames: {'out'}

Hyperparameters PoolSize: [3 2 2] Stride: [2 2 2] PaddingMode: 'manual' PaddingSize: [2×3 double]

This layer creates pooling regions of size 3-by-2-by-2 and takes the maximum of the twelve elements in each region. The stride is 2 in all dimensions. The pooling regions overlap because there are stride dimensions Stride that are less than the respective pooling dimensions PoolSize.

Algorithms

expand all

A 3-D max pooling layer extends the functionality of a max pooling layer to a third dimension, depth. A max pooling layer performs down-sampling by dividing the input into rectangular or cuboidal pooling regions, and computing the maximum of each region. To learn more, see the 2-D Max Pooling Layer section of the maxPooling2dLayer reference page.

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 MaxPooling3DLayer 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
"SSSCB" (spatial, spatial, spatial, channel, batch) "SSSCB" (spatial, spatial, spatial, channel, batch)
"SSCBT" (spatial, spatial, channel, batch, time) "SSCBT" (spatial, spatial, channel, batch, time)
"SSSCBT" (spatial, spatial, spatial, channel, batch, time) "SSSCBT" (spatial, spatial, spatial, channel, batch, time)
"SSSB" (spatial, spatial, spatial, batch) "SSSB" (spatial, spatial, spatial, batch)

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

Input Format Output Format
"SSSC" (spatial, spatial, spatial, channel) "SSSC" (spatial, spatial, spatial, channel)
"SSCT" (spatial, spatial, channel, time) "SSCT" (spatial, spatial, channel, time)
"SSSCT" (spatial, spatial, spatial, channel, time) "SSSCT" (spatial, spatial, spatial, channel, time)
"SSBT" (spatial, spatial, batch, time) "SSBT" (spatial, spatial, batch, time)
"SSSBT" (spatial, spatial, spatial, batch, time) "SSSBT" (spatial, spatial, spatial, batch, time)

Version History

Introduced in R2019a