class MaxPool2d(kernel_size, stride=None, padding=0, **kwargs)[源代码]

对输入数据进行2D最大值池化(max pooling)。

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:

\[\begin{aligned} out(N_i, C_j, h, w) ={} & \max_{m=0, \ldots, kH-1} \max_{n=0, \ldots, kW-1} \text{input}(N_i, C_j, \text{stride[0]} \times h + m, \text{stride[1]} \times w + n) \end{aligned}\]

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



>>> import numpy as np
>>> m = M.MaxPool2d(kernel_size=3, stride=1, padding=0)
>>> inp = mge.tensor(np.arange(0, 16).astype("float32").reshape(1, 1, 4, 4))
>>> oup = m(inp)
>>> oup.numpy()
array([[[[10., 11.],
         [14., 15.]]]], dtype=float32)