MaxUnpool1d#
- class torch.nn.modules.pooling.MaxUnpool1d(kernel_size, stride=None, padding=0)[原始碼]#
計算
MaxPool1d的部分逆運算。MaxPool1d不是完全可逆的,因為非最大值會被丟失。要計算
MaxPool1d的逆運算,需要提供MaxPool1d的輸出(包括最大值的索引),並計算一個部分逆運算,其中所有非最大值都設定為零。注意
當輸入索引存在重複值時,此操作可能表現出非確定性。更多資訊請參閱 pytorch/pytorch#80827 和 可復現性。
注意
MaxPool1d可以將多種輸入大小對映到相同的輸出大小。因此,逆運算可能會出現歧義。為了解決這個問題,您可以在前向傳播呼叫中提供所需的輸出大小作為附加引數output_size。請參閱下面的輸入和示例。- 引數
- 輸入
input: the input Tensor to invert
indices: 由
MaxPool1d給出的索引output_size (optional): the targeted output size
- 形狀
輸入: 或 。
輸出: 或 ,其中
or as given by
output_sizein the call operator
示例
>>> pool = nn.MaxPool1d(2, stride=2, return_indices=True) >>> unpool = nn.MaxUnpool1d(2, stride=2) >>> input = torch.tensor([[[1., 2, 3, 4, 5, 6, 7, 8]]]) >>> output, indices = pool(input) >>> unpool(output, indices) tensor([[[ 0., 2., 0., 4., 0., 6., 0., 8.]]]) >>> # Example showcasing the use of output_size >>> input = torch.tensor([[[1., 2, 3, 4, 5, 6, 7, 8, 9]]]) >>> output, indices = pool(input) >>> unpool(output, indices, output_size=input.size()) tensor([[[ 0., 2., 0., 4., 0., 6., 0., 8., 0.]]]) >>> unpool(output, indices) tensor([[[ 0., 2., 0., 4., 0., 6., 0., 8.]]])