({{, (RefLink[PoolingLayer, paclet:ref/PoolingLayer])[sz] 
represents a pooling net layer using kernels of size sz.}, {, (RefLink[PoolingLayer, paclet:ref/PoolingLayer])[{w}]
represents a layer performing one-dimensional pooling with kernels of size w.}, {, (RefLink[PoolingLayer, paclet:ref/PoolingLayer])[{h,w}]
represents a layer performing two-dimensional pooling with kernels of size h×w.}, {, (RefLink[PoolingLayer, paclet:ref/PoolingLayer])[{h,w,d}]
represents a layer performing three-dimensional pooling with kernels of size h×w×d.}, {, (RefLink[PoolingLayer, paclet:ref/PoolingLayer])[kernel,stride]
represents a layer that uses stride as the step size between kernel applications.}, {, (RefLink[PoolingLayer, paclet:ref/PoolingLayer])[kernel,opts]
includes options for other pooling methods, padding and other parameters.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[PoolingLayer, paclet:ref/PoolingLayer])[n,…] represents a layer that, applied to an input array with c input channels and one or more spatial dimensions, performs c distinct pooling operations across the spatial dimensions to produce an output array with c channels.

(RefLink[PoolingLayer, paclet:ref/PoolingLayer])[n] is equivalent to (RefLink[PoolingLayer, paclet:ref/PoolingLayer])[n,1].

The following optional parameters can be included:

With the setting "Interleaving"->(RefLink[False, paclet:ref/False]), the channel dimension is taken to be the first dimension of the input and output arrays.

With the setting "Interleaving"->(RefLink[True, paclet:ref/True]), the channel dimension is taken to be the last dimension of the input and output arrays.

The settings for kernel and stride can be of the following forms:

The setting for "PaddingSize" can be of the following forms:

(RefLink[PoolingLayer, paclet:ref/PoolingLayer])[…][input] explicitly computes the output from applying the layer.

(RefLink[PoolingLayer, paclet:ref/PoolingLayer])[…][{(Subscript[input, 1]),(Subscript[input, 2]),…}] explicitly computes outputs for each of the (Subscript[input, i]).

When given a (RefLink[NumericArray, paclet:ref/NumericArray]) as input, the output will be a (RefLink[NumericArray, paclet:ref/NumericArray]).

(RefLink[PoolingLayer, paclet:ref/PoolingLayer]) is typically used inside (RefLink[NetChain, paclet:ref/NetChain]), (RefLink[NetGraph, paclet:ref/NetGraph]), etc.

(RefLink[NetExtract, paclet:ref/NetExtract]) can be used to extract parameter values from a (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) object.

(RefLink[PoolingLayer, paclet:ref/PoolingLayer]) exposes the following ports for use in (RefLink[NetGraph, paclet:ref/NetGraph]) etc.:

(RefLink[PoolingLayer, paclet:ref/PoolingLayer]) can operate on arrays that contain "Varying" dimensions.

Possible explicit settings for the "Function" option include:

When it cannot be inferred from other layers in a larger net, the option "Input"->{(Subscript[d, 1]),…,(Subscript[d, n])} can be used to fix the input dimensions of (RefLink[PoolingLayer, paclet:ref/PoolingLayer]).

Given an input array of dimensions (Subscript[d, 1])×…×(Subscript[d, i])×…, the output array will be of dimensions (Subscript[(OverTilde[d]), 1])×…×(Subscript[(OverTilde[d]), i])×…, where the channel dimension remains unchanged (i.e. (Subscript[d, 1])=(Subscript[(OverTilde[d]), 1])) and the sizes of spatial dimensions are transformed according to (OverTilde[(Subscript[d, i])])=⌊((Subscript[d, i])+(Subscript[p, b])+(Subscript[p, e])-k)/s+1⌋, where (Subscript[p, b])/(Subscript[p, e]) are the padding sizes at the beginning/end of the axis, k is the kernel size, and s is the stride size for each dimension.

OpenersPrimaryExamplesSection(Spacer1)Examples  (14)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create a (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) with a kernel size of 5×5:

PoolingLayer[{5,5}]

Create a one-dimensional (RefLink[PoolingLayer, paclet:ref/PoolingLayer]):

pool=PoolingLayer[{2}]

Apply the layer to an input matrix:

pool[{{1,2,3},{4,5,6},{7,8,9}}]//MatrixForm

OpenersExampleSection1(Spacer1)Scope  (4)

Create a one-dimensional (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) with a stride of 4 and apply it to an input:

pool=PoolingLayer[3,{4},"Function"->Mean]

pool[{Range[20]}]

Create an initialized three-dimensional (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) with kernel size 2:

pool=PoolingLayer[2]

Apply the layer to an input array:

pool[{{{1,3,0},{0,0,1},{-2,1,0}}}]

Create a two-dimensional (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) with a non-symmetric stride and apply it to an input:

pool=PoolingLayer[3,{2,3}]

pool[RandomReal[1,{3,4,4}]]

Create a two-dimensional (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) that takes an image and returns an image:

pool=PoolingLayer[16,"Input"-> NetEncoder["Image"],"Output"-> NetDecoder["Image"]]

Apply the layer to an image:

pool[]

The layer threads across a batch of examples:

pool[{,}]

OpenersExampleSection2(Spacer1)Options  (6)

OpenersExampleSubsection0(Spacer1)"Function"  (2)

Different aggregation functions can be specified for pooling:

data={{1,2,3}};
AssociationMap[PoolingLayer[{3},"Function"->#]@data&,{Max,Total,Mean}]

Make a table of the effect of the different pooling functions on two test images:

imgs={,};

Grid@Map[
Prepend[#]@PoolingLayer[16,"Function"->#,"Input"-> NetEncoder["Image"],"Output"->NetDecoder["Image"]]@imgs&,{Max,Mean,Total}]

OpenersExampleSubsection1(Spacer1)"Interleaving"  (1)

Create a (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) with "Interleaving"->(RefLink[False, paclet:ref/False]) and one input channel:

PoolingLayer[2,"Input"->{1,25,25},"Interleaving"->False]

Create a (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) with "Interleaving"->(RefLink[True, paclet:ref/True]) and one input channel:

PoolingLayer[2,"Input"->{25,25,1},"Interleaving"->True]

OpenersExampleSubsection2(Spacer1)"PaddingSize"  (3)

Create a two-dimensional (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) that pads the first dimension with 10 zeros on each side and the second dimension with 12 zeros on each side:

pool=PoolingLayer[15,"PaddingSize"-> {10,12},"Input"-> NetEncoder["Image"],"Output"->NetDecoder["Image"]]

pool[]

Create a two-dimensional (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) that pads the first dimension with 10 zeros at the beginning and 14 zeros at the end:

pool=PoolingLayer[15,"PaddingSize"-> {{10,14},{0,0}},"Input"-> NetEncoder["Image"],"Output"->NetDecoder["Image"]]

pool[]

Use padding to make the output dimensions equivalent to the input dimensions:

pool=PoolingLayer[5,"Input"->{1,25,25},"PaddingSize"->2 ]

pool[["Input"]]==pool[["Output"]]

OpenersExampleSection3(Spacer1)Properties & Relations  (2)

The following function computes the size of the non-channel dimensions, given the input size and parameters:

outputSize[inputSize_List,kern_,stride_,pad_]:=
Floor[(inputSize+2*pad-kern)/stride]+1

The output size of an input of size {256,252}, a kernel size of 3, a stride of 2, and padding size of 2:

outputSize[{256,252},3,2,2]

This agrees with defining a (RefLink[PoolingLayer, paclet:ref/PoolingLayer]) with the same parameters:

PoolingLayer[3,2,"PaddingSize"->2,"Input"->{3,256,252}]

Increasing the stride can decrease the evaluation time of (RefLink[PoolingLayer, paclet:ref/PoolingLayer]):

data=RandomReal[1,{3,400,400}];
PoolingLayer[50,1][data];//AbsoluteTiming
PoolingLayer[50,5][data];//AbsoluteTiming

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ConvolutionLayer, paclet:ref/ConvolutionLayer])  ▪  (RefLink[BatchNormalizationLayer, paclet:ref/BatchNormalizationLayer])  ▪  (RefLink[SpatialTransformationLayer, paclet:ref/SpatialTransformationLayer])  ▪  (RefLink[AggregationLayer, paclet:ref/AggregationLayer])  ▪  (RefLink[NetChain, paclet:ref/NetChain])  ▪  (RefLink[NetGraph, paclet:ref/NetGraph])  ▪  (RefLink[NetTrain, paclet:ref/NetTrain])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Neural Networks in the Wolfram Language, paclet:tutorial/NeuralNetworksOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Neural Networks, paclet:guide/NeuralNetworks])}})}})