MaxUnpool1d#
- classtorch.nn.MaxUnpool1d(kernel_size,stride=None,padding=0)[source]#
Computes a partial inverse of
MaxPool1d.MaxPool1dis not fully invertible, since the non-maximal values are lost.MaxUnpool1dtakes in as input the output ofMaxPool1dincluding the indices of the maximal values and computes a partial inversein which all non-maximal values are set to zero.Note
This operation may behave nondeterministically when the input indices has repeat values.Seepytorch/pytorch#80827 andReproducibility for more information.
Note
MaxPool1dcan map several input sizes to the same outputsizes. Hence, the inversion process can get ambiguous.To accommodate this, you can provide the needed output sizeas an additional argumentoutput_sizein the forward call.See the Inputs and Example below.- Parameters
- Inputs:
input: the input Tensor to invert
indices: the indices given out by
MaxPool1doutput_size (optional): the targeted output size
- Shape:
Input: or.
Output: or, where
or as given by
output_sizein the call operator
Example:
>>>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.]]])