MaxUnpool2d#
- class torch.nn.MaxUnpool2d(kernel_size, stride=None, padding=0)[source]#
計算
MaxPool2d的部分逆運算。MaxPool2d並非完全可逆,因為非最大值會丟失。MaxUnpool2d以MaxPool2d的輸出來輸入,包括最大值的索引,並計算一個部分逆運算,其中所有非最大值都被設定為零。注意
當輸入索引存在重複值時,此操作可能表現出非確定性。更多資訊請參閱 pytorch/pytorch#80827 和 可復現性。
注意
MaxPool2d可以將多個輸入尺寸對映到相同的輸出尺寸。因此,逆運算過程可能會有歧義。為了解決這個問題,您可以在前向呼叫中提供所需的輸出尺寸作為附加引數output_size。請參閱下面的輸入和示例。- 引數
- 輸入
input: the input Tensor to invert
indices:
MaxPool2d輸出的索引output_size (optional): the targeted output size
- 形狀
輸入: 或 。
輸出: 或 ,其中
or as given by
output_sizein the call operator
示例
>>> pool = nn.MaxPool2d(2, stride=2, return_indices=True) >>> unpool = nn.MaxUnpool2d(2, stride=2) >>> input = torch.tensor([[[[ 1., 2., 3., 4.], [ 5., 6., 7., 8.], [ 9., 10., 11., 12.], [13., 14., 15., 16.]]]]) >>> output, indices = pool(input) >>> unpool(output, indices) tensor([[[[ 0., 0., 0., 0.], [ 0., 6., 0., 8.], [ 0., 0., 0., 0.], [ 0., 14., 0., 16.]]]]) >>> # Now using output_size to resolve an ambiguous size for the inverse >>> input = torch.tensor([[[[ 1., 2., 3., 4., 5.], [ 6., 7., 8., 9., 10.], [11., 12., 13., 14., 15.], [16., 17., 18., 19., 20.]]]]) >>> output, indices = pool(input) >>> # This call will not work without specifying output_size >>> unpool(output, indices, output_size=input.size()) tensor([[[[ 0., 0., 0., 0., 0.], [ 0., 7., 0., 9., 0.], [ 0., 0., 0., 0., 0.], [ 0., 17., 0., 19., 0.]]]])