Skip to content
fn

max_pool3d

→Tensor
max_pool3d(input: 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, ceil_mode: bool = False, return_indices: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

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

inputTensor
Input of shape (N, C, D, H, W), or (C, D, H, W) unbatched.
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.
ceil_modebool= False
Use ceil instead of floor in the output-size formula.
return_indicesbool= False
Also return (output, indices) — see max_pool1d; the indices are what max_unpool3d takes.

Returns

Tensor

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

Dout=⌊D+2pD−dD(kD−1)−1sD+1⌋D_{\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=max⁡l,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)

Used by 3