module onnx_tools.exports.tf2onnx_helper
#
Short summary#
module mlprodict.onnx_tools.exports.tf2onnx_helper
Helpers to run examples created with function
export2tf2onnx()
.
Classes#
class |
truncated documentation |
---|---|
Helpers to build graph. |
|
Applies the converter on an ONNX graph. |
|
Decorator to register any new converter. |
Functions#
function |
truncated documentation |
---|---|
Returns the maximum value for a specific type. |
|
Creates a unique name. |
|
Raises an exception if cond is not verified. |
|
Converts an ONNX operators into tf2onnx code. |
|
Converts ONNX type into numpy type. |
Properties#
property |
truncated documentation |
---|---|
Returns the graph. |
Methods#
method |
truncated documentation |
---|---|
Registers an object in in the graph by its name. |
|
in ONNX, input shold come from node, so it must be a string |
|
Returns the type of one node or None if unknown. |
|
Retrieves a node by its name. |
|
Returns the type of one node or None if unknown. |
|
Make a new constants in the graph. |
|
Produces the new ONNX graph with the updated sets of nodes. |
|
Adds a node to the list of nodes. |
|
slice changes its schema at opset 10: it treats some attributes as dynamic input so this function has to process … |
|
Squeeze changes its schema at opset 13: it treats axes as a dynamic input kwargs: key could be [“data”, “axes”]. … |
|
Unsqueeze changes its schema at opset 13: it treats axes as a dynamic input kwargs: key could be [“data”, “axes”]. … |
|
Removes a node name from the list. |
|
Every taking old_name as inputs will take new_name instead. Looks in the output as well but in that case, it … |
|
Calls the registered converters on the graph held by this instance. Returns the new onnx graph. |
Documentation#
Helpers to run examples created with function
export2tf2onnx
.
- class mlprodict.onnx_tools.exports.tf2onnx_helper.GraphBuilder(graph)#
Bases:
object
Helpers to build graph. :param graph!
- __init__(graph)#
- _convert_to_attribute(tensor, is_optional=False)#
- _convert_to_input(tensor, const_name, is_optional=False, dtype=None)#
in ONNX, input shold come from node, so it must be a string
- property graph#
Returns the graph.
- make_slice(kwargs, name=None, shapes=None, dtypes=None, return_node=False)#
slice changes its schema at opset 10: it treats some attributes as dynamic input so this function has to process inputs according to graph’s opset version to get “inputs” and “attr” to feed “make_node” kwargs: key could be [“data”, “starts”, “ends”, “axes”, “steps”, “outputs”].
- make_squeeze(kwargs, name=None, shapes=None, dtypes=None, return_node=False, op_name_scope=None)#
Squeeze changes its schema at opset 13: it treats axes as a dynamic input kwargs: key could be [“data”, “axes”].
- make_unsqueeze(kwargs, name=None, shapes=None, dtypes=None, return_node=False, op_name_scope=None)#
Unsqueeze changes its schema at opset 13: it treats axes as a dynamic input kwargs: key could be [“data”, “axes”].
- class mlprodict.onnx_tools.exports.tf2onnx_helper.Tf2OnnxConvert(onnx_model, _tf_op=None, verbose=None, target_opset=None, max_iter=5)#
Bases:
object
Applies the converter on an ONNX graph.
- Parameters:
onnx_model – ONNX graph
tf_op – class which register
verbose – verbosity
target_opset – targetted opsets
- __init__(onnx_model, _tf_op=None, verbose=None, target_opset=None, max_iter=5)#
- _add_node_name(obj)#
Registers an object in in the graph by its name. :param name: node or initializer
- get_dtype(input_name)#
Returns the type of one node or None if unknown. :param input_name: result name :return: numpy dtype
- get_node_by_name(name)#
Retrieves a node by its name.
- Parameters:
name – node name
- Returns:
node name
- get_shape(input_name)#
Returns the type of one node or None if unknown. :param input_name: result name :return: numpy dtype
- make_const(name, np_val, skip_conversion=False, raw=True)#
Make a new constants in the graph. :param name: const node name, must be unique. :param np_val: value of type numpy ndarray. :param skip_conversion:
bool, indicate whether this created node would be mapped during conversion
- Parameters:
raw – whether to store data at field of raw_data or the specific field according to its dtype
- Returns:
create initializer
- make_model()#
Produces the new ONNX graph with the updated sets of nodes.
- make_node(op_type, inputs, attr=None, outputs=None, name=None, domain='', output_count=1, shapes=None, dtypes=None)#
Adds a node to the list of nodes.
- Parameters:
op_type – operator type
inputs – list of strings
attr – dictionary of attributes
outputs – None or list of strings
output_count – used if outputs is None to guess the number of outputs of this node
name – name of the node
domain – domain
shapes – unused
dtypes – unused
- Returns:
created node
- remove_node(name)#
Removes a node name from the list.
- replace_all_inputs(old_name, new_name)#
Every taking old_name as inputs will take new_name instead. Looks in the output as well but in that case, it creates an identity node to avoid changing an output name. :param old_name: name to replace :param new_name: new name :return: list of impacted nodes
- run()#
Calls the registered converters on the graph held by this instance. Returns the new onnx graph.
- Returns:
ONNX graph
- mlprodict.onnx_tools.exports.tf2onnx_helper.get_max_value(np_dtype)#
Returns the maximum value for a specific type.
- mlprodict.onnx_tools.exports.tf2onnx_helper.make_name(name)#
Creates a unique name.
- mlprodict.onnx_tools.exports.tf2onnx_helper.make_sure(cond, msg, *args)#
Raises an exception if cond is not verified.
- mlprodict.onnx_tools.exports.tf2onnx_helper.make_tf2onnx_code(opset, name=None, op_type=None, domain='', inputs=None, outputs=None, attributes=None, used=None, context=None, mark_inits=None, indent=8, **unused)#
Converts an ONNX operators into tf2onnx code.
- Parameters:
opset – target opset for the conversion (usually unused)
name – node name
op_type – operator type
domain – domain
inputs – inputs
outputs – outputs
attributes – attributes
used – dictionary {k: v}, list of nodes taking k as input
context – whole context
mark_inits – marks initializer as replaced
indent – number of spaces to add on the second and following rows
- Returns:
code as str
- mlprodict.onnx_tools.exports.tf2onnx_helper.map_onnx_to_numpy_type(onnx_dtype)#
Converts ONNX type into numpy type.
- class mlprodict.onnx_tools.exports.tf2onnx_helper.tf_op(name, domain='', **kwargs)#
Bases:
object
Decorator to register any new converter. :param name: type of the operator to rewrite :param domain: domain
- _OPSETS = {}#
- __call__(func)#
Call self as a function.
- __init__(name, domain='', **kwargs)#
- _register_handler(func, version, names, domain, kwargs)#