ReflectionPad2d¶
- class torch.nn.ReflectionPad2d(padding)[source][source]¶
使用输入边界的反射来填充输入张量。
对于 N 维填充,使用
torch.nn.functional.pad()
。- 参数:
填充(int,tuple)- 填充的大小。如果为 int,则在所有边界使用相同的填充。如果为 4 元组,则使用( , , , )。注意,填充大小应小于相应的输入维度。
- 形状:
输入: 或 。
输出: 或 其中
示例:
>>> m = nn.ReflectionPad2d(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([[[[8., 7., 6., 7., 8., 7., 6.], [5., 4., 3., 4., 5., 4., 3.], [2., 1., 0., 1., 2., 1., 0.], [5., 4., 3., 4., 5., 4., 3.], [8., 7., 6., 7., 8., 7., 6.], [5., 4., 3., 4., 5., 4., 3.], [2., 1., 0., 1., 2., 1., 0.]]]]) >>> # using different paddings for different sides >>> m = nn.ReflectionPad2d((1, 1, 2, 0)) >>> m(input) tensor([[[[7., 6., 7., 8., 7.], [4., 3., 4., 5., 4.], [1., 0., 1., 2., 1.], [4., 3., 4., 5., 4.], [7., 6., 7., 8., 7.]]]])