concrete.ml.onnx.onnx_utils
Utils to interpret an ONNX model with numpy.
ATTR_TYPES
ATTR_GETTERS
ONNX_OPS_TO_NUMPY_IMPL
ONNX_COMPARISON_OPS_TO_NUMPY_IMPL_FLOAT
ONNX_COMPARISON_OPS_TO_NUMPY_IMPL_BOOL
ONNX_COMPARISON_OPS_TO_ROUNDED_TREES_NUMPY_IMPL_BOOL
ONNX_OPS_TO_NUMPY_IMPL_BOOL
IMPLEMENTED_ONNX_OPS
get_attribute
Get the attribute from an ONNX AttributeProto.
Args:
attribute
(onnx.AttributeProto): The attribute to retrieve the value from.
Returns:
Any
: The stored attribute value.
get_op_type
Construct the qualified type name of the ONNX operator.
Args:
node
(Any): ONNX graph node
Returns:
result
(str): qualified name
execute_onnx_with_numpy
Execute the provided ONNX graph on the given inputs.
Args:
graph
(onnx.GraphProto): The ONNX graph to execute.
*inputs
: The inputs of the graph.
Returns:
Tuple[numpy.ndarray]
: The result of the graph's execution.
execute_onnx_with_numpy_trees
Execute the provided ONNX graph on the given inputs for tree-based models only.
Args:
graph
(onnx.GraphProto): The ONNX graph to execute.
lsbs_to_remove_for_trees
(Optional[Tuple[int, int]]): This parameter is exclusively used for optimizing tree-based models. It contains the values of the least significant bits to remove during the tree traversal, where the first value refers to the first comparison (either "less" or "less_or_equal"), while the second value refers to the "Equal" comparison operation. Default to None.
*inputs
: The inputs of the graph.
Returns:
Tuple[numpy.ndarray]
: The result of the graph's execution.
remove_initializer_from_input
Remove initializers from model inputs.
In some cases, ONNX initializers may appear, erroneously, as graph inputs. This function searches all model inputs and removes those that are initializers.
Args:
model
(onnx.ModelProto): the model to clean
Returns:
onnx.ModelProto
: the cleaned model