adaptive_avg_pool1d¶
根据 output_size
对 Tensor x
计算 1D 自适应平均池化。
注解
详细请参考对应的 Class 请参考:AdaptiveAvgPool1D。
参数¶
x (Tensor) - 自适应平均池化的输入,它是形状为 \([N,C,L]\) 的 3-D Tensor,其中 \(N\) 是批大小,\(C\) 是通道数而 \(L\) 是输入特征的长度,其数据类型为 float32 或 float64。
output_size (int) - 输出特征的长度,数据类型为 int。
name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。
返回¶
Tensor,计算 1D 自适应平均池化的结果,数据类型与输入相同。
代码示例¶
>>> # 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])/(lstart - lend)
>>> #
>>> import paddle
>>> import paddle.nn.functional as F
>>> data = paddle.uniform([1, 3, 32])
>>> pool_out = F.adaptive_avg_pool1d(data, output_size=16)
>>> print(pool_out.shape)
[1, 3, 16]