Main Content

maxPooling2dLayer

Max pooling layer

Description

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

Creation

Description

layer= maxPooling2dLayer(poolSize)creates a max pooling layer and sets thePoolSizeproperty.

example

layer= maxPooling2dLayer(poolSize,Name,Value)sets the optionalStride,Name, andHasUnpoolingOutputsproperties using name-value pairs. To specify input padding, use the'Padding'name-value pair argument. For example,maxPooling2dLayer(2,'Stride',3)creates a max pooling layer with pool size[2 2]and stride[3 3]. You can specify multiple name-value pairs. Enclose each property name in single quotes.

Input Arguments

expand all

Name-Value Pair Arguments

Use comma-separated name-value pair arguments to specify the size of the padding to add along the edges of the layer input and to set theStride,Name, andHasUnpoolingOutputsproperties. Enclose names in single quotes.

Example:maxPooling2dLayer(2,'Stride',3)creates a max pooling layer with pool size[2 2]and stride[3 3].

Input edge padding, specified as the comma-separated pair consisting of'Padding'and one of these values:

  • 'same'— Add padding of size calculated by the software at training or prediction time so that the output has the same size as the input when the stride equals 1.If the stride is larger than 1, then the output size isceil(inputSize/stride), whereinputSizeis the height or width of the input andstride在相应的维度是进步。的software adds the same amount of padding to the top and bottom, and to the left and right, if possible. If the padding that must be added vertically has an odd value, then the software adds extra padding to the bottom. If the padding that must be added horizontally has an odd value, then the software adds extra padding to the right.

  • Nonnegative integerp— Add padding of sizepto all the edges of the input.

  • Vector[a b]of nonnegative integers — Add padding of sizeato the top and bottom of the input and padding of sizebto the left and right.

  • Vector[t b l r]of nonnegative integers — Add padding of sizetto the top,bto the bottom,lto the left, andrto the right of the input.

Example:'Padding',1adds 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).

Properties

expand all

Max Pooling

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

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

的padding dimensionsPaddingSizemust be less than the pooling region dimensionsPoolSize.

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], whereais the vertical step size andbis the horizontal step size. When creating the layer, you can specifyStrideas a scalar to use the same value for both dimensions.

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

的padding dimensionsPaddingSizemust be less than the pooling region dimensionsPoolSize.

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, wheretis the padding applied to the top,bis the padding applied to the bottom,lis the padding applied to the left, andris 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'.

的software automatically sets the value ofPaddingModebased on the'Padding'value you specify when creating a layer.

  • If you set the'Padding'option to a scalar or a vector of nonnegative integers, then the software automatically setsPaddingModeto'manual'.

  • If you set the'Padding'option to'same', then the software automatically setsPaddingModeto'same'and calculates the size of the padding at training time so that the output has the same size as the input when the stride equals 1.If the stride is larger than 1, then the output size isceil(inputSize/stride), whereinputSizeis the height or width of the input andstride在相应的维度是进步。的software adds the same amount of padding to the top and bottom, and to the left and right, if possible. If the padding that must be added vertically has an odd value, then the software adds extra padding to the bottom. If the padding that must be added horizontally has an odd value, then the software adds extra padding to the right.

Note

Paddingproperty will be removed in a future release. UsePaddingSizeinstead. When creating a layer, use the'Padding'name-value pair 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, whereais the padding applied to the top and bottom of the input data andbis 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.

Flag for outputs to unpooling layer, specified astrueorfalse.

If theHasUnpoolingOutputsvalue equalsfalse, then the max pooling layer has a single output with the name'out'.

To use the output of a max pooling layer as the input to a max unpooling layer, set theHasUnpoolingOutputsvalue totrue. In this case, the max pooling layer has two additional outputs that you can connect to a max unpooling layer:

  • 'indices'— Indices of the maximum value in each pooled region.

  • 'size'— Size of the input feature map.

To enable outputs to a max unpooling layer, the pooling regions of the max pooling layer must be nonoverlapping.

For more information on how to unpool the output of a max pooling layer, seemaxUnpooling2dLayer.

Layer

Layer name, specified as a character vector or a string scalar. ForLayerarray input, thetrainNetwork,assembleNetwork,layerGraph, anddlnetworkfunctions automatically assign names to layers withNameset to''.

Data Types:char|string

This property is read-only.

Number of inputs of the layer. This layer accepts a single input only.

Data Types:double

This property is read-only.

Input names of the layer. This layer accepts a single input only.

Data Types:cell

Number of outputs of the layer.

If theHasUnpoolingOutputsvalue equalsfalse, then the max pooling layer has a single output with the name'out'.

To use the output of a max pooling layer as the input to a max unpooling layer, set theHasUnpoolingOutputsvalue totrue. In this case, the max pooling layer has two additional outputs that you can connect to a max unpooling layer:

  • 'indices'— Indices of the maximum value in each pooled region.

  • 'size'— Size of the input feature map.

To enable outputs to a max unpooling layer, the pooling regions of the max pooling layer must be nonoverlapping.

For more information on how to unpool the output of a max pooling layer, seemaxUnpooling2dLayer.

Data Types:double

Output names of the layer.

If theHasUnpoolingOutputsvalue equalsfalse, then the max pooling layer has a single output with the name'out'.

To use the output of a max pooling layer as the input to a max unpooling layer, set theHasUnpoolingOutputsvalue totrue. In this case, the max pooling layer has two additional outputs that you can connect to a max unpooling layer:

  • 'indices'— Indices of the maximum value in each pooled region.

  • 'size'— Size of the input feature map.

To enable outputs to a max unpooling layer, the pooling regions of the max pooling layer must be nonoverlapping.

For more information on how to unpool the output of a max pooling layer, seemaxUnpooling2dLayer.

Data Types:cell

Examples

collapse all

Create a max pooling layer with nonoverlapping pooling regions.

layer = maxPooling2dLayer(2,'Stride',2)
layer = MaxPooling2DLayer with properties: Name: '' HasUnpoolingOutputs: 0 NumOutputs: 1 OutputNames: {'out'} Hyperparameters PoolSize: [2 2] Stride: [2 2] PaddingMode: 'manual' PaddingSize: [0 0 0 0]

的height and the 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 2].

Include a max pooling layer with nonoverlapping regions in aLayerarray.

layers = [...imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer]
layers = 7x1 Layer array with layers: 1 '' Image Input 28x28x1 images with 'zerocenter' normalization 2 '' Convolution 20 5x5 convolutions with stride [1 1] and padding [0 0 0 0] 3 '' ReLU ReLU 4 '' Max Pooling 2x2 max pooling with stride [2 2] and padding [0 0 0 0] 5 '' Fully Connected 10 fully connected layer 6 '' Softmax softmax 7 '' Classification Output crossentropyex

Create a max pooling layer with overlapping pooling regions.

layer = maxPooling2dLayer([3 2],'Stride',2)
layer = MaxPooling2DLayer with properties: Name: '' HasUnpoolingOutputs: 0 NumOutputs: 1 OutputNames: {'out'} Hyperparameters PoolSize: [3 2] Stride: [2 2] PaddingMode: 'manual' PaddingSize: [0 0 0 0]

This layer creates pooling regions of size [3 2] and takes the maximum of the six elements in each region. The pooling regions overlap because there are stride dimensionsStridethat are less than the respective pooling dimensionsPoolSize.

Include a max pooling layer with overlapping pooling regions in aLayerarray.

layers = [...imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer([3 2],'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer]
layers = 7x1 Layer array with layers: 1 '' Image Input 28x28x1 images with 'zerocenter' normalization 2 '' Convolution 20 5x5 convolutions with stride [1 1] and padding [0 0 0 0] 3 '' ReLU ReLU 4 '' Max Pooling 3x2 max pooling with stride [2 2] and padding [0 0 0 0] 5 '' Fully Connected 10 fully connected layer 6 '' Softmax softmax 7 '' Classification Output crossentropyex

More About

expand all

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

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Introduced in R2016a