[Frontend][Relay] Fix node indices attribute error for tensorflow 2.3 (#6288)
authorIswariya Manivannan <36193676+iswariyam@users.noreply.github.com>
Mon, 17 Aug 2020 03:53:38 +0000 (05:53 +0200)
committerGitHub <noreply@github.com>
Mon, 17 Aug 2020 03:53:38 +0000 (20:53 -0700)
* Fix errors caused due to node attributes

* Add node_indices attr for old keras pkg support

python/tvm/relay/frontend/keras.py

index 6972fb7..32de471 100644 (file)
@@ -1073,11 +1073,18 @@ def from_keras(model, shape=None, layout='NCHW'):
                 # The one exception is InputLayer. Changing input variable names after conversion
                 # would confuse users, so we should keep them as far as possible. Fortunately,
                 # they are named uniquely to input_1, input_2, input_3... by default.
-                zip_node = zip(
-                    _as_list(node.node_indices),
-                    _as_list(node.tensor_indices),
-                    _as_list(node.inbound_layers))
-                for n_idx, t_idx, inbound_layer in zip_node:
+                # node_indices attribute removed in tensorflow 2.3, however iterate_inbound() can
+                # be used
+                if hasattr(node, 'node_indices'):
+                    zip_node = zip(
+                        _as_list(node.inbound_layers),
+                        _as_list(node.node_indices),
+                        _as_list(node.tensor_indices),
+                        _as_list(node.input_tensors))
+                    node_attributes = zip_node
+                else:
+                    node_attributes = node.iterate_inbound()
+                for inbound_layer, n_idx, t_idx, _ in node_attributes:
                     if isinstance(inbound_layer, input_layer_class):
                         expr_name = inbound_layer.name
                         _convert_input_layer(inbound_layer)