class
FractionalMaxPool3d
extends
ModuleFractionalMaxPool3d(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:
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= NoneFixed 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= NoneTarget size as a fraction of each input dimension. Values must
lie in .
return_indicesbool= FalseIf
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 Noneoutput_ratiofloat or tuple[float, float, float] or Nonereturn_indicesboolNotes
- 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_sizeoroutput_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)Methods (2)
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.
fn
forward
→Tensorforward(x: Tensor)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.