megengine.functional.nn.avg_pool2d¶
- avg_pool2d(inp, kernel_size, stride=None, padding=0, mode='average_count_exclude_padding')[源代码]¶
对输入进行二维平均池化。
更多信息参见
AvgPool2d
。- 参数
inp (
Tensor
) – input tensor of shape \((N, C, H_{\text{in}}, W_{\text{in}})\) .kernel_size (
Union
[int
,Tuple
[int
,int
]]) – size of the window used to calculate the average value.stride (
Union
[int
,Tuple
[int
,int
],None
]) – stride of the window. Default value iskernel_size
.padding (
Union
[int
,Tuple
[int
,int
]]) – implicit zero padding 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”
- 返回类型
- 返回
output tensor of shape \((N, C, H_{\text{out}}, W_{\text{out}})\).
实际案例
>>> import numpy as np >>> inp = Tensor(np.arange(1 * 1 * 3 * 4).astype(np.float32).reshape(1, 1, 3, 4)) >>> F.avg_pool2d(inp, kernel_size=2, stride=2, padding=[1,0], mode="average") Tensor([[[[0.25 1.25] [6.5 8.5 ]]]], device=xpux:0)