AdaptiveAvgPool1D¶
- class paddle.nn. AdaptiveAvgPool1D ( output_size, name=None ) [source]
-
A 1D adaptive average pooling over an input signal composed of several input planes, based on
output_size
. Input and output are in NCL format, where N is batch size, C is the number of channels and L is the length of the feature. The shape of output will be [N,C,output_size].The formulation for average adaptive pool1d is
lstart=⌊i∗Lin/Lout⌋,lend=⌈(i+1)∗Lin/Lout⌉,Output(i)=∑Input[lstart:lend]lend−lstart.- Parameters
-
output_size (int) – The target output size. Its data type must be int.
name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.
- Returns
-
A callable object for computing 1D adaptive average pooling.
Examples
>>> # average adaptive pool1d >>> # suppose input data in shape of [N, C, L], `output_size` is m or [m], >>> # output shape is [N, C, m], adaptive pool divide L dimension >>> # of input data into m grids averagely and performs poolings in each >>> # grid to get output. >>> # adaptive max pool performs calculations as follow: >>> # >>> # for i in range(m): >>> # lstart = floor(i * L / m) >>> # lend = ceil((i + 1) * L / m) >>> # output[:, :, i] = sum(input[:, :, lstart: lend])/(lend - lstart) >>> # >>> import paddle >>> import paddle.nn as nn >>> data = paddle.uniform([1, 3, 32], dtype="float32", min=-1, max=1) >>> AdaptiveAvgPool1D = nn.AdaptiveAvgPool1D(output_size=16) >>> pool_out = AdaptiveAvgPool1D(data) >>> print(pool_out.shape) [1, 3, 16]
-
forward
(
input
)
forward¶
-
Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
-
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-
extra_repr
(
)
extra_repr¶
-
Extra representation of this layer, you can have custom implementation of your own layer.