# AvgPool2d¶

$out(N_i, C_j, h, w) = \frac{1}{kH * kW} \sum_{m=0}^{kH-1} \sum_{n=0}^{kW-1} input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)$

padding 非零， 则输入数据会被隐式地在两边用零值进行填充（pad) padding 个点。

• kernel_size (Union[int, Tuple[int, int]]) – 窗的大小。

• stride (Union[int, Tuple[int, int]]) – 窗口的步长。默认值是 kernel_size

• padding (Union[int, Tuple[int, int]]) – 将被隐式填充到两边的零的数量。默认值：0.

Shape:
• Input: $$(N, C, H_{in}, W_{in})$$ or $$(C, H_{in}, W_{in})$$.

• Output: $$(N, C, H_{out}, W_{out})$$ or $$(C, H_{out}, W_{out})$$, where

$H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[0] - \text{kernel\_size}[0]}{\text{stride}[0]} + 1\right\rfloor$
$W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[1] - \text{kernel\_size}[1]}{\text{stride}[1]} + 1\right\rfloor$

module. The instance of the AvgPool2d module.

Return type

>>> import numpy as np
>>> m = M.AvgPool2d(kernel_size=2, stride=2, padding=[1,0], mode="average")
>>> inp = mge.tensor(np.arange(1 * 1 * 3 * 4).astype(np.float32).reshape(1, 1, 3, 4))
>>> output = m(inp)
>>> output
Tensor([[[[0.25 1.25]
[6.5  8.5 ]]]], device=xpux:0)