MaxUnpool1d¶
- class torch.nn.MaxUnpool1d(kernel_size, stride=None, padding=0)[源代码]¶
计算
MaxPool1d的部分逆。MaxPool1d不是完全可逆的,因为非最大值会丢失。MaxUnpool1d接受MaxPool1d的输出作为输入,包括最大值的索引,并计算一个部分逆运算,其中所有非最大值都设置为零。注意
当输入索引有重复值时,此操作可能会表现出不确定性。 请参阅 https://github.com/pytorch/pytorch/issues/80827 和 可重复性 以获取更多信息。
注意
MaxPool1d可以将多个输入大小映射到相同的输出大小。因此,反向过程可能会变得不明确。 为了适应这种情况,您可以在前向调用中提供所需的输出大小作为额外参数output_size。 请参阅下面的输入和示例。- Parameters
- Inputs:
输入: 要反转的输入张量
indices: 由
MaxPool1d给出的索引output_size(可选):目标输出大小
- Shape:
输入: 或 。
输出: 或 , 其中
或由调用操作符中的
output_size给出
示例:
>>> 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.]]]) >>> # 示例展示了如何使用 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.]]])