From 78c48b184cb746a52de54f8bd233beadee1c0b02 Mon Sep 17 00:00:00 2001 From: Yating Jing Date: Tue, 9 Apr 2024 14:08:54 +0000 Subject: [PATCH] avoid failing directly if given a Keras 2 model --- tensorboard/plugins/graph/keras_util.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tensorboard/plugins/graph/keras_util.py b/tensorboard/plugins/graph/keras_util.py index ffa80b5edd..f6563bbfa7 100644 --- a/tensorboard/plugins/graph/keras_util.py +++ b/tensorboard/plugins/graph/keras_util.py @@ -122,6 +122,11 @@ def _get_inbound_nodes(layer): inbound_nodes = [] if layer.get("inbound_nodes") is not None: for maybe_inbound_node in layer.get("inbound_nodes", []): + if not isinstance(maybe_inbound_node, dict): + # Note that the inbound node parsing is not backward compatible with + # Keras 2. If given a Keras 2 model, the input nodes will be missing + # in the final graph. + continue for inbound_node_args in maybe_inbound_node.get("args", []): # Sometimes this field is a list when there are multiple inbound nodes # for the given layer.