快捷鍵

ReplicationPad1d

class torch.nn.ReplicationPad1d(padding)[原始碼][原始碼]

使用輸入邊界的複製來填充輸入張量。

對於 N 維度填充,請使用 torch.nn.functional.pad()

參數

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

形狀
  • 輸入: (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+padding_left+padding_rightW_{out} = W_{in} + \text{padding\_left} + \text{padding\_right}

範例

>>> m = nn.ReplicationPad1d(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([[[0., 0., 0., 1., 2., 3., 3., 3.],
         [4., 4., 4., 5., 6., 7., 7., 7.]]])
>>> # using different paddings for different sides
>>> m = nn.ReplicationPad1d((3, 1))
>>> m(input)
tensor([[[0., 0., 0., 0., 1., 2., 3., 3.],
         [4., 4., 4., 4., 5., 6., 7., 7.]]])

文件

取得 PyTorch 的完整開發者文件

檢視文件

教學課程

取得適合初學者和進階開發人員的深入教學課程

檢視教學課程

資源

尋找開發資源並獲得問題解答

檢視資源