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.]]]])