Skip to content
class

MaxUnpool1d

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

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 is typically obtained from a paired MaxPool1d with return_indices=True.
  • 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)

Used by 1

Instance methods

2
fn

extra_repr

→strfrom _MaxUnpoolNd
extra_repr()

Return a string representation of the layer's configuration.

fn

forward

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

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.