class
MaxUnpool1d
extends
_MaxUnpoolNdMaxUnpool1d(kernel_size: int | tuple[int, ...], stride: int | tuple[int, ...] | None = None, padding: int | tuple[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 must be obtained from the pairedMaxPool1dwithreturn_indices=True. Currently,return_indices=Trueis not yet implemented forMaxPool1d, soMaxUnpool1drequires 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_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)Methods (1)
fn
forward
→Tensorforward(x: Tensor, indices: Tensor, output_size: tuple[int, ...] | None = None)Apply the pooling operation to the input tensor.
Parameters
inputTensorInput tensor of shape where are the
spatial dimensions appropriate for this pooling layer.
Returns
TensorPooled output tensor.