AvgPool2d¶
- class AvgPool2d(kernel_size, stride=None, padding=0, mode='average_count_exclude_padding', **kwargs)[源代码]¶
对输入数据进行2D平均池化。
For instance, given an input of the size \((N, C, H_{\text{in}}, W_{\text{in}})\) and
kernel_size
\((kH, kW)\), this layer generates the output of the size \((N, C, H_{\text{out}}, W_{\text{out}})\) through a process described as:\[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
个点。- 参数
stride (
Union
[int
,Tuple
[int
,int
],None
]) – the stride of the window. Default value iskernel_size
.padding (
Union
[int
,Tuple
[int
,int
]]) – implicit zero padding to be added on both sides.Default: 0.mode (
str
) – whether to include the padding values while calculating the average, set to “average” will do counting. Default: “average_count_exclude_padding”
实际案例
>>> 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)