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

Changing to AdaptiveAvgPool2d on Alexnet #746

Merged
merged 1 commit into from
Feb 14, 2019
Merged

Changing to AdaptiveAvgPool2d on Alexnet #746

merged 1 commit into from
Feb 14, 2019

Conversation

ekagra-ranjan
Copy link
Contributor

@ekagra-ranjan ekagra-ranjan commented Feb 13, 2019

The update allows Alexnet to process images larger 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.

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.
@TheCodez
Copy link
Contributor

Doesn't this change the accuracy?

@fmassa
Copy link
Member

fmassa commented Feb 13, 2019

I believe the output should be the same if the images have the same size as before (224x224). @ekagra-ranjan can you double-check?

@ekagra-ranjan
Copy link
Contributor Author

ekagra-ranjan commented Feb 13, 2019

Yes @fmassa, it won't change if we pass the original input dimension on which the net was trained. This is because AdaptiveAvgPool will receive a Cx6x6 input (if you pass the precribed imagnet size by AlexNet) and so the output will be equal to the input as AdaptiveAvgPool has output dim as Cx6x6 also, making the predictions unchanged.

If you pass larger sized images then it might be different compared to the original input size for the same task but that won't matter as your aim is to train the net on your larger resolution for whatever reason like maybe improving the performance by passing higher resolution images.

@ekagra-ranjan
Copy link
Contributor Author

@TheCodez if your confusion was due to my description that the modification could handle smaller input dimensions then sorry for that. I have made the correction in my description.

@TheCodez
Copy link
Contributor

@ekagra-ranjan thanks for the explanation 👍

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!

@fmassa fmassa merged commit 6434dea into pytorch:master Feb 14, 2019
@franciscocms
Copy link

franciscocms commented Mar 4, 2020

And for inputs smaller than 224? I'm working with 80x80 images, and I'm not sure if I should process these images to fit the network or to manually change the input that is expected by the network. Also, if I change the input, I must change the filter's parameters so every layer has a correct output size, right? Thank you

@fmassa
Copy link
Member

fmassa commented Mar 4, 2020

@franciscocms in this case, I would say you should resize the images to be 224x224.

If you still want to use 80x80, you'll need to change the network structure to fit your data, but it won't be the exact same model anymore.

@franciscocms
Copy link

@fmassa thank you for your answer! What type of resizing would you consider? Like padding with reflection in order to achieve the 224x224(or close to that) image? I've made some calculations and saw that if I used the 80x80 input, the output of the convolutional part will be 2x2x256, which I think is really small, and some information per filter might get lost.

@ekagra-ranjan
Copy link
Contributor Author

@franciscocms You can try those out things. IMO, interpolating the 80x80 images to 224x224 could work better.

@franciscocms
Copy link

Ok, I'll try it out! Thank you!

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

Successfully merging this pull request may close these issues.

4 participants