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