CircularPad2d¶
- class torch.nn.CircularPad2d(padding)[原始碼][原始碼]¶
使用輸入的迴圈填充來填充輸入張量邊界。
維度開始處的張量值用於填充末尾,末尾的值用於填充開始。如果應用負數填充,則張量的末端將被移除。
對於 N 維填充,請使用
torch.nn.functional.pad()。- 形狀
輸入: 或 。
輸出: 或 ,其中
示例
>>> 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.]]]])