vinitra opened a new pull request #17711: [ONNX export] Fixing spatial export 
for batchnorm
URL: https://github.com/apache/incubator-mxnet/pull/17711
 
 
   ## Description ##
   In the ONNX model zoo, we noticed that models like ArcFace and DUC that have 
been exported from mxnet with batchnorm operators are not treating spatial mode 
correctly. 
   
   https://github.com/onnx/models/issues/156
   https://github.com/onnx/models/issues/91#issuecomment-540312125
   
   Quoting from [MxNet BatchNorm 
documentation](https://mxnet.apache.org/api/python/docs/tutorials/packages/gluon/training/normalization/index.html):
 "One of the most popular normalization techniques is Batch Normalization, 
usually called BatchNorm for short. We normalize the activations across all 
samples in a batch for each of the channels independently."
   
   The comment in the exporter refers to mean and variance per feature, instead 
of per channel. Fixing this will mean that spatial mode should be 1, instead of 
0 in the ONNX export.
   
   Changing spatial to 1 fixed these models, in accordance with the issue 
referenced above.
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to 
the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) 
created (except PRs with tiny changes)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding 
a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing 
distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a 
new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments 
are documented. 
   - For new examples, README.md is added to explain the what the example does, 
the source of the dataset, expected performance on test set and reference to 
the original paper if applicable
   - Check the API doc at 
https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [ ] To the best of my knowledge, examples are either not affected by this 
change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Fixing onnx export for batchnorm spatial mode
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be 
made.
   - Interesting edge cases to note here
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to