快捷方式

CircularPad1d

class torch.nn.CircularPad1d(padding)[source][source]

使用輸入邊界的循環填充來填充輸入 tensor。

維度開始處的 Tensor 值用於填充結尾,而結尾處的值用於填充開頭。 如果應用負填充,則會移除 tensor 的結尾。

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

參數

padding ( 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+padding_left+padding_rightW_{out} = W_{in} + \text{padding\_left} + \text{padding\_right}

範例

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

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深入教學

檢視教學

資源

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

檢視資源