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 was the maximum at flat index within the original input, then:
Parameters
kernel_ sizeintMust match the
kernel_size of the paired MaxPool1d.strideint or None= NoneMust match the
stride of the paired pool. Defaults to
kernel_size.paddingint= 0Must match the
padding of the paired pool. Default: 0.Attributes
kernel_ sizeintstrideintpaddingintNotes
- Input
x:(N, C, L_pooled) - Input
indices:(N, C, L_pooled)— flat indices from pool - Output:
(N, C, L_original)
- The
indicestensor is typically obtained from a pairedMaxPool1dwithreturn_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_sizeargument 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
2Return a string representation of the layer's configuration.
forward(input: Tensor, indices: Tensor, output_size: tuple[int, ...] | None = None)