({{, (RefLink[PaddingLayer, paclet:ref/PaddingLayer])[{{(Subscript[m, 1]),(Subscript[n, 1])},{(Subscript[m, 2]),(Subscript[n, 2])},…}] 
represents a net layer that pads an input array with (Subscript[m, i]) elements at the beginning and (Subscript[n, i]) elements at the end at level i of the array.}})

OpenersNotesSection(Spacer1)Details and Options

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

(RefLink[PaddingLayer, paclet:ref/PaddingLayer])[…][{(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[PaddingLayer, paclet:ref/PaddingLayer]) is typically used inside (RefLink[NetChain, paclet:ref/NetChain]), (RefLink[NetGraph, paclet:ref/NetGraph]), etc.

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

The following optional parameter can be included:

Possible explicit settings for the (RefLink[Padding, paclet:ref/Padding]) option include:

The default option is to pad with the value 0.

The (RefLink[Padding, paclet:ref/Padding]) value "Fixed" indicates that the rectangles of pixels added at each corner should be copies of the pixels at the corners of the original array.

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 of (RefLink[PaddingLayer, paclet:ref/PaddingLayer]) to be an array of dimensions (Subscript[d, 1])×…×(Subscript[d, n]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (9)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create a (RefLink[PaddingLayer, paclet:ref/PaddingLayer]) that pads a vector with zeros:

PaddingLayer[{{1,2}}]

Create a (RefLink[PaddingLayer, paclet:ref/PaddingLayer]) that pads a vector with zeros:

p=PaddingLayer[{{2,0}}]

Apply the layer to a vector:

p[{1,2,3}]

OpenersExampleSection1(Spacer1)Scope  (3)

Create a (RefLink[PaddingLayer, paclet:ref/PaddingLayer]) that pads a vector with zeros:

p=PaddingLayer[{{2,0}}]

The layer threads across a batch of examples:

p[{{1,2,3},{5,6,7}}]//MatrixForm

Create a (RefLink[PaddingLayer, paclet:ref/PaddingLayer]) that pads a matrix:

p=PaddingLayer[{{1,2},{0,1}}]

Apply the layer to a matrix:

p[{{2,3},{5,7}}]//MatrixForm

Create a (RefLink[PaddingLayer, paclet:ref/PaddingLayer]) that pads an image encoded as a 3-dimensional array, using "Fixed" padding:

p=PaddingLayer[{{0,0},{20,20},{20,20}},"Padding"->"Fixed","Input"->NetEncoder["Image"],"Output"->NetDecoder["Image"]]

p[]

OpenersExampleSection2(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)Padding  (3)

Use -999 as the padding value:

p=PaddingLayer[{{1,2}},Padding->-999]

Apply the layer to a vector:

p[{0.1,-0.4}]

Use the "Fixed" padding method:

p=PaddingLayer[{{1,2}},Padding->"Fixed"]

Apply the layer to a vector:

p[{0.1,-0.4}]

Use the "Reflected" padding method:

p=PaddingLayer[{{1,1}},Padding->"Reflected"]

Apply the layer to a vector:

p[{0.1,0.2,-0.4}]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

(RefLink[PaddingLayer, paclet:ref/PaddingLayer]) is equivalent to (RefLink[ArrayPad, paclet:ref/ArrayPad]):

pad={{1,2}};
data={1,2,3};

PaddingLayer[pad]@data
ArrayPad[data,pad]

(RefLink[PaddingLayer, paclet:ref/PaddingLayer]) also supports the "Fixed" padding type:

PaddingLayer[pad,Padding->"Fixed"]@data
ArrayPad[data,pad,"Fixed"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ReshapeLayer, paclet:ref/ReshapeLayer])  ▪  (RefLink[NetChain, paclet:ref/NetChain])  ▪  (RefLink[NetGraph, paclet:ref/NetGraph])  ▪  (RefLink[NetTrain, paclet:ref/NetTrain])  ▪  (RefLink[ArrayPad, paclet:ref/ArrayPad])}})}})

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

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