CircularPad2d#
- class torch.nn.modules.padding.CircularPad2d(padding)[原始碼]#
使用輸入邊界的迴圈填充來填充輸入張量。
張量維度開頭的值用於填充結尾,維度結尾的值用於填充開頭。如果應用負填充,則會移除張量的末端。
對於 N 維填充,請使用
torch.nn.functional.pad()。- 引數
padding (int, tuple) – 填充的大小。如果為 int,則在所有邊界使用相同的填充。如果為 4-tuple,則使用 (, , , ) 請注意,填充大小應小於或等於相應的輸入維度。
- 形狀
輸入: 或 。
輸出: 或 ,其中
示例
>>> 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.]]]]) >>> # using different paddings for different sides >>> 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.]]]])