AdaptiveMaxPool2d

class AdaptiveMaxPool2d(oshp, **kwargs)[源代码]

对输入数据进行 2D 最大池化。

例如,给定形状为 \((N, C, H, W)\) 的输入以及输出形状 \((OH, OW)\) ,该层产生形状为 \((N, C, OH, OW)\) 的输出。生成过程描述如下:

\[\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}\]

kernel_sizestride 可以从输入输出的形状推断:

  • padding: (0, 0)

  • stride: (floor(IH / OH), floor(IW / OW))

  • kernel_size: (IH - (OH - 1) * stride_h, IW - (OW - 1) * stride_w)

参数

oshp (Union[Tuple[int, int], int, Tensor]) – the target output shape of the image of the form Height * Width. Can be tuple (H, W) or a single H for a square image H * H.

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}, W_{out})=\text{output\_shape}\).

返回

module. The instance of the AdaptiveMaxPool2d module.

返回类型

Return type

实际案例

>>> import numpy as np
>>> m = M.AdaptiveMaxPool2d((2, 2))
>>> inp = mge.tensor(np.arange(0, 16).astype("float32").reshape(1, 1, 4, 4))
>>> oup = m(inp)
>>> oup.numpy()
array([[[[ 5.,  7.],
         [13., 15.]]]], dtype=float32)