MaxUnpool2d
-
class torch.nn.MaxUnpool2d(kernel_size, stride=None, padding=0)[source] -
Computes a partial inverse of
MaxPool2d.MaxPool2dis not fully invertible, since the non-maximal values are lost.MaxUnpool2dtakes in as input the output ofMaxPool2dincluding the indices of the maximal values and computes a partial inverse in which all non-maximal values are set to zero.Note
MaxPool2dcan map several input sizes to the same output sizes. Hence, the inversion process can get ambiguous. To accommodate this, you can provide the needed output size as 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 byMaxPool2d -
output_size(optional): the targeted output size
-
- Shape:
-
- Input:
-
Output: , where
or as given by
output_sizein the call operator
Example:
>>> 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.]]]]) >>> # specify a different output size than input size >>> unpool(output, indices, output_size=torch.Size([1, 1, 5, 5])) tensor([[[[ 0., 0., 0., 0., 0.], [ 6., 0., 8., 0., 0.], [ 0., 0., 0., 14., 0.], [ 16., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.]]]])
© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.nn.MaxUnpool2d.html