Rate this Page

ZeroPad2d#

classtorch.nn.modules.padding.ZeroPad2d(padding)[source]#

Pads the input tensor boundaries with zero.

ForN-dimensional padding, usetorch.nn.functional.pad().

Parameters

padding (int,tuple) – the size of the padding. If isint, uses the samepadding in all boundaries. If a 4-tuple, uses (padding_left\text{padding\_left},padding_right\text{padding\_right},padding_top\text{padding\_top},padding_bottom\text{padding\_bottom})

Shape:

Examples:

>>>m=nn.ZeroPad2d(2)>>>input=torch.randn(1,1,3,3)>>>inputtensor([[[[-0.1678, -0.4418,  1.9466],          [ 0.9604, -0.4219, -0.5241],          [-0.9162, -0.5436, -0.6446]]]])>>>m(input)tensor([[[[ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000],          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000],          [ 0.0000,  0.0000, -0.1678, -0.4418,  1.9466,  0.0000,  0.0000],          [ 0.0000,  0.0000,  0.9604, -0.4219, -0.5241,  0.0000,  0.0000],          [ 0.0000,  0.0000, -0.9162, -0.5436, -0.6446,  0.0000,  0.0000],          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000],          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000]]]])>>># using different paddings for different sides>>>m=nn.ZeroPad2d((1,1,2,0))>>>m(input)tensor([[[[ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],          [ 0.0000, -0.1678, -0.4418,  1.9466,  0.0000],          [ 0.0000,  0.9604, -0.4219, -0.5241,  0.0000],          [ 0.0000, -0.9162, -0.5436, -0.6446,  0.0000]]]])
extra_repr()[source]#

Return the extra representation of the module.

Return type

str