max_unpool1d
→Tensormax_unpool1d(x: Tensor, indices: Tensor, kernel_size: int | tuple[int], stride: int | tuple[int] | None = None, padding: int | tuple[int] = 0, output_size: tuple[int, ...] | None = None)Inverse of max_pool1d via scatter at saved argmax indices.
Restores a "sparse" higher-resolution feature map by placing each
value of x at the spatial position recorded in indices
(i.e. the argmax positions captured by the corresponding max-pool
forward pass). Non-selected positions remain zero. Standard
component of encoder-decoder networks such as SegNet that
propagate pooling indices through skip connections.
Parameters
xTensor(N, C, L_in).indicesTensorx.kernel_sizeint or tuple of intstrideint or tuple of int= Nonepaddingint or tuple of int= 0output_sizetuple of int= Nonemax_pool1d.Returns
TensorOutput of shape (N, C, L_out) containing x scattered
into a zero buffer at the positions recorded in indices.
Notes
Math (let be the bijection from pooled-cell index to saved flat input position):
Implemented as a differentiable scatter_add over a
flattened spatial axis — gradients flow back to x.
output_size is required because Lucid does not yet emit
argmax indices from the forward pool, so we cannot infer the
original spatial extent.
Examples
>>> import lucid
>>> from lucid.nn.functional import max_unpool1d
>>> x = lucid.randn(1, 2, 4)
>>> idx = lucid.tensor([[[0, 2, 4, 6], [1, 3, 5, 7]]], dtype=lucid.int64)
>>> y = max_unpool1d(x, idx, kernel_size=2, output_size=(8,))
>>> y.shape
(1, 2, 8)