AdaptiveAvgPool1d(N)
对一个C*H*W的三维输入Tensor, 池化输出为C*H*N, 即按照H轴逐行对W轴平均池化
>>> a = torch.ones(2,3,4)
>>> a[0,1,2] = 0
>>>> a
tensor([[[1., 1., 1., 1.],
[1., 1., 0., 1.],
[1., 1., 1., 1.]],
[[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]]])
>>> nn.AdaptiveAvgPool1d(5)(a)
tensor([[[1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
[1.0000, 1.0000, 0.5000, 0.5000, 1.0000],
[1.0000, 1.0000, 1.0000, 1.0000, 1.0000]],
[[1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
[1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
[1.0000, 1.0000, 1.0000, 1.0000, 1.0000]]])
>>> nn.AdaptiveAvgPool1d(1)(a)
tensor([[[1.0000],
[0.7500],
[1.0000]],
[[1.0000],
[1.0000],
[1.0000]]])
AdaptiveAvgPool2d((M,N))
对一个B*C*H*W的四维输入Tensor, 池化输出为B*C*M*N, 即按照C轴逐通道对H*W平面平均池化
>>> a = torch.ones(2,2,3,4)
>>> a[:,:,:,1] = 0
>>> a
tensor([[[[1., 0., 1., 1.],
[1., 0., 1., 1.],
[1., 0., 1., 1.]],
[[1., 0., 1., 1.],
[1., 0., 1., 1.],
[1., 0., 1., 1.]]],
[[[1., 0., 1., 1.],
[1., 0., 1., 1.],
[1., 0., 1., 1.]],
[[1., 0., 1., 1.],
[1., 0., 1., 1.],
[1., 0., 1., 1.]]]])
>>> nn.AdaptiveAvgPool2d((1,2))(a)
tensor([[[[0.5000, 1.0000]],
[[0.5000, 1.0000]]],
[[[0.5000, 1.0000]],
[[0.5000, 1.0000]]]])
>>> nn.AdaptiveAvgPool2d(1)(a)
tensor([[[[0.7500]],
[[0.7500]]],
[[[0.7500]],
[[0.7500]]]])
AdaptiveAvgPool3d((M,N,K))
对一个B*C*D*H*W的五维输入Tensor, 池化输出为B*C*M*N*K, 即按照C轴逐通道对D*H*W平面平均池化
>>> a = torch.ones(1,2,2,3,4)
>>> a[0,0,:,:,0:2] = 0
>>> a
tensor([[[[[0., 0., 1., 1.],
[0., 0., 1., 1.],
[0., 0., 1., 1.]],
[[0., 0., 1., 1.],
[0., 0., 1., 1.],
[0., 0., 1., 1.]]],
[[[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]],
[[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]]]]])
>>> nn.AdaptiveAvgPool3d((1,1,2))(a)
tensor([[[[[0., 1.]]],
[[[1., 1.]]]]])
>>> nn.AdaptiveAvgPool3d(1)(a)
tensor([[[[[0.5000]]],
[[[1.0000]]]]])