This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Page tree
Skip to end of metadata
Go to start of metadata

This document describes the onnx module in mxnet.contrib package that provides ONNX format support within MXNet. It outlines the currently implemented APIs and the future roadmap and design of proposed APIs.

Import ONNX into MXNet Symbol graph

Given an ONNX model file import into MXNet’s symbolic graph along with all the parameter tensors. This API is implemented and will be shipped as part of MXNet v1.2 release.

Import ONNX to Symbolic Interface
def 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
	Input Parameters –
	----------
	model_file – 
		A string object representing the path to the ONNX model file.
	
	Return type –
	----------
	sym – 
		An mxnet symbol object representing the symbolic graph of the given model.
	arg_params -  
		A dictionary object mapping the parameter name to an mxnet ndarray object representing its tensor value. These are the parameter values that are learned while training the model.
	aux_params – 
		A dictionary object mapping parameter names to an mxnet ndarray object representing the tensor values of the parameters. It stores the values that are not learned during the training process.
	"""
	...
	return sym, arg_params, aux_params

Import ONNX model files into Gluon Symbolic block

Given an ONNX model file import the model into Gluon’s SymbolicBlock object.

Import ONNX to Imperative Gluon Interface
def mxnet.contrib.onnx.import_to_gluon(model_file):
	"""
	Imports the ONNX model files, passed as a parameter, into Gluon’s SymbolicBlock object.
	Input Parameters –
	----------
	model_file – 
		A string object representing the path to the ONNX model file.
	Return Type –
	----------
	sym_block – 
		A SymbloicBlock object representing the given model file.
	"""
	...
	return sym_block

Model Metadata for a given ONNX model file

Given an ONNX model file, the user can use this API to fetch the related metadata of the model. This is a request from customers and users of the ONNX module, where they had a use case for knowing the shape information of the input and output tensors of a given ONNX model. This API is being implemented to meet that request.

Model Metadata
def mxnet.contrib.onnx.get_model_metadata(model_file):
	"""
	Returns the metadata information of the given model. Currently it will return the shape information of the input and output tensors.
	Input Parameters –
	----------
	model_file – 
		A string object representing the path to the ONNX model file.
 
	Return Type –
	----------
	model_metadata – 
		A dictionary object mapping various metadata to its corresponding value. The proposed implementation will return a dictionary with following template.
		{
			“input_tensor_shape”: <list of tuples representing the shape of the input paramters>,
			“output_tensor_shape”: <list of tuples representing the shape of the output of the model>
		}
	"""
	...
	return metadata

Export MXNet symbolic model to an ONNX model file.

Given a MXNet model object/file, export the model to ONNX model file.

Export MXNet's sumbolic model to ONNX format
def mxnet.contrib.onnx._export .export_model( sym, params, input_shape, output):
	"""
	Exports a given MXNet symbol object file or path to saved file to ONNX model file.
	Input Parameters -
	----------
	sym - 
		A str object (path to json file) or mxnet symbol object or checkpointed mxnet symbol object
	params - 
		A str object (path to params file) or dict object containing the model params
	input_shape - 
		list of tuple object , specifies the shape of each input to the model
	output -
		path to the output file, including the filename.  Default: current path , filename: model.onnx
 
	Return Type –
	----------
	onnx_model_path -
		str object , path to saved .onnx file.
	"""
	...
	return onnx_model_path
  • No labels