...
To implement the import/export functionality in MXNet, I propose to expose a MXNet python module to do the model conversion:
- “serde”(serialization/deserialization - name taken from Apache Hive project) which can be called as (mx.serde.import/ mx.serde.export)
- OR It can also go under contrib. MXNet contrib is used to add experimental features which can be later moved outside. This can qualify as an experimental feature as there is a gap in operator implementation. (See Appendix)
mx.contrib.serde.import/ mx.contrib.serde.export
This wrapper serialization/deserialization module should have following methods supporting different formats:
Import model into mxnet.
sym, params = mx.serde.import(input_file, in_format=‘onnx’, out_format=’gluon’)
...
- sym : model definition
- module : mxnet module object
- gluon_model : model definition (HybridBlock)
- params : weights
- format : onnx, coreml
- filename_prefix: a filename prefix to be used to model save files. E.g., for onnx, a binary protobuf will be written to output file with “.onnx” extension.
In addition to this core format conversion module(`serde`), I think implementing a wrapper according to the different namespace will be more user friendly.
For example,
- Gluon
mx.gluon.import_from(input_file)
mx.gluon.export_to(format=’onnx’, filename_prefix=”model_name”)
If any pre-processing/post-processing logic is required for gluon specific models, it can go under this gluon wrapper. These functions will internally call `serde` module APIs.
- For Symbolic interface
sym, params = mx.mod.Module.import_from(input_file, in_format=‘onnx’)
mx.mod.Module.export_to(format=‘onnx’, filename_prefix=”model_name”)
This function will directly save the file called “model_name.onnx” on disk.
Implementation Implementation approaches
There are two approaches which can be taken to import/export onnx model.
...