CircularPad2d#
- class torch.nn.CircularPad2d(padding)[source]#
使用输入边界的循环填充来填充输入张量。
张量的维度开头的值用于填充张量的末尾,维度末尾的值用于填充张量的开头。如果应用了负填充,则会移除张量的末尾部分。
对于 N 维填充,请使用
torch.nn.functional.pad()
。- 参数
padding (int, tuple) – 填充的大小。如果为 int,则在所有边界使用相同的填充。如果是 4-tuple,则使用 (, , , ))其中 , , , 分别是左、右、上、下的填充大小。请注意,填充大小应小于或等于相应的输入维度。
- 形状
输入: 或 。
输出: 或 ,其中
示例
>>> m = nn.CircularPad2d(2) >>> input = torch.arange(9, dtype=torch.float).reshape(1, 1, 3, 3) >>> input tensor([[[[0., 1., 2.], [3., 4., 5.], [6., 7., 8.]]]]) >>> m(input) tensor([[[[4., 5., 3., 4., 5., 3., 4.], [7., 8., 6., 7., 8., 6., 7.], [1., 2., 0., 1., 2., 0., 1.], [4., 5., 3., 4., 5., 3., 4.], [7., 8., 6., 7., 8., 6., 7.], [1., 2., 0., 1., 2., 0., 1.], [4., 5., 3., 4., 5., 3., 4.]]]]) >>> # using different paddings for different sides >>> m = nn.CircularPad2d((1, 1, 2, 0)) >>> m(input) tensor([[[[5., 3., 4., 5., 3.], [8., 6., 7., 8., 6.], [2., 0., 1., 2., 0.], [5., 3., 4., 5., 3.], [8., 6., 7., 8., 6.]]]])