CircularPad2d¶
- class torch.nn.CircularPad2d(padding)[源代码]¶
使用输入边界的循环填充来填充输入张量。
维度开始处的张量值用于填充末尾,而末尾的值用于填充开始处。如果应用了负填充,则张量的末端会被移除。
对于N维填充,使用
torch.nn.functional.pad()。- Shape:
输入: 或 。
输出: 或 , 其中
示例:
>>> 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.]]]]) >>> # 对不同边使用不同的填充 >>> 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.]]]])