# mindspore.ops.AvgPool3D

3D Average pooling operation.

Applies a 3D average pooling over an input Tensor which can be regarded as a composition of 3D input planes. Typically the input is of shape $$(N, C, D_{in}, H_{in}, W_{in})$$, AvgPool3D outputs regional average in the $$(D_{in}, H_{in}, W_{in})$$-dimension. Given kernel size $$ks = (d_{ker}, h_{ker}, w_{ker})$$ and stride $$s = (s_0, s_1, s_2)$$, the operation is as follows.

Warning

“kernel_size” is in the range [1, 255]. “strides” is in the range [1, 63].

$\text{output}(N_i, C_j, d, h, w) = \frac{1}{d_{ker} * h_{ker} * w_{ker}} \sum_{l=0}^{d_{ker}-1} \sum_{m=0}^{h_{ker}-1} \sum_{n=0}^{w_{ker}-1} \text{input}(N_i, C_j, s_0 \times d + l, s_1 \times h + m, s_2 \times w + n)$
Parameters
• kernel_size (Union[int, tuple[int]]) – The size of kernel used to take the average value, is an int number that represents depth, height and width are both kernel_size, or a tuple of three int numbers that represent depth, height and width respectively. Default: 1.

• strides (Union[int, tuple[int]]) – The distance of kernel moving, an int number that represents the depth, height and width of movement are both strides, or a tuple of three int numbers that represent depth, height and width of movement respectively. Default: 1.

The optional value for pad mode, is “SAME”, “VALID”, “PAD”. Default: “VALID”.

• same: Adopts the way of completion. The depth, height and width of the output will be the same as the input. The total number of padding will be calculated in depth, horizontal and vertical directions and evenly distributed to head and tail, top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the tail, bottom and the right side. If this mode is set, pad must be 0.

• valid: Adopts the way of discarding. The possible largest depth, height and width of output will be returned without padding. Extra pixels will be discarded. If this mode is set, pad must be 0.

• pad: Implicit paddings on both sides of the input in depth, height, width. The number of pad will be padded to the input Tensor borders. pad must be greater than or equal to 0.

• ceil_mode (bool) – If True, ceil instead of floor to compute the output shape. Default: False.

• count_include_pad (bool) – If True, averaging calculation will include the zero-padding. Default: True.

• divisor_override (int) – If specified, it will be used as divisor in the averaging calculation, otherwise kernel_size will be used. Default: 0.

• data_format (str) – The optional value for data format. Currently only support ‘NCDHW’. Default: ‘NCDHW’.

Inputs:
• x (Tensor) - Tensor of shape $$(N, C, D_{in}, H_{in}, W_{in})$$. Currently support float16 and float32 data type.

Outputs:

Tensor, with shape $$(N, C, D_{out}, H_{out}, W_{out})$$. Has the same data type with x.

Raises
• TypeError – If kernel_size, strides or pad is neither an int not a tuple.

• TypeError – If ceil_mode or count_include_pad is not a bool.

• TypeError – If pad_mode or data_format is not a string.

• TypeError – If divisor_override is not an int.

• ValueError – If numbers in kernel_size or strides are not positive.

• ValueError – If kernel_size or strides is a tuple whose length is not equal to 3.

• ValueError – If pad_mode is not one of ‘same’, ‘valid’ or ‘pad’.

• ValueError – If pad is a tuple whose length is not equal to 6.

• ValueError – If element of pad is less than 0.

• ValueError – If pad_mode is not equal to ‘pad’ and pad is not equal to 0 or (0, 0, 0, 0, 0, 0).

• ValueError – If data_format is not ‘NCDHW’.

Supported Platforms:

Ascend

Examples

>>> x = Tensor(np.arange(1 * 2 * 2 * 2 * 3).reshape((1, 2, 2, 2, 3)), mindspore.float16)
>>> avg_pool3d = ops.AvgPool3D(kernel_size=2, strides=1, pad_mode="valid")
>>> output = avg_pool3d(x)
>>> print(output)
[[[[[ 5.  6.]]]
[[[17. 18.]]]]]