contrib.onnx

Module for ONNX model format support for Apache MXNet.

Functions

export_model(sym, params, input_shape[, …])

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, input_shape, input_type=<class 'numpy.float32'>, onnx_file_path='model.onnx', verbose=False)[source]

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://cwiki.apache.org/confluence/display/MXNET/ONNX+Operator+Coverage

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

  • params (str or symbol object) – Path to the params file or params dictionary. (Including both arg_params and aux_params)

  • input_shape (List of tuple) – Input shape of the model e.g [(1,3,224,224)]

  • input_type (data type) – Input data type e.g. np.float32

  • onnx_file_path (str) – Path where to save the generated onnx file

  • verbose (Boolean) – If true will print logs of the model conversion

Returns

onnx_file_path – Onnx file path

Return type

str

Notes

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

mxnet.contrib.onnx.get_model_metadata(model_file)[source]

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)[source]

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)[source]

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