class

MaxUnpool1d

extends_MaxUnpoolNd
MaxUnpool1d(kernel_size: int | tuple[int, ...], stride: int | tuple[int, ...] | None = None, padding: int | tuple[int, ...] = 0)
source

Computes a partial inverse of MaxPool1d.

MaxPool1d is not fully invertible because the non-maximum values in each window are discarded. MaxUnpool1d performs an approximate inversion by placing each pooled value back at its original position (recorded by the indices tensor) and filling all other locations with zero.

Formally, if xpool[n,c,i]x_{\text{pool}}[n,c,i] was the maximum at flat index idx[n,c,i]\text{idx}[n,c,i] within the original input, then:

xunpool[n,c,j]={xpool[n,c,i]if j=idx[n,c,i]0otherwisex_{\text{unpool}}[n, c, j] = \begin{cases} x_{\text{pool}}[n, c, i] & \text{if } j = \text{idx}[n,c,i] \\ 0 & \text{otherwise} \end{cases}

Parameters

kernel_sizeint
Must match the kernel_size of the paired MaxPool1d.
strideint or None= None
Must match the stride of the paired pool. Defaults to kernel_size.
paddingint= 0
Must match the padding of the paired pool. Default: 0.

Attributes

kernel_sizeint
strideint
paddingint

Notes

  • Input x: (N, C, L_pooled)
  • Input indices: (N, C, L_pooled) — flat indices from pool
  • Output: (N, C, L_original)
  • The indices tensor must be obtained from the paired MaxPool1d with return_indices=True. Currently, return_indices=True is not yet implemented for MaxPool1d, so MaxUnpool1d requires the caller to supply compatible indices by another means.
  • The output is sparse — only the positions corresponding to maxima are non-zero. This sparsity is intentional and matches the original architecture (SegNet, etc.).
  • Use the optional output_size argument to control the shape of the reconstructed tensor when ambiguity exists.

Examples

Typical encoder-decoder unpool:
>>> import lucid
>>> import lucid.nn as nn
>>> unpool = nn.MaxUnpool1d(kernel_size=2, stride=2)
>>> x = lucid.ones((1, 4, 8))
>>> indices = lucid.zeros((1, 4, 8), dtype="int32")
>>> y = unpool(x, indices)
>>> y.shape
(1, 4, 16)
With explicit output_size:
>>> unpool = nn.MaxUnpool1d(kernel_size=2, stride=2)
>>> x = lucid.ones((1, 4, 8))
>>> indices = lucid.zeros((1, 4, 8), dtype="int32")
>>> y = unpool(x, indices, output_size=(1, 4, 17))
>>> y.shape
(1, 4, 17)

Methods (1)

fn

forward

Tensor
forward(x: Tensor, indices: Tensor, output_size: tuple[int, ...] | None = None)
source

Apply the pooling operation to the input tensor.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *) where * are the spatial dimensions appropriate for this pooling layer.

Returns

Tensor

Pooled output tensor.