Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why AvgPool2d instead of AdaptiveAvgPool2d for ResNet? #16

Open
chihyaoma opened this issue Nov 19, 2019 · 3 comments
Open

Why AvgPool2d instead of AdaptiveAvgPool2d for ResNet? #16

chihyaoma opened this issue Nov 19, 2019 · 3 comments

Comments

@chihyaoma
Copy link

Hi

Thank you for sharing this project with us! I am curious why did you change the default AdaptiveAvgPool2d of ResNet to AvgPool2d. How does this change affect the performance?

Your AvgPool2d layer:
https://github.com/HobbitLong/CMC/blob/master/models/resnet.py#L124

Pytorch's AdaptiveAvgPool2d layer:
https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py#L153

@HobbitLong
Copy link
Owner

HobbitLong commented Nov 26, 2019

Hi, @chihyaoma ,

AvgPool2d is used in previous version of Pytorch's official implementation. Now they switch to AdaptiveAvgPool2d. I guess it's essentially the same in my case as the feature map before the pooling layer is right 7x7, please correct me if I am wrong.

@IgorSusmelj
Copy link

No, it might only be the same for your current code since you resize the input data to 224x224 pixels.
The adaptive version ensures a predefined output shape whereas the normal version just pools the input features according to kernel size and stride.
This can be very handy for changing the input resolution of the image with keeping the output feature size the same.

@HobbitLong
Copy link
Owner

HobbitLong commented Nov 26, 2019

Hi, @IgorSusmelj ,

Thanks for pointing this out. That's what I mean, since the standard input is 224x224, then the size before the final pooling layer is always 7x7. Therefore in this case, both are essentially the same. It might be different in other resolutions, though.

Sorry for not being very clear at the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants