class oneflow.nn.AvgPool3d(kernel_size: Union[int, Tuple[int, int, int]], stride: Optional[Union[int, Tuple[int, int, int]]] = None, padding: Union[int, Tuple[int, int, int]] = 0, ceil_mode: bool = False, count_include_pad: bool = True, divisor_override: int = 0)

Applies a 3D average pooling over an input signal composed of several input planes. In the simplest case, the output value of the layer with input size \((N, C, D, H, W)\), output \((N, C, D_{out}, H_{out}, W_{out})\) and kernel_size \((kD, kH, kW)\) can be precisely described as:

\[\begin{split}out(N_i, C_j, d, h, w) = \\frac{1}{kD * kH * kW } \\sum_{k=0}^{kD-1} \\sum_{m=0}^{kH-1} \\sum_{n=0}^{kW-1} input(N_i, C_j, stride[0] \\times d + k, stride[1] \\times h + m, stride[2] \\times w + n)\end{split}\]

If padding is non-zero, then the input is implicitly zero-padded on all three sides for padding number of points.


When ceil_mode=True, sliding windows are allowed to go off-bounds if they start within the left padding or the input. Sliding windows that would start in the right padded region are ignored.

  • kernel_size – the size of the window.

  • strides – the stride of the window. Default value is kernel_size.

  • padding – implicit zero padding to be added on all three sides.

  • ceil_mode – when True, will use ceil instead of floor to compute the output shape.

  • count_include_pad – when True, will include the zero-padding in the averaging calculation.

  • divisor_override – if specified, it will be used as divisor, otherwise kernel_size will be used.

  • Input: \((N, C, D_{in}, H_{in}, W_{in})\)

  • Output: \((N, C, D_{out}, H_{out}, W_{out})\), where

    \[\begin{split}D_{out} = \\left\\lfloor\\frac{D_{in} + 2 \\times \\text{padding}[0] - \\text{kernel_size}[0]}{\\text{stride}[0]} + 1\\right\\rfloor\end{split}\]
    \[\begin{split}H_{out} = \\left\\lfloor\\frac{H_{in} + 2 \\times \\text{padding}[1] - \\text{kernel_size}[1]}{\\text{stride}[1]} + 1\\right\\rfloor\end{split}\]
    \[\begin{split}W_{out} = \\left\\lfloor\\frac{W_{in} + 2 \\times \\text{padding}[2] - \\text{kernel_size}[2]}{\\text{stride}[2]} + 1\\right\\rfloor\end{split}\]

For example:

import oneflow as flow
import numpy as np

m = flow.nn.AvgPool3d(kernel_size=(2,2,2),padding=(0,0,0),stride=(1,1,1))
x = flow.tensor(np.random.randn(9, 7, 11, 32, 20))
y = m(x)
oneflow.Size([9, 7, 10, 31, 19])