mindspore.nn.AvgPool3d
- class mindspore.nn.AvgPool3d(kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True, divisor_override=None)[source]
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})\), and AvgPool3D outputs regional average in the \((D_{in}, H_{in}, W_{in})\)-dimension. Given kernel size is \(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]. stride 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, can be an int number that represents depth, height and width, or a tuple of three int numbers that represent depth, height and width respectively. The value must be a positive integer.
stride (Union[int, tuple[int]]) – The distance of kernel moving, can be an int number that represents the depth, height and width of movement, or a tuple of three int numbers that represent depth, height and width of movement respectively. The value must be a positive integer. If the value is None, the default value kernel_size is used.
padding (Union(int, tuple[int])) – The padding value to be filled. Default: 0. The value cannot be negative. If padding is an integer, the paddings of head, tail, top, bottom, left and right are the same, equal to padding. If padding is a tuple of six integers, the padding of head, tail, top, bottom, left and right equal to padding[0], padding[1], padding[2], padding[3], padding[4] and padding[5] correspondingly.
ceil_mode (bool) – If True, use ceil to compute the output shape instead of floor. 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: None.
- Inputs:
x (Tensor) - Tensor of shape \((N, C, D_{in}, H_{in}, W_{in})\) or \((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})\) or \((C, D_{in}, H_{in}, W_{in})\), with the same data type as x.
- Raises
TypeError – If kernel_size, stride or padding is neither an int nor a tuple.
TypeError – If ceil_mode or count_include_pad is not a bool.
TypeError – If data_format is not a string.
TypeError – If divisor_override is not an int.
ValueError – If numbers in kernel_size or stride are not positive.
ValueError – If kernel_size or stride is a tuple whose length is not equal to 3.
ValueError – If padding is a tuple whose length is not equal to 6.
ValueError – If element of padding is less than 0.
ValueError – If length of shape of x is not equal to 5.
- Supported Platforms:
Ascend
CPU
Examples
>>> import mindspore as ms >>> import mindspore.nn as nn >>> import numpy as np >>> pool = nn.AvgPool3d(kernel_size=3, stride=1) >>> x = ms.Tensor(np.random.randint(0, 10, [1, 2, 4, 4, 5]), ms.float32) >>> output = pool(x) >>> print(output.shape) (1, 2, 2, 2, 3)