Adaptive_avg_pool2d vs avg_pool2d

I am not sure how nn.AdaptiveAvgPool2d works…
I defined a tensor of shape (1,1,3,3)

inp = torch.tensor([[[[1,2.,3], [4,5,6], [7,8,9]]]], dtype = torch.float)

print(inp .shape)
print(inp)
torch.Size([1, 1, 3, 3])
tensor([[[[1., 2., 3.],
          [4., 5., 6.],
          [7., 8., 9.]]]])

Then i applied AdaptiveAvgPool2d on it and the result was not what i had expected.

out = nn.AdaptiveAvgPool2d((2,2))(inp)
print(out)
tensor([[[[3., 4.],
          [6., 7.]]]])

I thought the result would look like

tensor([[[[5., 6.],
          [8., 9.]]]])

Please correct me understnding how adaptive pooling works. Thanks in advance ! :slight_smile:

2 Likes