class

MaxUnpool3d

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

Computes a partial inverse of MaxPool3d.

Extends MaxUnpool2d to three spatial dimensions. Each pooled value is scattered back to its 3-D source position (recorded in indices) and all other voxels are set to zero.

Parameters

kernel_sizeint or tuple[int, int, int]
Must match the kernel_size of the paired MaxPool3d.
strideint or tuple[int, int, int] or None= None
Must match the stride of the paired pool. Defaults to kernel_size.
paddingint or tuple[int, int, int]= 0
Must match the padding of the paired pool. Default: 0.

Attributes

kernel_sizeint or tuple[int, int, int]
strideint or tuple[int, int, int]
paddingint or tuple[int, int, int]

Notes

  • Input x: (N, C, D_pooled, H_pooled, W_pooled)
  • Input indices: (N, C, D_pooled, H_pooled, W_pooled)
  • Output: (N, C, D_original, H_original, W_original)
  • 3-D unpooling is used in volumetric segmentation networks that mirror a pooling encoder with an unpooling decoder.
  • As with MaxUnpool2d, the output is sparse — only voxels that were pool maxima receive non-zero values.
  • Pass output_size when the original volumetric shape cannot be uniquely determined from the pooling hyperparameters.

Examples

Reconstruct a volumetric map:
>>> import lucid
>>> import lucid.nn as nn
>>> unpool = nn.MaxUnpool3d(kernel_size=2, stride=2)
>>> x = lucid.ones((1, 32, 4, 4, 4))
>>> indices = lucid.zeros((1, 32, 4, 4, 4), dtype="int32")
>>> y = unpool(x, indices)
>>> y.shape
(1, 32, 8, 8, 8)
With explicit output_size:
>>> unpool = nn.MaxUnpool3d(kernel_size=2, stride=2)
>>> x = lucid.ones((1, 8, 3, 3, 3))
>>> indices = lucid.zeros((1, 8, 3, 3, 3), dtype="int32")
>>> y = unpool(x, indices, output_size=(1, 8, 7, 7, 7))
>>> y.shape
(1, 8, 7, 7, 7)

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.