Shortcuts

ReflectionPad1d

class torch.nn.ReflectionPad1d(padding)[源代码]

使用输入边界的反射来填充输入张量。

对于N维填充,使用torch.nn.functional.pad()

Parameters

填充 (int, tuple) – 填充的大小。如果是int,则在所有边界使用相同的填充。如果是2-tuple,则使用 (padding_left\text{padding\_left}, padding_right\text{padding\_right})

Shape:
  • 输入: (C,Win)(C, W_{in})(N,C,Win)(N, C, W_{in})

  • 输出: (C,Wout)(C, W_{out})(N,C,Wout)(N, C, W_{out}), 其中

    Wout=Win+左填充+右填充W_{out} = W_{in} + \text{左填充} + \text{右填充}

示例:

>>> m = nn.ReflectionPad1d(2)
>>> input = torch.arange(8, dtype=torch.float).reshape(1, 2, 4)
>>> input
tensor([[[0., 1., 2., 3.],
         [4., 5., 6., 7.]]])
>>> m(input)
tensor([[[2., 1., 0., 1., 2., 3., 2., 1.],
         [6., 5., 4., 5., 6., 7., 6., 5.]]])
>>> # 对不同边使用不同的填充
>>> m = nn.ReflectionPad1d((3, 1))
>>> m(input)
tensor([[[3., 2., 1., 0., 1., 2., 3., 2.],
         [7., 6., 5., 4., 5., 6., 7., 6.]]])
优云智算