contrib.onnx

Module for ONNX model format support for Apache MXNet.

Functions

export_model_(sym, params[, in_shapes, …])

Exports the MXNet model file, passed as a parameter, into ONNX model.

export_model_(sym, params, in_shapes=None, in_types=<class 'numpy.float32'>, onnx_file_path='model.onnx', verbose=False, dynamic=False, dynamic_input_shapes=None, run_shape_inference=False, input_type=None, input_shape=None, large_model=False)

Exports the MXNet model file, passed as a parameter, into ONNX model. Accepts both symbol,parameter objects as well as json and params filepaths as input. Operator support and coverage - https://github.com/apache/mxnet/tree/v1.x/python/mxnet/onnx#user-content-operator-support-matrix

Parameters
  • sym (str or symbol object) – Path to the json file or Symbol object

  • params (str or dict or list of dict) – str - Path to the params file dict - params dictionary (Including both arg_params and aux_params) list - list of length 2 that contains 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

  • input_shape (List of tuple) – This is the old name of in_shapes. We keep this parameter name for backward compatibility

  • large_model (Boolean) – Whether to export a model that is larger than 2 GB. If true will save param tensors in separate files along with .onnx model file. This feature is supported since onnx 1.8.0

Returns

onnx_file_path – Onnx file path

Return type

str

Notes

This method is available when you import mxnet.onnx