mindspore.mint.nn.functional.avg_pool1d
- mindspore.mint.nn.functional.avg_pool1d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True)[source]
Applies a 1D average pooling over an input Tensor which can be regarded as a composition of 1D input planes.
Typically the input is of shape \((N_{in}, C_{in}, L_{in})\), avg_pool1d outputs regional average in the \((L_{in})\)-dimension. Given kernel size as \(ks = l_{ker}\) and stride as \(s = s_0\), the operation is as follows.
\[\text{output}(N_i, C_j, l) = \frac{1}{l_{ker}} \sum_{n=0}^{l_{ker}-1} \text{input}(N_i, C_j, s_0 \times l + n)\]Warning
This is an experimental API that is subject to change or deletion.
- Parameters
input (Tensor) – Tensor of shape \((N, C_{in}, L_{in})\).
kernel_size (Union(int, tuple[int])) – The size of kernel window used to take the average value.
stride (Union(int, tuple[int]), optional) – The distance of kernel moving. stride can either be an int number or a tuple of one int number. Default:
None
, the same value as kernel_size.padding (Union(int, tuple[int]), optional) – The pad length to be filled. padding can either be an integer or a tuple of one integer. Default:
0
.ceil_mode (bool, optional) – If True, apply ceil instead of floor to compute the output shape. Default:
False
.count_include_pad (bool, optional) – If True, include the zero-padding in the averaging calculation. Default:
True
.
- Returns
Tensor of shape \((N, C_{in}, L_{out})\).
- Raises
TypeError – If input is not a Tensor.
TypeError – If kernel_size or stride is not an int.
TypeError – If ceil_mode or count_include_pad is not a bool.
ValueError – If kernel_size or stride is less than 1.
ValueError – If kernel_size or stride or padding is not int nor a tuple whose length is greater than 1.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, mint >>> input_x = Tensor(np.random.randint(0, 10, [1, 3, 6]), mindspore.float32) >>> output = mint.nn.functional.avg_pool1d(input_x, kernel_size=6, stride=1) >>> print(output.shape) (1, 3, 1)