torch.nn.AdaptiveAvgPool2d() 自适应平均池化函数,该函数只需要给定输出特征图的大小,其中通道数前后不变。
例子
m = nn.AdaptiveAvgPool2d((3,7))
input = torch.randn(1, 64, 8, 9)
print(m(input))
#torch.Size([1, 64, 3, 7])
m = nn.AdaptiveAvgPool2d(7)
input = torch.randn(1, 64, 10, 9)
print(m(input))
#torch.Size([1, 64, 7, 7])
m = nn.AdaptiveAvgPool2d((None, 3))
input = torch.randn(1, 64, 10, 9)
print(m(input))
#torch.Size([1, 64, 10, 3])