onnx_extended.tools.stats_nodes

enumerate_nodes

onnx_extended.tools.stats_nodes.enumerate_nodes(onx: FunctionProto | GraphProto | ModelProto, recursive: bool = True) Iterable[Tuple[Tuple[str, ...], GraphProto | FunctionProto, NodeProto | TensorProto | SparseTensorProto]][source]

Enumerates all nodes in a model.

Parameters:
  • onx – the model

  • recursive – look into subgraphs

Returns:

enumerate tuple (name, parent, node)

enumerate_stats_nodes

onnx_extended.tools.stats_nodes.enumerate_stats_nodes(onx: FunctionProto | GraphProto | ModelProto, recursive: bool = True, stats_fcts: Dict[Tuple[str, str], Callable[[GraphProto | FunctionProto, NodeProto | TensorProto | SparseTensorProto], NodeStatistics | HistStatistics]] | None = None) Iterable[Tuple[Tuple[str, ...], GraphProto | FunctionProto, NodeStatistics | HistStatistics]][source]

Computes statistics of nodes functions.

Parameters:
  • onx – the model

  • recursive – look into subgraphs

  • stats_fcts – a dicionary of functions to call for every node, the key is (domain, op_type), if None, uses the default statistiques

Returns:

enumerate tuple (name, parent, statistics)

HistStatistics

class onnx_extended.tools.stats_nodes.HistStatistics(parent: GraphProto | FunctionProto, node: NodeProto | TensorProto | SparseTensorProto, bins: int = 20)[source]

Stores statistics on constants.

property dict_values: Dict[str, Any]

Returns the statistics as a dictionary.

property is_sparse: bool

Tells if the tensor is sparse.

property name: str

Returns the name of the tensor.

property values

Returns the values as an array.

HistTreeStatistics

class onnx_extended.tools.stats_nodes.HistTreeStatistics(node: NodeProto, featureid: int, values: ndarray, bins: int = 20)[source]

Stores statistics on thresholds.

NodeStatistics

class onnx_extended.tools.stats_nodes.NodeStatistics(parent: GraphProto | FunctionProto, node: NodeProto)[source]

Stores many statistics for NodeProto.

property dict_values: Dict[str, Any]

Returns the statistics as a dictionary.

stats_tree_ensemble

onnx_extended.tools.stats_nodes.stats_tree_ensemble(parent: GraphProto | FunctionProto, node: NodeProto) NodeStatistics[source]

Computes statistics on every tree of a TreeEnsemble.

Parameters:
  • parent – function or graph proto hosting the node

  • node – node

Returns:

instance of NodeStatistics

TreeStatistics

class onnx_extended.tools.stats_nodes.TreeStatistics(node: NodeProto, tree_id: int)[source]

Stores many statistics on a tree extracted from TreeEnsemble* operators.