You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2021/05/07 19:16:35 UTC

[GitHub] [incubator-mxnet] waytrue17 opened a new pull request #20253: [v1.x] Update ONNX tutorial and doc

waytrue17 opened a new pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253


   ## Description ##
   Update ONNX tutorial and doc
   
   ## Checklist ##
   ### Essentials ###
   - [ ] PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], [FEATURE], [DOC], etc)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage
   - [ ] Code is well-documented
   
   ### Changes ###
   - [ ] Feature1, tests, (and when applicable, API doc)
   - [ ] Feature2, tests, (and when applicable, API doc)
   
   ## 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:
users@infra.apache.org



[GitHub] [incubator-mxnet] waytrue17 commented on a change in pull request #20253: [v1.x] Update ONNX tutorial and doc

Posted by GitBox <gi...@apache.org>.
waytrue17 commented on a change in pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253#discussion_r628563909



##########
File path: python/mxnet/onnx/README.md
##########
@@ -29,6 +29,59 @@ From the 1.9 release and on, the ONNX export module has become an offical, built
 If you are a user of earlier MXNet versions and do not want to upgrade MXNet, you can still enjoy the latest ONNX suppor by pulling the MXNet source code and building the wheel for only the mx2onnx module. Just do `cd python/mxnet/onnx` and then build the wheel with `python3 -m build`. You should be able to find the wheel under `python/mxnet/onnx/dist/mx2onnx-0.0.0-py3-none-any.whl` and install it with `pip install mx2onnx-0.0.0-py3-none-any.whl`. You should be able to access the module with `import mx2onnx` then.
 
 ### APIs
+```python
+mxnet.onnx.export_model(sym, params, in_shapes=None, in_types=np.float32,
+                 onnx_file_path='model.onnx', verbose=False, dynamic=False,
+                 dynamic_input_shapes=None, run_shape_inference=False, input_type=None,
+                 input_shape=None)
+```
+Exports the MXNet model file into ONNX model.
+
+Parameters:
+
+    sym : str or symbol object
+        Path to the MXNet json file or Symbol object
+    params : str or dict or list of dict
+        str - Path to the MXNet params file
+        dict - MXNet params dictionary (Including both arg_params and aux_params)
+        list - list of length 2 that contains MXNet arg_params and aux_params
+    in_shapes : List of tuple
+        Input shape of the model e.g [(1,3,224,224)]
+    in_types : data type or list of data types
+        Input data type e.g. np.float32, or [np.float32, np.int32]
+    onnx_file_path : str
+        Path where to save the generated onnx file
+    verbose : Boolean
+        If True will print logs of the model conversion
+    dynamic: Boolean
+        If True will allow for dynamic input shapes to the model
+    dynamic_input_shapes: list of tuple
+        Specifies the dynamic input_shapes. If None then all dimensions are set to None
+    run_shape_inference : Boolean
+        If True will run shape inference on the model
+    input_type : data type or list of data types
+        This is the old name of in_types. We keep this parameter name for backward compatibility
+    in_shapes : List of tuple
+        This is the old name of in_shapes. We keep this parameter name for backward compatibility
+
+Returns:
+
+    onnx_file_path : str
+        Onnx file path
+
+#### Model with Multiple Input
+When the model has multiple input, all the input shapes and dtypes should be provided with `in_shapes` and `in_dtypes`. Note that the shape/dtype in `in_shapes`/`in_dtypes` must follow the same order as in the MXNet model symbol file. If `in_dtypes` is provided as a single data type, the type will be applied to all input nodes.
+
+#### Dynamic Shape Input
+By setting up optional flags in export_model API, users have the control of partially/fully dynamic shape input export. The flag `dynamic` is set to switch on dynamic shape input export, and `dynamic_input_shapes` is used to specify which dimensions are dynamic (None for dynamic shape).
+
+```python
+# None indicating dynamic shape at a certain dimension

Review comment:
       > I think we might also touch on dynamic shapes in the tutorial as this is a very common use case e.g. different image sizes or sequence lengths. Also I think we can add a section to introduce [onnx-simplifier ](https://github.com/daquexian/onnx-simplifier) as it can significantly simplify the onnx graph in many cases.
   > 
   > CC the author of onnxsim @daquexian: we are releasing mx2onnx in the upcoming mxnet 1.9 release : )
   
   Added dynamic shape input in the tutorial, and a link reference to onnx-simp




-- 
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:
users@infra.apache.org



[GitHub] [incubator-mxnet] waytrue17 commented on pull request #20253: [v1.x] Update ONNX tutorial and doc

Posted by GitBox <gi...@apache.org>.
waytrue17 commented on pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253#issuecomment-834812496


   > I think we might also touch on dynamic shapes in the tutorial as this is a very common use case e.g. different image sizes or sequence lengths. Also I think we can add a section to introduce [onnx-simplifier ](https://github.com/daquexian/onnx-simplifier) as it can significantly simplify the onnx graph in many cases.
   > 
   > CC the author of onnxsim @daquexian: we are releasing mx2onnx in the upcoming mxnet 1.9 release : )
   
   Added dynamic shape input in the tutorial, and a link reference to onnx-simp


-- 
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:
users@infra.apache.org



[GitHub] [incubator-mxnet] Zha0q1 merged pull request #20253: [v1.x] Update ONNX tutorial and doc

Posted by GitBox <gi...@apache.org>.
Zha0q1 merged pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253


   


-- 
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:
users@infra.apache.org



[GitHub] [incubator-mxnet] Zha0q1 edited a comment on pull request #20253: [v1.x] Update ONNX tutorial and doc

Posted by GitBox <gi...@apache.org>.
Zha0q1 edited a comment on pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253#issuecomment-834796347


   I think we might also touch on dynamic shapes in the tutorial as this is a very common use case e.g. different image sizes or sequence lengths. Also I think we can add a section to introduce [onnx-simplifier ](https://github.com/daquexian/onnx-simplifier) as it can significantly simplify the onnx graph in many cases. 
   
   CC the author of onnxsim @daquexian: we are releasing mx2onnx in the upcoming mxnet 1.9 release : )


-- 
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:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #20253: [v1.x] Update ONNX tutorial and doc

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253#issuecomment-834712409


   Hey @waytrue17 , Thanks for submitting the PR 
   All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands: 
   - To trigger all jobs: @mxnet-bot run ci [all] 
   - To trigger specific jobs: @mxnet-bot run ci [job1, job2] 
   *** 
   **CI supported jobs**: [unix-cpu, clang, unix-gpu, edge, windows-gpu, windows-cpu, website, sanity, centos-cpu, centos-gpu, miscellaneous]
   *** 
   _Note_: 
    Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin. 
   All CI tests must pass before the PR can be merged. 
   


-- 
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:
users@infra.apache.org



[GitHub] [incubator-mxnet] Zha0q1 commented on pull request #20253: [v1.x] Update ONNX tutorial and doc

Posted by GitBox <gi...@apache.org>.
Zha0q1 commented on pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253#issuecomment-834796347


   I think we might also touch on dynamic shapes in the tutorial as this is a very common use case e.g. different image sizes or sequence lengths


-- 
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:
users@infra.apache.org



[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #20253: [v1.x] Update ONNX tutorial and doc

Posted by GitBox <gi...@apache.org>.
Zha0q1 commented on a change in pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253#discussion_r628545363



##########
File path: python/mxnet/onnx/README.md
##########
@@ -29,6 +29,59 @@ From the 1.9 release and on, the ONNX export module has become an offical, built
 If you are a user of earlier MXNet versions and do not want to upgrade MXNet, you can still enjoy the latest ONNX suppor by pulling the MXNet source code and building the wheel for only the mx2onnx module. Just do `cd python/mxnet/onnx` and then build the wheel with `python3 -m build`. You should be able to find the wheel under `python/mxnet/onnx/dist/mx2onnx-0.0.0-py3-none-any.whl` and install it with `pip install mx2onnx-0.0.0-py3-none-any.whl`. You should be able to access the module with `import mx2onnx` then.
 
 ### APIs
+```python
+mxnet.onnx.export_model(sym, params, in_shapes=None, in_types=np.float32,
+                 onnx_file_path='model.onnx', verbose=False, dynamic=False,
+                 dynamic_input_shapes=None, run_shape_inference=False, input_type=None,
+                 input_shape=None)
+```
+Exports the MXNet model file into ONNX model.
+
+Parameters:
+
+    sym : str or symbol object
+        Path to the MXNet json file or Symbol object
+    params : str or dict or list of dict
+        str - Path to the MXNet params file
+        dict - MXNet params dictionary (Including both arg_params and aux_params)
+        list - list of length 2 that contains MXNet arg_params and aux_params
+    in_shapes : List of tuple
+        Input shape of the model e.g [(1,3,224,224)]
+    in_types : data type or list of data types
+        Input data type e.g. np.float32, or [np.float32, np.int32]
+    onnx_file_path : str
+        Path where to save the generated onnx file
+    verbose : Boolean
+        If True will print logs of the model conversion
+    dynamic: Boolean
+        If True will allow for dynamic input shapes to the model
+    dynamic_input_shapes: list of tuple
+        Specifies the dynamic input_shapes. If None then all dimensions are set to None
+    run_shape_inference : Boolean
+        If True will run shape inference on the model
+    input_type : data type or list of data types
+        This is the old name of in_types. We keep this parameter name for backward compatibility
+    in_shapes : List of tuple
+        This is the old name of in_shapes. We keep this parameter name for backward compatibility
+
+Returns:
+
+    onnx_file_path : str
+        Onnx file path
+
+#### Model with Multiple Input
+When the model has multiple input, all the input shapes and dtypes should be provided with `in_shapes` and `in_dtypes`. Note that the shape/dtype in `in_shapes`/`in_dtypes` must follow the same order as in the MXNet model symbol file. If `in_dtypes` is provided as a single data type, the type will be applied to all input nodes.
+
+#### Dynamic Shape Input
+By setting up optional flags in export_model API, users have the control of partially/fully dynamic shape input export. The flag `dynamic` is set to switch on dynamic shape input export, and `dynamic_input_shapes` is used to specify which dimensions are dynamic (None for dynamic shape).
+
+```python
+# None indicating dynamic shape at a certain dimension

Review comment:
       here the dynamic shape can also be something like ('batch', 'seq_length') i.e. using strings rather than None




-- 
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:
users@infra.apache.org



[GitHub] [incubator-mxnet] waytrue17 commented on a change in pull request #20253: [v1.x] Update ONNX tutorial and doc

Posted by GitBox <gi...@apache.org>.
waytrue17 commented on a change in pull request #20253:
URL: https://github.com/apache/incubator-mxnet/pull/20253#discussion_r628563909



##########
File path: python/mxnet/onnx/README.md
##########
@@ -29,6 +29,59 @@ From the 1.9 release and on, the ONNX export module has become an offical, built
 If you are a user of earlier MXNet versions and do not want to upgrade MXNet, you can still enjoy the latest ONNX suppor by pulling the MXNet source code and building the wheel for only the mx2onnx module. Just do `cd python/mxnet/onnx` and then build the wheel with `python3 -m build`. You should be able to find the wheel under `python/mxnet/onnx/dist/mx2onnx-0.0.0-py3-none-any.whl` and install it with `pip install mx2onnx-0.0.0-py3-none-any.whl`. You should be able to access the module with `import mx2onnx` then.
 
 ### APIs
+```python
+mxnet.onnx.export_model(sym, params, in_shapes=None, in_types=np.float32,
+                 onnx_file_path='model.onnx', verbose=False, dynamic=False,
+                 dynamic_input_shapes=None, run_shape_inference=False, input_type=None,
+                 input_shape=None)
+```
+Exports the MXNet model file into ONNX model.
+
+Parameters:
+
+    sym : str or symbol object
+        Path to the MXNet json file or Symbol object
+    params : str or dict or list of dict
+        str - Path to the MXNet params file
+        dict - MXNet params dictionary (Including both arg_params and aux_params)
+        list - list of length 2 that contains MXNet arg_params and aux_params
+    in_shapes : List of tuple
+        Input shape of the model e.g [(1,3,224,224)]
+    in_types : data type or list of data types
+        Input data type e.g. np.float32, or [np.float32, np.int32]
+    onnx_file_path : str
+        Path where to save the generated onnx file
+    verbose : Boolean
+        If True will print logs of the model conversion
+    dynamic: Boolean
+        If True will allow for dynamic input shapes to the model
+    dynamic_input_shapes: list of tuple
+        Specifies the dynamic input_shapes. If None then all dimensions are set to None
+    run_shape_inference : Boolean
+        If True will run shape inference on the model
+    input_type : data type or list of data types
+        This is the old name of in_types. We keep this parameter name for backward compatibility
+    in_shapes : List of tuple
+        This is the old name of in_shapes. We keep this parameter name for backward compatibility
+
+Returns:
+
+    onnx_file_path : str
+        Onnx file path
+
+#### Model with Multiple Input
+When the model has multiple input, all the input shapes and dtypes should be provided with `in_shapes` and `in_dtypes`. Note that the shape/dtype in `in_shapes`/`in_dtypes` must follow the same order as in the MXNet model symbol file. If `in_dtypes` is provided as a single data type, the type will be applied to all input nodes.
+
+#### Dynamic Shape Input
+By setting up optional flags in export_model API, users have the control of partially/fully dynamic shape input export. The flag `dynamic` is set to switch on dynamic shape input export, and `dynamic_input_shapes` is used to specify which dimensions are dynamic (None for dynamic shape).
+
+```python
+# None indicating dynamic shape at a certain dimension

Review comment:
       Updated the description




-- 
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:
users@infra.apache.org