oneflow.nn.MaxUnpool1d

class oneflow.nn.MaxUnpool1d(kernel_size: Union[int, Tuple[int]], stride: Optional[Union[int, Tuple[int]]] = None, padding: Optional[Union[int, Tuple[int]]] = 0)

Computes a partial inverse of MaxPool1d.

MaxPool1d is not fully invertible, since the non-maximal values are lost.

MaxUnpool1d takes in as input the output of MaxPool1d including the indices of the maximal values and computes a partial inverse in which all non-maximal values are set to zero.

The interface is consistent with PyTorch. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.nn.MaxUnpool1d.html.

Note

MaxPool1d can 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 argument output_size in the forward call. See the Inputs and Example below.

Parameters
  • kernel_size (int or tuple) – Size of the max pooling window.

  • stride (int or tuple) – Stride of the max pooling window. It is set to kernel_size by default.

  • padding (int or tuple) – Padding that was added to the input

Inputs:
  • input: the input Tensor to invert

  • indices: the indices given out by MaxPool1d

  • output_size (optional): the targeted output size

Shape:
  • Input: \((N, C, H_{in})\).

  • Output: \((N, C, H_{out})\), where

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

    or as given by output_size in the call operator

For example:

>>> import oneflow as flow
>>> pool = flow.nn.MaxPool1d(2, stride=2, return_indices=True)
>>> unpool = flow.nn.MaxUnpool1d(2, stride=2)
>>> input = flow.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.]]], dtype=oneflow.float32)
>>> # Example showcasing the use of output_size
>>> input = flow.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.]]], dtype=oneflow.float32)
>>> unpool(output, indices)
tensor([[[0., 2., 0., 4., 0., 6., 0., 8.]]], dtype=oneflow.float32)

Note

When indices contains elements out of the output_size range, an RuntimeError will be raised on the cpu and an indeterminate result will be calculated on the cuda.