Skip to content

Changing to AdaptiveAvgPool2d on SqueezeNet and ResNet #643

New issue

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

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

Already on GitHub? # to your account

Merged
merged 3 commits into from
Nov 6, 2018

Conversation

AdanMora
Copy link
Contributor

Hi,

I'm dealing with this problem with the hardcoded AvgPool2d on SqueezeNet, some people notice this a year ago, also in ResNet, so I made these changes, Pytorch must be as robust as possible. I left the other AvgPool2d layers because they have another purpose.

nn.AvgPool2d -> nn.AdaptiveAvgPool2d((1,1)) assures the output's size like (batch_size, num_classes, 1,1) on SqueezeNet and ResNet.

The Average Pool Layer on SqueezeNet and ResNet was hardcoded, this was changed, now any the input size is accepted.
@fmassa
Copy link
Member

fmassa commented Oct 30, 2018

@houseroad will this change break ONNX?

I'm inclined to make all torchvision models take an nn.AdaptiveAvgPool2d(1, 1) instead of a fixed AvgPool2d with fixed kernels.

Copy link
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/pytorch/pytorch/blob/master/torch/onnx/symbolic.py#L599

(1,1) case is supported. I have manually tested SqueezeNet, it works fine. I think this change will NOT break ONNX test.

Thanks.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Adan!

@AdanMora
Copy link
Contributor Author

AdanMora commented Nov 6, 2018

Thanks to you and your work!!

fmassa pushed a commit that referenced this pull request Feb 14, 2019
The update allows Alexnet to process images larger or smaller than prescribed imagenet size using adaptive average pooling. Will be useful while finetuning or testing on different resolution images. Similar to #643 and #672. I did not include adaptive avg pool in features or classifier block so that these predefined blocks can be used as it is.
fmassa pushed a commit that referenced this pull request Feb 14, 2019
The update allows VGG to process images larger or smaller than prescribed imagenet size using adaptive average pooling. Will be useful while finetuning or testing on different resolution images. Similar to #643 and #672. I did not include adaptive avg pool in features or classifier block so that these predefined blocks can be used as it is.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants