fn

max_pool3d

Tensor
max_pool3d(x: Tensor, kernel_size: int | tuple[int, int, int], stride: int | tuple[int, int, int] | None = None, padding: int | tuple[int, int, int] = 0, dilation: int | tuple[int, int, int] = 1, return_indices: bool = False, ceil_mode: bool = False)
source

3-D max pooling over a sliding window.

Volumetric downsampling primitive — extends max_pool2d by one depth dimension. Used in 3-D CNNs for medical imaging and video understanding.

Parameters

xTensor
Input of shape (N, C, D, H, W).
kernel_sizeint or (int, int, int)
Size of the pooling window per axis.
strideint or (int, int, int)= None
Window step. Defaults to kernel_size.
paddingint or (int, int, int)= 0
Implicit zero-padding on each spatial side.
dilationint or (int, int, int)= 1
Spacing between window elements. Default 1.
return_indicesbool= False
Must currently be False.
ceil_modebool= False
Use ceil instead of floor in the output-size formula.

Returns

Tensor

Output of shape (N, C, D_out, H_out, W_out) where each spatial dim obeys

Dout=D+2pDdD(kD1)1sD+1D_{\text{out}} = \left\lfloor \frac{D + 2 p_D - d_D (k_D - 1) - 1}{s_D} + 1 \right\rfloor

Notes

Math:

yi,c,d,h,w=maxl,m,nxi,c,sDd+l,sHh+m,sWw+ny_{i,c,d,h,w} = \max_{l,m,n} x_{i,\,c,\,s_D d + l,\,s_H h + m,\,s_W w + n}

Memory cost can become significant for large volumes — when the network only needs a global summary, prefer adaptive_max_pool3d with output_size=(1, 1, 1).

Examples

>>> import lucid
>>> from lucid.nn.functional import max_pool3d
>>> x = lucid.randn(1, 4, 8, 16, 16)
>>> y = max_pool3d(x, kernel_size=2)
>>> y.shape
(1, 4, 4, 8, 8)