Skip to content
class

FractionalMaxPool3d

extendsModule
FractionalMaxPool3d(kernel_size: int | tuple[int, int, int], output_size: int | tuple[int, int, int] | None = None, output_ratio: float | tuple[float, float, float] | None = None, return_indices: bool = False)

Applies fractional max-pooling over a 3-D volumetric feature map.

Extends FractionalMaxPool2d to three spatial dimensions (depth, height, width) following the same random fractional boundary scheme of Graham (2014). Independent random partitions are sampled for each of the three axes:

y[n,c,d,i,j]=max⁡z∈[rd(d),rd(d+1))h∈[rh(i),rh(i+1))w∈[rw(j),rw(j+1))x[n,c,z,h,w]y[n,c,d,i,j] = \max_{\substack{ z \in [r_d^{(d)},\, r_d^{(d+1)}) \\ h \in [r_h^{(i)},\, r_h^{(i+1)}) \\ w \in [r_w^{(j)},\, r_w^{(j+1)}) }} x[n,c,z,h,w]

Parameters

kernel_sizeint or tuple[int, int, int]
Size of the max pooling window at each sampled position.
output_sizeint or tuple[int, int, int] or None= None
Fixed target output size (D_out, H_out, W_out). Exactly one of output_size and output_ratio must be given.
output_ratiofloat or tuple[float, float, float] or None= None
Target size as a fraction of each input dimension. Values must lie in (0,1)(0, 1).
return_indicesbool= False
If True, also return flat indices of the selected maxima. Default: False.

Attributes

kernel_sizeint or tuple[int, int, int]
output_sizeint or tuple[int, int, int] or None
output_ratiofloat or tuple[float, float, float] or None
return_indicesbool

Notes

  • Input: (N, C, D_in, H_in, W_in)
  • Output: (N, C, D_out, H_out, W_out)
  • The random partition is drawn independently per batch-channel pair, so the output shape is deterministic (fixed by output_size or output_ratio) but the selected voxels differ across calls during training.
  • The stochastic sampling implicitly augments the data, which can reduce over-fitting on volumetric datasets.
  • Delegates to lucid.nn.functional.pooling.fractional_max_pool3d.

Examples

Volumetric fractional pooling with fixed output:
>>> import lucid
>>> import lucid.nn as nn
>>> pool = nn.FractionalMaxPool3d(kernel_size=2, output_size=(4, 4, 4))
>>> x = lucid.ones((1, 32, 8, 8, 8))
>>> y = pool(x)
>>> y.shape
(1, 32, 4, 4, 4)
Using output_ratio for proportional downsampling:
>>> pool = nn.FractionalMaxPool3d(kernel_size=2, output_ratio=0.5)
>>> x = lucid.ones((2, 16, 12, 12, 12))
>>> y = pool(x)
>>> y.shape[0], y.shape[1]
(2, 16)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(kernel_size: int | tuple[int, int, int], output_size: int | tuple[int, int, int] | None = None, output_ratio: float | tuple[float, float, float] | None = None, return_indices: bool = False)

Initialise the FractionalMaxPool3d module. See the class docstring for parameter semantics.

Instance methods

1
fn

forward

→Tensor | tuple[Tensor, Tensor]
forward(input: Tensor)

Pool input of shape (N, C, D, H, W), or unbatched.

Returns the pooled tensor, and with return_indices also each window maximum's flat position in the input.