module npy.xop
#
Short summary#
module mlprodict.npy.xop
Xop API to build onnx graphs. Inspired from sklearn-onnx.
Classes#
class |
truncated documentation |
---|---|
For operators defined outside onnx. |
|
Graph builder. It takes a graph structure made with instances of |
|
Holds static variables. |
|
Wrappers around class |
|
Wrappers around print to help debugging. |
|
Wrapper around OnnxIdentity to specify this operator is not part of the subgraph it is used in. |
|
Automatically creating all operators from onnx packages takes time. That’s why function |
|
Ancestor to every ONNX operator exposed in |
|
Base class for |
|
This operator is used to insert existing ONNX function into the ONNX graph being built. |
|
Accessor to one of the output returned by a |
|
Class used to return multiple |
Functions#
function |
truncated documentation |
---|---|
Returns the default mapping between opset and ir_version. |
|
Converts domain into a name. |
|
Automatically generates classes for each of the operators module onnx defines and described at Operators … |
|
Determines the domain of an operator. Raises an exception if not found or if there is an ambiguity. |
|
Populates all schemas. |
|
Dynamically creates a class for a specific operator. |
|
Dynamically creates a class for a every operator type in the given list. |
Properties#
property |
truncated documentation |
---|---|
Returns all operators wrapped in classes. |
|
Returns all domains. |
|
Returns all schemas. |
|
Returns all operators, domains, versions. |
|
Returns the list of implicit inputs the subgraph assumes to be existing even if they are not referenced as … |
|
Returns the only inputs in a list. |
|
Returns the only inputs in a list. |
|
|
Returns self.output_names_. |
Returns self.output_names_. |
|
This method should be overwritten. |
|
|
Returns self.output_names_. |
Returns None. |
|
Returns ‘output_names’ of attribute ‘unique’. |
|
Returns ‘output_names’ of attribute ‘unique’. |
Static Methods#
staticmethod |
truncated documentation |
---|---|
|
Enables expression cls[opset]. It returns the appropriate class cls_opset. Parameter op_version should be … |
Enables expression cls[opset]. It returns the appropriate class cls_opset. Parameter op_version should be … |
|
|
Enables expression cls[opset]. It returns the appropriate class cls_opset. Parameter op_version should be … |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Converts an attribute into a value using python structures. |
|
Returns a unique variable name. |
|
Converts a numbers into a string keeping the same alphabetical order. |
|
Parses this class from a json string. |
Methods#
method |
truncated documentation |
---|---|
|
Automatically adds operator OnnxAbs to the graph. |
Automatically adds operator OnnxAbs to the graph. |
|
|
Automatically adds operator OnnxAbs to the graph. |
|
Automatically adds operator OnnxAdd to the graph. |
Automatically adds operator OnnxAdd to the graph. |
|
|
Automatically adds operator OnnxAdd to the graph. |
|
Creates an instance of class |
Creates an instance of class |
|
|
Creates an instance of class |
|
Automatically adds operator OnnxEqual to the graph. |
Automatically adds operator OnnxEqual to the graph. |
|
|
Automatically adds operator OnnxEqual to the graph. |
|
Automatically adds operator OnnxGreaterOrEqual to the graph. |
Automatically adds operator OnnxGreaterOrEqual to the graph. |
|
|
Automatically adds operator OnnxGreaterOrEqual to the graph. |
Enables expressions such as: |
|
|
Returns an accessor to one of the output of this node. |
Returns an accessor to one of the output of this node. |
|
|
Returns an accessor to one of the output of this node. |
usual |
|
|
Automatically adds operator OnnxGreater to the graph. |
Automatically adds operator OnnxGreater to the graph. |
|
|
Automatically adds operator OnnxGreater to the graph. |
constructor |
|
constructor |
|
|
Allows expressions such as |
Allows expressions such as |
|
|
Allows expressions such as |
Iterates on the outputs. |
|
|
Automatically adds operator OnnxLess to the graph. |
Automatically adds operator OnnxLess to the graph. |
|
|
Automatically adds operator OnnxLess to the graph. |
usual |
|
|
Automatically adds operator OnnxLess to the graph. |
Automatically adds operator OnnxLess to the graph. |
|
|
Automatically adds operator OnnxLess to the graph. |
|
Automatically adds operator OnnxMatMul to the graph. |
Automatically adds operator OnnxMatMul to the graph. |
|
|
Automatically adds operator OnnxMatMul to the graph. |
|
Automatically adds operator OnnxMod to the graph. |
Automatically adds operator OnnxMod to the graph. |
|
|
Automatically adds operator OnnxMod to the graph. |
|
Automatically adds operator OnnxMul to the graph. |
Automatically adds operator OnnxMul to the graph. |
|
|
Automatically adds operator OnnxMul to the graph. |
|
Automatically adds operator OnnxNot x OnnxEqual to the graph. |
Automatically adds operator OnnxNot x OnnxEqual to the graph. |
|
|
Automatically adds operator OnnxNot x OnnxEqual to the graph. |
|
Automatically adds operator OnnxPow to the graph. |
Automatically adds operator OnnxPow to the graph. |
|
|
Automatically adds operator OnnxPow to the graph. |
usual |
|
usual |
|
usual |
|
usual |
|
usual |
|
usual |
|
|
Automatically adds operator OnnxSub to the graph. |
Automatically adds operator OnnxSub to the graph. |
|
|
Automatically adds operator OnnxSub to the graph. |
|
Automatically adds operator OnnxDiv to the graph. |
Automatically adds operator OnnxDiv to the graph. |
|
|
Automatically adds operator OnnxDiv to the graph. |
|
Fills attribute attribute. |
Fills attribute attribute. |
|
|
Fills attribute attribute. |
|
|
|
|
|
Builds a graph as a list of nodes to walk through in that order. |
Builds a graph as a list of nodes to walk through in that order. |
|
|
Builds a graph as a list of nodes to walk through in that order. |
|
Walks through attributes and replaces them by ONNX values. |
Walks through attributes and replaces them by ONNX values. |
|
|
Walks through attributes and replaces them by ONNX values. |
Sets control_op for every instance of |
|
Tells this operator is part of a subgraph. |
|
|
Sets control_op for every instance of |
|
Tells this operator is part of a subgraph. |
Tells this operator is part of a subgraph. |
|
|
Converts one subgraph into ONNX. Returns the ONNX graph and the hidden inputs. |
Converts one subgraph into ONNX. Returns the ONNX graph and the hidden inputs. |
|
|
Converts one subgraph into ONNX. Returns the ONNX graph and the hidden inputs. |
|
Converts attributes into ONNX. Returns the hidden inputs. |
Converts attributes into ONNX. Returns the hidden inputs. |
|
|
Converts attributes into ONNX. Returns the hidden inputs. |
Calls self.onx_op._to_onnx_attributes. |
|
Calls self.onx_op._to_onnx_attributes. |
|
|
Tells a subgraph this node comes from a graph calling this one. |
Tells a subgraph this node comes from a graph calling this one. |
|
Tells a subgraph this node comes from the main graph. It may be used only by the subgraph but it must be processed … |
|
|
Tells a subgraph this node comes from a graph calling this one. |
|
Tells a subgraph this node comes from the main graph. It may be used only by the subgraph but it must be processed … |
|
Tells a subgraph this node comes from the main graph. It may be used only by the subgraph but it must be processed … |
Adds a function to the graph. |
|
Adds an initializer to the graph. |
|
Adds a node to the graph. |
|
|
Adds to graph builder. |
Adds to graph builder. |
|
This method should be overwritten. |
|
Adds to graph builder. |
|
Adds to graph builder. Does nothing because the original node is already added. |
|
Adds to graph builder. Does nothing because the original node is already added. |
|
|
Automatically adds operator OnnxAnd to the graph. |
Automatically adds operator OnnxAnd to the graph. |
|
|
Automatically adds operator OnnxAnd to the graph. |
|
Automatically adds operator OnnxCast to the graph. |
Automatically adds operator OnnxCast to the graph. |
|
|
Automatically adds operator OnnxCast to the graph. |
Returns all data in that class in a dictionary. |
|
debug |
|
debug |
|
|
debug |
unindent |
|
|
unindent |
|
Fills attribute body. |
Fills attribute body. |
|
|
Fills attribute body. |
|
Fills attribute else_branch. |
Fills attribute else_branch. |
|
|
Fills attribute else_branch. |
For the eager mode. |
|
Computes the predictions for this node. Similar to an eager evaluation. |
|
Evaluates this node. |
|
|
Computes the predictions for this node. Similar to an eager evaluation. |
Computes the predictions for this node. Similar to an eager evaluation. |
|
|
Evaluates this node. |
Retrieves all named inputs in this graph. |
|
Retrieves all named inputs in this graph. |
|
Returns all inputs to the graph. |
|
|
Retrieves all named inputs in this graph. |
Returns all inputs to the graph. |
|
Returns all inputs to the graph. |
|
|
Checks if there is an existing schema for a specific version. |
Checks if there is an existing schema for a specific version. |
|
|
Checks if there is an existing schema for a specific version. |
Returns input names for node node and inputs inputs. |
|
|
Returns the output name at position i. |
Returns the output name at position i. |
|
|
Returns the output name at position i. |
Returns the output name at position i. |
|
Returns a unique name to name an output. |
|
Returns a unique output_name for a NodeResultName. |
|
indent |
|
|
indent |
|
Automatically adds operator OnnxNot to the graph. |
Automatically adds operator OnnxNot to the graph. |
|
|
Automatically adds operator OnnxNot to the graph. |
|
Automatically adds operator OnnxOr to the graph. |
Automatically adds operator OnnxOr to the graph. |
|
|
Automatically adds operator OnnxOr to the graph. |
Populates static variables. |
|
|
Returns the list of predecessors. |
Returns the list of predecessors. |
|
|
Returns the list of predecessors. |
Reserves a name so that it cannot be changed. |
|
Adds names to the list of reserved names. All must be unique. |
|
|
Other name for OnnxInference.f. |
Other name for OnnxInference.f. |
|
|
Other name for OnnxInference.f. |
Serializes this class into json. |
|
|
Fills attribute then_branch. |
Fills attribute then_branch. |
|
|
Fills attribute then_branch. |
|
Converts this operator into an ONNX graph. |
Converts this operator into an ONNX graph. |
|
|
Converts this operator into an ONNX graph. |
Converts this operator into an ONNX graph. It follows the same signature as |
|
Converts this operator into an ONNX graph. |
|
|
Returns a simple ONNX graph corresponding to this node. |
Returns a simple ONNX graph corresponding to this node. |
|
|
Returns a simple ONNX graph corresponding to this node. |
|
Some operators return a undefined number of outputs. The method is called when require one of them (with __getitem__) … |
Some operators return a undefined number of outputs. The method is called when require one of them (with __getitem__) … |
|
|
Some operators return a undefined number of outputs. The method is called when require one of them (with __getitem__) … |
Documentation#
Xop API to build onnx graphs. Inspired from sklearn-onnx.
New in version 0.9.
- mlprodict.npy.xop.ClassFactory(class_name, op_name, inputs, outputs, input_range, output_range, domain, attr_names, doc, deprecated, since_version, past_version)#
Dynamically creates a class for a specific operator.
- Parameters:
class_name – class name
op_name – operator type
inputs – expected inputs
outputs – expected outputs
input_range – input range
output_range – output_range
domain – domain
attr_names – attributes names
doc – docstring
deprecated – is the operator deprecated
since_version – available since version
past_version – list of versions
- class mlprodict.npy.xop.OnnxExisting(*args, **kwargs)#
Bases:
OnnxOperator
Wrapper around OnnxIdentity to specify this operator is not part of the subgraph it is used in.
- __init__(*args, **kwargs)#
- __repr__()#
usual
- _set_control_op(op, subgraph_inputs=None)#
Sets control_op for every instance of
OnnxExisting
node.- Parameters:
op – operator calling the subgraph.
inputs – additional parameters to convert into ONNX
- _unique_names = {}#
- f(*inputs, verbose=0, fLOG=None, clear_cache=False, runtime=None)#
For the eager mode.
- find_named_inputs()#
Retrieves all named inputs in this graph.
- static get_unique_name(var)#
Returns a unique variable name.
- Parameters:
var – an instance of OnnxOperator.
- Returns:
unique variable name
- class mlprodict.npy.xop.OnnxLoadFactory#
Bases:
object
Automatically creating all operators from onnx packages takes time. That’s why function
loadop
only creates classes for the requested operators. This class does the same when an attributes is requested.cl = OnnxLoadOperators() x = cl.Add(...)
It is equivalent to:
OnnxAdd = loadop('Add') x = OnnxAdd(...)
- __getattr__(name)#
Enables expressions such as:
ops = OnnxLoadFactory() op = ops.Abs('X')
- __init__()#
- class mlprodict.npy.xop.OnnxOperator(*inputs, op_version=None, output_names=None, domain=None, global_context=None, **kwargs)#
Bases:
OnnxOperatorBase
Ancestor to every ONNX operator exposed in
mlprodict.npy.xops
andmlprodict.npy.xops_ml
.- Parameters:
inputs – list of inputs expected by the operator
op_version – to select a specific version of the operator
output_names – used defined names for the outputs
domain – to overwrite the default domain
global_context – operator If executes one subgraph whose nodes may use one existing output in the current context. If not used in the main graph, these operators are not linked to the output and cannot be retrieved. global_context is a dictionary mapped the subgraph input names to these operators.
kwargs – additional parameters of the operator
- class _InputContainer#
Bases:
object
- __init__()#
- __iter__()#
- __len__()#
- __repr__()#
Return repr(self).
- append(inp)#
Append one element to the list.
- has_input(inp)#
Checks that input inp is part the list of names.
- __abs__()#
Automatically adds operator OnnxAbs to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxAbs(self, ov)
- __add__(ov)#
Automatically adds operator OnnxAdd to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxAdd(self, ov)
- __call__(*args, function_name=None, function_domain=None, **kwargs)#
Creates an instance of class
OnnxOperatorFunction
. Equivalent to OnnxOperatorFunction(proto, *args, **kwargs).- Parameters:
args – see
OnnxOperatorFunction
function_name – name to be given to the function
function_domain – function domain, if None, it is given a default value
kwargs – see
OnnxOperatorFunction
- Returns:
instance of type
OnnxOperatorFunction
- classmethod __class_getitem__(opset)#
Enables expression cls[opset]. It returns the appropriate class cls_opset. Parameter op_version should be specified.
- __eq__(ov)#
Automatically adds operator OnnxEqual to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxEqual(self, ov)
- __ge__(ov)#
Automatically adds operator OnnxGreaterOrEqual to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxGreater(self, ov)
- __getitem__(index)#
Returns an accessor to one of the output of this node.
- __gt__(ov)#
Automatically adds operator OnnxGreater to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxGreater(self, ov)
- __hash__ = None#
- __init__(*inputs, op_version=None, output_names=None, domain=None, global_context=None, **kwargs)#
- __iter__()#
Allows expressions such as
a, b = OnnxTopK(...)
.
- __le__(ov)#
Automatically adds operator OnnxLess to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxLess(self, ov)
- __lt__(ov)#
Automatically adds operator OnnxLess to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxLess(self, ov)
- __matmul__(ov)#
Automatically adds operator OnnxMatMul to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnMatMul(self, ov)
- __mod__(ov)#
Automatically adds operator OnnxMod to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxMod(self, ov)
- __mul__(ov)#
Automatically adds operator OnnxMul to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxMul(self, ov)
- __ne__(ov)#
Automatically adds operator OnnxNot x OnnxEqual to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxNot(OnnxEqual(self, ov))
- __pow__(ov)#
Automatically adds operator OnnxPow to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnPow(self, ov)
- __repr__()#
usual
- __sub__(ov)#
Automatically adds operator OnnxSub to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxSub(self, ov)
- __truediv__(ov)#
Automatically adds operator OnnxDiv to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxDiv(self, ov)
- _add_subgraph(attribute, branch, subgraph_inputs=None)#
Fills attribute attribute.
- Parameters:
attribute – attribute name
branch – onnx graph or
OnnxOperator
subgraph_inputs – additional parameter to convert the subgraph into ONNX
- Returns:
self
- _check()#
- static _merge_op_version(n1, n2, at_least=None)#
- _node_to_graph(other_outputs=None, inputs=None, outputs=None, as_function=False, processed=None)#
Builds a graph as a list of nodes to walk through in that order.
- static _node_to_graph_get_type(node, name=None, outputs=None, outputs_dtype=None)#
- static _node_to_graph_preprocess_list(inputs)#
- static _node_to_graph_process_input(processed, inputs, set_inputs, node, inp, new_inputs, new_stack, inputs_dtype, as_function=False)#
- static _node_to_graph_reorder_by_name(new_inputs, inputs)#
- _post_process_attributes()#
Walks through attributes and replaces them by ONNX values.
- _set_control_op(op, subgraph_inputs=None)#
Sets control_op for every instance of
OnnxExisting
node.- Parameters:
op – operator calling the subgraph.
inputs – additional parameters to convert into ONNX
- _to_onnx_attribute(att_name, oxop, inputs=None, target_opset=None, optim=True, verbose=0, run_shape=True, fLOG=<built-in function print>, processed=None)#
Converts one subgraph into ONNX. Returns the ONNX graph and the hidden inputs.
- _to_onnx_attributes(inputs=None, target_opset=None, optim=True, verbose=0, run_shape=True, fLOG=<built-in function print>, processed=None)#
Converts attributes into ONNX. Returns the hidden inputs.
- add_external_input(op)#
Tells a subgraph this node comes from a graph calling this one.
- add_to(builder)#
Adds to graph builder.
- Parameters:
builder – instance of
_GraphBuilder
, it must have a method add_node
- and_(ov)#
Automatically adds operator OnnxAnd to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxAnd(self, ov)
- astype(to)#
Automatically adds operator OnnxCast to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxCast(self, ov, to=to)
- do(body, subgraph_inputs=None)#
Fills attribute body.
- Parameters:
branch – onnx graph or
OnnxOperator
subgraph_inputs – additional parameter to convert the subgraph into ONNX
- Returns:
self
- else_do(branch)#
Fills attribute else_branch.
- Parameters:
branch – onnx graph or
OnnxOperator
- Returns:
self
- f(*inputs, verbose=0, fLOG=None, clear_cache=False, runtime=None)#
Computes the predictions for this node. Similar to an eager evaluation.
- Parameters:
inputs – inputs as dictionary or a list of inputs (see below)
verbose – display information while predicting
fLOG – logging function if verbose > 0
clear_cache – onnx graph is created once unless this parameter is True
runtime – runtime to use for the evaluation, see
OnnxInference
- Returns:
outputs as a dictionary if the input were given as a dictionary or a single result or a tuple otherwise
The inputs refer to the inputs of the graph. The method walks through all inputs and finds inputs defined as string. It replaces them by the value found in the dictionary. If the inputs are specified in a list, the function retrieves the list of inputs defined as a string and assigns them a value. Logging function can be used to get more insight about it. During the evaluation every node is independently converted into ONNX. The ONNX graph is cached in the class itself.
- find_named_inputs()#
Retrieves all named inputs in this graph.
- find_schema(op_version)#
Checks if there is an existing schema for a specific version.
- Parameters:
op_version – requested version
- Returns:
schema
- get_output_result(i=0)#
Returns the output name at position i.
- not_()#
Automatically adds operator OnnxNot to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxNot(self, ov)
- or_(ov)#
Automatically adds operator OnnxOr to the graph.
- Parameters:
ov – onnx node
- Returns:
OnnxOr(self, ov)
- property output_names#
Returns self.output_names_.
- predecessors()#
Returns the list of predecessors.
- Returns:
list of
OnnxOperator
- run(*inputs, verbose=0, fLOG=None, clear_cache=False, runtime=None)#
Other name for OnnxInference.f.
- then_do(branch)#
Fills attribute then_branch.
- Parameters:
branch – onnx graph or
OnnxOperator
- Returns:
self
- to_onnx(inputs=None, outputs=None, other_outputs=None, target_opset=None, optim=True, verbose=0, run_shape=True, function_name=None, function_domain=None, fLOG=<built-in function print>, processed=None, check_model=True, return_builder=False)#
Converts this operator into an ONNX graph.
- Parameters:
inputs – information about type, it should not be None
outputs – information about types, if None, the function will use shape inference to guess the final output type and shape
other_outputs – additional nodes to consider as graph outputs but not outputs of this particular node
target_opset – dictionary with target opset per domain, None for the default one
optim – optimize the model with function
onnx_optimisations
run_shape – in case output shapes are not specify, the function runs function infer_shapes to guess them, False would disable that default behaviour
verbose – prints information
function_name – if not None, returns a FunctionProto
function_domain – in case of a function, declares the function as part of this domain
fLOG – logging function
processed – keeps track the of the processed nodes
check_model – checks the output model
return_builder – if True, returns the instance of
GraphBuilder
used to build the onnx graph.
- Returns:
ONNX stucture
inputs and outputs parameters work the same way. Here is some possible walues:
inputs=numpy.float32: all inputs are dense tensors of unknown shapes sharing the same element type
inputs={‘X’: numpy.float32, ‘Y’: numpy.in64}`: input X is a dense tensor of float32, input Y is a dense tensor of int64,
{‘X’: numpy.array(…)}}: input X is a dense tensor with a precise shape
inputs=[Variable(‘X’, numpy.float32, [1, 2])]: input X is a dense tensor of float32 with shape [1, 2]
inputs=[Variable(‘X’, numpy.float32, [None, 2])]: input X is a dense tensor of float32 with a 2D tensor with an unknown dimension (first one)
see
Variable
(OnnxOperator)
- to_onnx_this(evaluated_inputs)#
Returns a simple ONNX graph corresponding to this node.
- Parameters:
evaluated_inputs – inputs as a list
- Returns:
ONNX graph
(OnnxOperator)
- update_max_item(index)#
Some operators return a undefined number of outputs. The method is called when require one of them (with __getitem__) and keeps the greater requested index assuming the node does not output any result beyond that index.
- Parameters:
index – requested index
- class mlprodict.npy.xop.OnnxOperatorBase#
Bases:
object
Base class for
OnnxOperator
,OnnxOperator
.- __init__()#
- _set_control_op(op, subgraph_inputs=None)#
Tells this operator is part of a subgraph.
- add_external_input(op)#
Tells a subgraph this node comes from the main graph. It may be used only by the subgraph but it must be processed as well.
- add_to(builder)#
This method should be overwritten.
- f(*args, **kwargs)#
Evaluates this node.
- find_named_inputs()#
Returns all inputs to the graph.
- property output_names#
This method should be overwritten.
- class mlprodict.npy.xop.OnnxOperatorFunction(function_proto, *inputs, output_names=None, sub_functions=None)#
Bases:
OnnxOperator
This operator is used to insert existing ONNX function into the ONNX graph being built.
- Parameters:
function_proto – instance of type FunctionProto
inputs – inputs
output_names – output names
sub_functions – functions called by this one
- __init__(function_proto, *inputs, output_names=None, sub_functions=None)#
- __repr__()#
usual
- add_to(builder)#
Adds to graph builder.
- Parameters:
builder – instance of
_GraphBuilder
, it must have a method add_node
- static attribute_to_value(att)#
Converts an attribute into a value using python structures.
- class mlprodict.npy.xop.OnnxOperatorItem(onx_op, index, op_version=None)#
Bases:
OnnxOperatorBase
Accessor to one of the output returned by a
OnnxOperator
.- Parameters:
onx_op –
OnnxOperator
index – integer
op_version – defines the opset version
- __init__(onx_op, index, op_version=None)#
- __repr__()#
usual
- __str__()#
usual
- _to_onnx_attributes(inputs=None, target_opset=None, optim=True, verbose=0, run_shape=True, fLOG=<built-in function print>, processed=None)#
Calls self.onx_op._to_onnx_attributes.
- add_to(builder)#
Adds to graph builder. Does nothing because the original node is already added.
- Parameters:
builder – instance of
_GraphBuilder
, it must have a method add_node
- f(*inputs, verbose=0, fLOG=None, clear_cache=False, runtime=None)#
Computes the predictions for this node. Similar to an eager evaluation.
- Parameters:
inputs – inputs as dictionary or a list of inputs (see below)
verbose – display information while predicting
fLOG – logging function if verbose > 0
clear_cache – onnx graph is created once unless this parameter is True
runtime – runtime to use for the evaluation, see
OnnxInference
- Returns:
outputs as a dictionary if the input were given as a dictionary or a single result or a tuple otherwise
The inputs refer to the inputs of the graph. The method walks through all inputs and finds inputs defined as string. It replaces them by the value found in the dictionary. If the inputs are specified in a list, the function retrieves the list of inputs defined as a string and assigns them a value. Logging function can be used to get more insight about it. During the evaluation every node is independently converted into ONNX. The ONNX graph is cached in the class itself.
- find_named_inputs()#
Returns all inputs to the graph.
- get_output_result(i=0)#
Returns the output name at position i.
- property inputs#
Returns the only inputs in a list.
- property output_names#
Returns None.
- class mlprodict.npy.xop.OnnxOperatorTuple(first, *args)#
Bases:
OnnxOperatorBase
Class used to return multiple
OnnxVar
at the same time.- __getitem__(i)#
usual
- __init__(first, *args)#
- __iter__()#
Iterates on the outputs.
- __len__()#
usual
- __repr__()#
usual
- _set_control_op(op, subgraph_inputs=None)#
Tells this operator is part of a subgraph.
- _to_onnx_attributes(inputs=None, target_opset=None, optim=True, verbose=0, run_shape=True, fLOG=<built-in function print>, processed=None)#
Calls self.onx_op._to_onnx_attributes.
- add_to(builder)#
Adds to graph builder. Does nothing because the original node is already added.
- Parameters:
builder – instance of
_GraphBuilder
, it must have a method add_node
- property external_inputs#
Returns the list of implicit inputs the subgraph assumes to be existing even if they are not referenced as explicit input for the graph.
- find_named_inputs()#
Returns all inputs to the graph.
- property inputs#
Returns the only inputs in a list.
- property output_names#
Returns ‘output_names’ of attribute ‘unique’.
- property outputs#
Returns ‘output_names’ of attribute ‘unique’.
- to_onnx(inputs=None, outputs=None, other_outputs=None, target_opset=None, optim=True, verbose=0, run_shape=True, processed=None, check_model=True, return_builder=False, fLOG=None)#
Converts this operator into an ONNX graph. It follows the same signature as
OnnxOperator.to_onnx
and calls this method of the unique input object or the first one if there are several. In that case, other inputs in attribute values are moved into container other_outputs.(OnnxOperatorTuple)
- class mlprodict.npy.xop._CustomSchema(schema)#
Bases:
object
For operators defined outside onnx.
- static ParseFromString(s)#
Parses this class from a json string.
- SerializeToString()#
Serializes this class into json.
- __eq__(ot)#
Return self==value.
- __hash__ = None#
- __init__(schema)#
- __repr__()#
Return repr(self).
- class _attribute(att)#
Bases:
object
attribute
- __eq__(ot)#
Return self==value.
- __hash__ = None#
- __init__(att)#
- data()#
Returns all data in that class in a dictionary.
- _atts = ['domain', 'name', 'since_version', 'inputs', 'outputs', 'attributes', 'min_input', 'max_input', 'min_output', 'max_output', 'doc']#
- class _empty#
Bases:
object
dummy class
- static from_attribute(data)#
Creates an instance of _CustomSchema._attribute.
- static from_io(data)#
Creates an instance of _CustomSchema._io.
- class _io(t)#
Bases:
object
input, output
- __eq__(ot)#
Return self==value.
- __hash__ = None#
- __init__(t)#
- data()#
Returns all data in that class in a dictionary.
- data()#
Returns all data in that class in a dictionary.
- class mlprodict.npy.xop._GraphBuilder#
Bases:
object
Graph builder. It takes a graph structure made with instances of
OnnxOperatorBase
. The main method is to_onnx.initializer: list of initializers to add to the ONNX graph
node: list of nodes to add to the ONNX graph
input: list of inputs to add to the ONNX graph
output: list of inputs to add to the ONNX graph
opsets: opsets of the ONNX graph
- input_names: dictionary of input names
{name: InputDetectedVariable}
- node_output_names: memorizes a name for a node output
when the user did not specify any {(id(node), index): OutputDetectedVariable}
- reserved_names: dictionary { name : (node, index) },
name which should remain unchanged in the ONNX graph
names: list of uniques names
functions: dictionary { domain, name: function_proto }
function_hashes: dictionary { domain, name: hash of function_proto }
- __init__()#
- _add_domain(domain, version)#
- _add_name(name)#
- _process_io(inputs, input_names_)#
- add_function(function_proto, raise_if_exist=False, check_unique=True, opset=1)#
Adds a function to the graph.
- Parameters:
function_proto – instance of type FunctionProto
raise_if_exist – raises an exception if a function of the same name was already added
check_unique – checks if a function was added twice, it is the same
opset – opset for the domain the function belongs to
- add_initializer(name, init)#
Adds an initializer to the graph.
- Parameters:
name – initializer name
init – initializer to copy
- Returns:
created intializer
- add_node(op_type, name, inputs, outputs, domain='', opset=None, **attributes)#
Adds a node to the graph.
- Parameters:
op_type – operator type
name – node name
inputs – inputs name list
outputs – outputs name list
domain – node domain
opset – node opset
- Returns:
created node
- get_input_names(node, inputs)#
Returns input names for node node and inputs inputs.
- Parameters:
node – node
inputs – inputs
- Returns:
name
- get_unique_name(name, reserved=True)#
Returns a unique name to name an output.
- Parameters:
name – name
reserved – bypass if the name is a reserved one
- Returns:
unique name, may be the same if not taken already
- get_unique_output_name(result)#
Returns a unique output_name for a NodeResultName.
- Parameters:
result – instance of
NodeResultName
- static number2alpha(index)#
Converts a numbers into a string keeping the same alphabetical order.
- reserve_name(node, name, index)#
Reserves a name so that it cannot be changed.
- Parameters:
node – node or None for an input
name – name
index – input index
- reserve_names(node, output_names)#
Adds names to the list of reserved names. All must be unique.
- Parameters:
node – node or None for an input
output_names – names of the output
- to_onnx(inputs=None, outputs=None, target_opset=None, run_shape=False, optim=True, function_name=None, function_domain=None, verbose=0, check_model=True)#
Converts this operator into an ONNX graph.
- Parameters:
inputs – specific inputs (as a dictionary) or default inputs if not specified
outputs – specific outputs
target_opset – dictionary with target opset per domain, None for the default one
run_shape – run shape inference before returning the model
optim – optimize the model with function
onnx_optimisations
function_name – if not None builds a FunctionProto use this name
function_domain – in case of a function, declares the function as part of this domain, ‘mlprodict’ if None
verbose – prints information
check_model – checks the output model
- Returns:
onnx graph
(_GraphBuilder)
- class mlprodict.npy.xop._StaticVariables#
Bases:
object
Holds static variables.
- __init__()#
- property all_classes#
Returns all operators wrapped in classes.
- property all_domains#
Returns all domains.
- property all_schemas#
Returns all schemas.
- property all_schemas_versions#
Returns all operators, domains, versions.
- populate()#
Populates static variables.
- class mlprodict.npy.xop._WrapperLogger(lg)#
Bases:
object
Wrappers around class
logging.Logger
to take indentation into account.constructor
- __init__(lg)#
constructor
- debug(msg, *args)#
- dedent()#
unindent
- indent()#
- class mlprodict.npy.xop._WrapperPrint#
Bases:
_WrapperLogger
Wrappers around print to help debugging.
constructor
- __init__()#
constructor
- debug(msg, *args, indent=None)#
- mlprodict.npy.xop._default_OPSET_TO_IR_VERSION()#
Returns the default mapping between opset and ir_version.
<<<
import pprint from mlprodict.npy.xop import _default_OPSET_TO_IR_VERSION pprint.pprint(_default_OPSET_TO_IR_VERSION())
>>>
{1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3, 7: 3, 8: 4, 9: 4, 10: 5, 11: 6, 12: 7, 13: 7, 14: 7, 15: 8, 16: 8, 17: 8}
- mlprodict.npy.xop._domain_to_class_name(domain)#
Converts domain into a name.
- Parameters:
domain – domain name such as ai.onnx.ml
- Returns:
string
<<<
from mlprodict.npy.xop import _domain_to_class_name print(_domain_to_class_name('ai.onnx.ml'))
>>>
AiOnnxMl
- mlprodict.npy.xop._dynamic_class_creation(operator_names=None, cache=False, include_past=False, verbose=0, fLOG=<built-in function print>)#
Automatically generates classes for each of the operators module onnx defines and described at Operators and Operators.
- Parameters:
operator_names – list of operators to request or None for all
cache – extract the documentation from onnx package and saves it on disk it True
include_past – includes past versions if operator_names is None
verbose – display some progress
fLOG – logging function
- Returns:
list of requested operators as a tuple
- mlprodict.npy.xop._find_operator_domain(name)#
Determines the domain of an operator. Raises an exception if not found or if there is an ambiguity.
- Parameters:
name – operator name
- Returns:
domain
- mlprodict.npy.xop._get_all_operator_schema()#
- mlprodict.npy.xop._populate_schemas()#
Populates all schemas.
- mlprodict.npy.xop._split_op_name(name)#
- mlprodict.npy.xop.loadop(*names, cache=False, verbose=0, fLOG=<built-in function print>)#
Dynamically creates a class for a every operator type in the given list.
- mlprodict.npy.xop.local_print(msg, *args, indent=None)#
debug