Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions mlprodict/plotting/text_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def onnx_text_plot(model_onnx, recursive=False, graph_type='basic',

.. runpython::
:showcode:
:warningout: DeprecationWarning

import numpy
from skl2onnx.algebra.onnx_ops import OnnxAdd, OnnxSub
Expand Down Expand Up @@ -52,6 +53,7 @@ def onnx_text_plot_tree(node):

.. runpython::
:showcode:
:warningout: DeprecationWarning

import numpy
from sklearn.datasets import load_iris
Expand Down Expand Up @@ -193,7 +195,7 @@ def reorder_nodes_for_display(nodes, verbose=False):
successors = {}
predecessors = {}
for node in nodes:
node_name = node.name + "".join(node.output)
node_name = node.name + "#" + "|".join(node.output)
dnodes[node_name] = node
successors[node_name] = set()
predecessors[node_name] = set()
Expand Down Expand Up @@ -256,6 +258,13 @@ def _find_sequence(node_name, known, done):
print("[reorder_nodes_for_display] sequence(%s)=%s" % (
k, ",".join(sequences[k])))

if len(sequences) == 0:
raise RuntimeError(
"Unexpected empty sequences (len(possibles)=%d, "
"len(done)=%d, len(nodes)=%d). This is usually due to "
"a name used both as result name and node node."
"" % (len(possibles), len(done), len(nodes)))

# find the best sequence
best = None
for k, v in sequences.items():
Expand All @@ -273,7 +282,7 @@ def _find_sequence(node_name, known, done):
best = k
if best is None:
raise RuntimeError( # pragma: no cover
"Wrong implementationt.")
"Wrong implementation (len(sequence)=%d)." % len(sequences))
if verbose:
print("[reorder_nodes_for_display] BEST: sequence(%s)=%s" % (
best, ",".join(sequences[best])))
Expand Down Expand Up @@ -316,6 +325,7 @@ def onnx_simple_text_plot(model, verbose=False, att_display=None):

.. runpython::
:showcode:
:warningout: DeprecationWarning

import numpy
from sklearn.cluster import KMeans
Expand Down Expand Up @@ -464,7 +474,7 @@ def str_node(indent, node):
successors = {}
predecessors = {}
for node in model.node:
node_name = node.name + "".join(node.output)
node_name = node.name + "#" + "|".join(node.output)
successors[node_name] = []
predecessors[node_name] = []
for name in node.input:
Expand Down Expand Up @@ -493,7 +503,7 @@ def str_node(indent, node):
previous_in = None
for node in nodes:
add_break = False
name = node.name + "".join(node.output)
name = node.name + "#" + "|".join(node.output)
if name in indents:
indent = indents[name]
if previous_indent is not None and indent < previous_indent:
Expand Down