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.

get_model_metadata_(model_file)

Returns the name and shape information of input and output tensors of the given ONNX model file.

import_model_(model_file)

Imports the ONNX model file, passed as a parameter, into MXNet symbol and parameters.

import_to_gluon_(model_file, ctx)

Imports the ONNX model files, passed as a parameter, into Gluon SymbolBlock object.

mxnet.contrib.onnx.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)

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/incubator-mxnet/tree/v1.x/python/mxnet/onnx#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

Returns

onnx_file_path – Onnx file path

Return type

str

Notes

This method is available when you import mxnet.onnx

mxnet.contrib.onnx.get_model_metadata_(model_file)

Returns the name and shape information of input and output tensors of the given ONNX model file.

Notes

This method is available when you import mxnet.contrib.onnx

Parameters

model_file (str) – ONNX model file name

Returns

model_metadata – A dictionary object mapping various metadata to its corresponding value. The dictionary will have the following template:

'input_tensor_data' : list of tuples representing the shape of the input paramters
'output_tensor_data' : list of tuples representing the shape of the output of the model

Return type

dict

mxnet.contrib.onnx.import_model_(model_file)

Imports the ONNX model file, passed as a parameter, into MXNet symbol and parameters. Operator support and coverage - https://cwiki.apache.org/confluence/display/MXNET/ONNX+Operator+Coverage

Parameters

model_file (str) – ONNX model file name

Returns

  • sym (Symbol) – MXNet symbol object

  • arg_params (dict of str to NDArray) – Dict of converted parameters stored in mxnet.ndarray.NDArray format

  • aux_params (dict of str to NDArray) – Dict of converted parameters stored in mxnet.ndarray.NDArray format

Notes

This method is available when you import mxnet.contrib.onnx

mxnet.contrib.onnx.import_to_gluon_(model_file, ctx)

Imports the ONNX model files, passed as a parameter, into Gluon SymbolBlock object.

Parameters
  • model_file (str) – ONNX model file name

  • ctx (Context or list of Context) – Loads the model into one or many context(s).

Returns

sym_block – A SymbolBlock object representing the given model file.

Return type

SymbolBlock

Notes

This method is available when you import mxnet.contrib.onnx