From 7eece0c75d1442c364ec0bdef9469b049d6a2d36 Mon Sep 17 00:00:00 2001 From: rstar327 Date: Tue, 24 Feb 2026 17:10:14 +0200 Subject: [PATCH 1/2] fix(utils): use curved splines for LR/RL rankdir in plot_model --- keras/src/utils/model_visualization.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/keras/src/utils/model_visualization.py b/keras/src/utils/model_visualization.py index fb5ec22ceaa4..9f5157bb50ae 100644 --- a/keras/src/utils/model_visualization.py +++ b/keras/src/utils/model_visualization.py @@ -257,7 +257,12 @@ def model_to_dot( dot.set("rankdir", rankdir) dot.set("concentrate", True) dot.set("dpi", dpi) - dot.set("splines", "ortho") + # "ortho" splines are incompatible with horizontal (LR/RL) layouts + # in graphviz, producing empty output for complex models. + if rankdir in ("LR", "RL"): + dot.set("splines", "curved") + else: + dot.set("splines", "ortho") dot.set_node_defaults(shape="record") if kwargs.pop("layer_range", None) is not None: From 24bc36119120fb3116f4611811d3d080f21832f7 Mon Sep 17 00:00:00 2001 From: rstar327 Date: Tue, 17 Mar 2026 02:29:12 +0200 Subject: [PATCH 2/2] feat(visualization): add splines argument to plot_model and model_to_dot --- keras/src/utils/model_visualization.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/keras/src/utils/model_visualization.py b/keras/src/utils/model_visualization.py index 9f5157bb50ae..12ab6ca6879b 100644 --- a/keras/src/utils/model_visualization.py +++ b/keras/src/utils/model_visualization.py @@ -203,6 +203,7 @@ def model_to_dot( subgraph=False, show_layer_activations=False, show_trainable=False, + splines="ortho", **kwargs, ): """Convert a Keras model to dot format. @@ -222,6 +223,9 @@ def model_to_dot( show_layer_activations: Display layer activations (only for layers that have an `activation` property). show_trainable: whether to display if a layer is trainable. + splines: Controls how edges are drawn. Defaults to `"ortho"` + (right-angle lines). Other options include `"curved"`, + `"polyline"`, `"spline"`, and `"line"`. Returns: A `pydot.Dot` instance representing the Keras model or @@ -257,12 +261,7 @@ def model_to_dot( dot.set("rankdir", rankdir) dot.set("concentrate", True) dot.set("dpi", dpi) - # "ortho" splines are incompatible with horizontal (LR/RL) layouts - # in graphviz, producing empty output for complex models. - if rankdir in ("LR", "RL"): - dot.set("splines", "curved") - else: - dot.set("splines", "ortho") + dot.set("splines", splines) dot.set_node_defaults(shape="record") if kwargs.pop("layer_range", None) is not None: @@ -419,6 +418,7 @@ def plot_model( dpi=200, show_layer_activations=False, show_trainable=False, + splines="ortho", **kwargs, ): """Converts a Keras model to dot format and save to a file. @@ -449,6 +449,9 @@ def plot_model( show_layer_activations: Display layer activations (only for layers that have an `activation` property). show_trainable: whether to display if a layer is trainable. + splines: Controls how edges are drawn. Defaults to `"ortho"` + (right-angle lines). Other options include `"curved"`, + `"polyline"`, `"spline"`, and `"line"`. Returns: A Jupyter notebook Image object if Jupyter is installed. @@ -502,6 +505,7 @@ def plot_model( dpi=dpi, show_layer_activations=show_layer_activations, show_trainable=show_trainable, + splines=splines, ) to_file = str(to_file) if dot is None: