class

AvgPool3d

extendsModule
AvgPool3d(kernel_size: _Size3d, stride: _Size3d | None = None, padding: _Size3d = 0, ceil_mode: bool = False, count_include_pad: bool = True, divisor_override: int | None = None)
source

Applies 3-D average pooling over a volumetric feature map.

Computes the arithmetic mean of values in a kD×kH×kWk_D \times k_H \times k_W sliding window:

y[n,c,d,h,w]=1Wkd=0kD1kh=0kH1kw=0kW1x ⁣[n,c,dsD+kd,hsH+kh,wsW+kw]y[n,c,d,h,w] = \frac{1}{|W|} \sum_{k_d=0}^{k_D-1}\sum_{k_h=0}^{k_H-1}\sum_{k_w=0}^{k_W-1} x\!\left[n,\,c,\, d \cdot s_D + k_d,\, h \cdot s_H + k_h,\, w \cdot s_W + k_w \right]

where W=kDkHkW|W| = k_D k_H k_W when count_include_pad=True.

Output dimensions mirror those of MaxPool3d.

Parameters

kernel_sizeint or tuple[int, int, int]
Size of the averaging window along (D, H, W).
strideint or tuple[int, int, int] or None= None
Step between windows. Defaults to kernel_size.
paddingint or tuple[int, int, int]= 0
Zero-padding on all six faces. Default: 0.
ceil_modebool= False
Use ceiling for output size. Default: False.
count_include_padbool= True
Include zero-padded elements in the denominator. Default: True.
divisor_overrideint or None= None
If set, use this value as the divisor instead of the window size. (Stored but not yet applied in the current implementation.) Default: None.

Attributes

kernel_sizeint or tuple[int, int, int]
strideint or tuple[int, int, int] or None
paddingint or tuple[int, int, int]
ceil_modebool
count_include_padbool

Notes

  • Input: (N, C, D_in, H_in, W_in)
  • Output: (N, C, D_out, H_out, W_out)
  • 3-D average pooling is the natural extension of 2-D GAP to video and volumetric data; global 3-D average pooling collapses (D, H, W) to (1, 1, 1) for a compact feature vector.
  • Gradients are distributed uniformly over all elements in a window, which can help maintain stable training compared to max pooling.

Examples

Reduce temporal resolution while keeping spatial size:
>>> import lucid
>>> import lucid.nn as nn
>>> pool = nn.AvgPool3d(kernel_size=(2, 1, 1), stride=(2, 1, 1))
>>> x = lucid.ones((1, 16, 16, 8, 8))
>>> y = pool(x)
>>> y.shape
(1, 16, 8, 8, 8)
Halve all three dimensions simultaneously:
>>> pool = nn.AvgPool3d(kernel_size=2, stride=2)
>>> x = lucid.ones((2, 32, 8, 8, 8))
>>> y = pool(x)
>>> y.shape
(2, 32, 4, 4, 4)

Methods (3)

dunder

__init__

None
__init__(kernel_size: _Size3d, stride: _Size3d | None = None, padding: _Size3d = 0, ceil_mode: bool = False, count_include_pad: bool = True, divisor_override: int | None = None)
source

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

fn

forward

Tensor
forward(x: Tensor)
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.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.