krishna511
(krishna Chauhan)
June 29, 2021, 5:40pm
1
A=torch.rand(8,64,6,15)
m = nn.AdaptiveAvgPool2d(1)
o=m(A)
o.shape
>>torch.Size([8, 64, 1, 1])
Here what I am grasping is every 6*15
will be average to get a single value. Then
A=torch.rand(8,64,6,15)
m = nn.AdaptiveAvgPool2d(2)
o=m(A)
o.shape
>>torch.Size([8, 64, 2, 2])
Here the output shape indicates that every 5*14
grid is average to get this shape 2*2
?
So the output size is denoted in kernel??
Am I right ?
1 Like
Epoching
(Amar Saini)
June 29, 2021, 6:27pm
2
Looks correct to me according to python - What is Adaptive average pooling and How does it work? - Stack Overflow :
Stride = (input_size//output_size)
Kernel size = input_size - (output_size-1)*stride
Padding = 0
krishna511
(krishna Chauhan)
June 29, 2021, 6:44pm
3
Could u plz explain these three lines, I guess for second example stride is 1, is there any explicit way to mention stride, or is this the formula to calculate stride.
1 Like
Epoching
(Amar Saini)
June 29, 2021, 7:00pm
4
For nn.AdaptiveAvgPool2d
, you just specify the output size, stride will always be 1 (every possible grid will be used to achieve the output size):
torch.nn.AdaptiveAvgPool2d(output_size)
according to AdaptiveAvgPool2d — PyTorch 1.9.0 documentation
The formulas above I believe is to calculate kernel size given input size, output size, and stride, (i.e. the size of the grids)
krishna511
(krishna Chauhan)
June 30, 2021, 5:37am
5
Overall My answers are correct, actually there is no need for this much confusion here, The output size given in function only, which is required after avg pooling that’s it.
1 Like
Epoching
(Amar Saini)
June 30, 2021, 5:49am
6
Nice! Yea sorry if I misunderstood anything/made things confusing!
1 Like
Epoching
(Amar Saini)
June 30, 2021, 5:54am
7
Here the output shape indicates that every 5*14
grid is average to get this shape 2*2
?
Am I right ?
Completely correct
Also just noticed I linked to AvgPool2d
rather than AdaptiveAvgPool2d
: AdaptiveAvgPool2d — PyTorch 1.9.0 documentation . Sorry about that (just edited the reply)
The output size given in function only, which is required after avg pooling that’s it.
Exactly this, it’s the only argument we can specify! I’d imagine the stride is always 1 for the formulas mentioned above, i.e. every possible grid is used, like you said!
1 Like
Epoching
(Amar Saini)
June 30, 2021, 6:25am
9
No problem, thanks for posting @krishna511 , I learned something new haha!