mindspore.nn.AvgPool1d
- class mindspore.nn.AvgPool1d(kernel_size=1, stride=1, pad_mode='valid', 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
, AvgPool1d outputs regional average in the -dimension. Given kernel_size and stride , the operation is as follows:- Parameters
kernel_size (int) – The size of kernel window used to take the average value, Default:
1
.stride (int) – The distance of kernel moving, an int number that represents the width of movement is strides, Default:
1
.pad_mode (str) –
"pad"
, case insensitive. Default:"valid"
.same: The width of the output is the same as the value after the input is divided by stride.
valid: Returns the output obtained by effective calculation without padding. The excess pixels that do not meet the calculation will be discarded.
pad: Performs padding on the input. Adds padding size of zeros to both ends of the input. If this mode is set, padding must be greater than or equal to
0
.
padding (Union(int, tuple[int], list[int])) – Pooling padding value, only ‘pad’ mode can be set to non-zero. Default:
0
. padding can only be an integer or a tuple/list containing a single integer, in which case padding times or padding[0] times are padded on both sides of the input.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
.
- Inputs:
x (Tensor) - Tensor of shape
or .
- Outputs:
Tensor of shape
or .If pad_mode is in pad mode, the output shape calculation formula is as follows:
- Raises
TypeError – If kernel_size or stride is not an int.
ValueError – If pad_mode is not ‘valid’ ,’same’ or ‘pad’ with not case sensitive.
ValueError – If kernel_size or strides is less than 1.
ValueError – If length of padding tuple/list is not 1.
ValueError – If length of shape of x is not equal to 2 or 3.
ValueError – If padding is non-zero when pad_mode is not ‘pad’.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore as ms >>> import numpy as np >>> pool = ms.nn.AvgPool1d(kernel_size=6, stride=1) >>> x = ms.Tensor(np.random.randint(0, 10, [1, 3, 6]), ms.float32) >>> output = pool(x) >>> result = output.shape >>> print(result) (1, 3, 1) >>> pool2 = ms.nn.AvgPool1d(4, stride=1, ceil_mode=True, pad_mode='pad', padding=2) >>> x1 = ms.ops.randn(6, 6, 8) >>> output = pool2(x1) >>> print(output.shape) (6, 6, 9)