MaxUnpool1d

torch.nn.MaxUnpool1d(kernel_size, stride=None, padding=0)[源代码]

计算MaxPool1d的部分逆。

MaxPool1d 不是完全可逆的,因为非最大值会被丢弃。

MaxUnpool1dMaxPool1d 的输出作为输入,包括最大值的索引,并计算一个部分逆向操作,在此操作中所有非最大值都被设置为零。

注意

当输入索引包含重复值时,此操作可能会表现出非确定性的行为。详情请参见https://github.com/pytorch/pytorch/issues/80827重复性

注意

MaxPool1d 可以将多个不同的输入大小映射到相同的输出大小,这会导致反向过程变得模糊不清。为了解决这个问题,你可以在前向调用中提供所需的输出大小作为额外参数 output_size。请参见下面的示例和输入。

参数
  • kernel_size (inttuple) – 最大池化窗口的尺寸。

  • stride (inttuple) – 最大池化窗口的步长,默认值为 kernel_size

  • padding (inttuple) – 输入数据的填充值

输入:
  • input: 输入张量,需要对其进行逆运算

  • indices: MaxPool1d生成的索引

  • output_size(可选):目标输出的大小

形状:
  • 输入格式为: $(N, C, H_{in})$$(C, H_{in})$

  • 输出为 $(N, C, H_{out})$$(C, H_{out})$,其中

    $H_{out} = (H_{in} - 1) \times \text{stride}[0] - 2 \times \text{padding}[0] + \text{kernel\_size}[0]$

    或者如调用操作符中的 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.]]])

>>> # 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.]]])
本页目录