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

Squeezenet model ONNX export #690

Open
lara-hdr opened this issue Dec 17, 2018 · 7 comments
Open

Squeezenet model ONNX export #690

lara-hdr opened this issue Dec 17, 2018 · 7 comments

Comments

@lara-hdr
Copy link
Contributor

Hi,
I have some questions regarding the squeeznet model.

I failed at exporting the model to ONNX with the following error "ONNX export failed : Couldn't export operator aten:max_pool2d_with_indices".
I noticed that in /torch/onnx/symbolic.py , the use of "ceil_mode" is not supported in max_pool2d_with_indices.
After setting "ceil_mode" to False for all occurrences of "MaxPool2d", the export succeeds.

I also noticed that, when using the exported model mentioned above, the Pytorch results do not match the ONNX results, the reason being the use of "nn.Dropout(0.5)".

My questions are :

 1- Is there a particular reason "ceil_mode" is being used? and would there be a concern with setting it to False for the export to be possible? I could submit a PR with this change if no concern is noted.

 2- Why is "Dropout" used in the model outside of training? Could we remove it? 

Thanks

@fmassa
Copy link
Member

fmassa commented Dec 21, 2018

Hi,

About your questions:

1 - I believe SqueezeNet was originally developed in Caffe, for which the implementation of MaxPool2d only supports ceil_mode=True. If we change it to True, it would most certainly crash if we were not using AdaptiveAvgPool2d in the end, and now that we are using it, we might still obtain different results (but I'm not sure by how much).
2 - Dropout behaves differently during training and during testing. I'm not 100% sure that Dropout fully works with ONNX exported models, and might need to be removed before exporting it to ONNX.

@lara-hdr
Copy link
Contributor Author

lara-hdr commented Jan 7, 2019

Hey @fmassa,

1- To check if I understood well, now that AdaptiveAvgPool2d is used, it would be ok to set ceil_mode=False.

If the above statement is correct, here is the PR with modifications from 1- and 2- that will allow exporting the model in ONNX : #709

@soumith
Copy link
Member

soumith commented Jan 9, 2019

@lara-hdr what francisco is saying is that #709 will change the outputs of the model, so it's not really something we should do.

@ywang370
Copy link

@lara-hdr Hi how you convert it? Can you give an instruction? I meet the error that

RuntimeError: ONNX export failed: Couldn't export operator aten::adaptive_avg_pool2d

@lara-hdr
Copy link
Contributor Author

@ywang370, what version of pytorch are you using?
Exporting adaptive_avg_pool2d is supported with the params (1,1) since pytorch/pytorch#9711.
Also the issue with the ceil pooling discussed above should be fixed with pytorch/pytorch#16769.

@ywang370
Copy link

@lara-hdr Thanks for the link, very helpful!

@alejo9719
Copy link

alejo9719 commented Apr 12, 2019

Hi, I cloned and built the latest PyTorch master from GitHub and I exported the pretrained SqueezeNet model to ONNX with it. I didn't have any trouble doing that. I then exported the model with Caffe 2 mobile exporter to an init_net.pb and a predict_net.pb file, in order to use it with the AI Camera example :https://github.com/cedrickchee/pytorch-android. I executed the exported files using "predictor" in Python and it worked perfectly.

However, when I try to execute the model with predictor in Android, the app crashes. It doesn't happen with other models (e.g. MobileNet V2) or with the SqueezeNet protobuf files included in the AI Camera example.

Obviously, I also built/updated the Caffe 2 libraries for Android using the build_android.sh script from PyTorch master before trying to execute the model.

I provide some more detail in here: cedrickchee/pytorch-android#6

Thanks.

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

No branches or pull requests

5 participants