From c9fccab57ed15ad9b9f4c2d5789e434260cdb57f Mon Sep 17 00:00:00 2001 From: Sam Abrahams Date: Wed, 3 May 2017 14:20:06 -0700 Subject: [PATCH] Add check for duplicate names in import_graph_def (#9605) --- tensorflow/python/framework/importer.py | 3 +++ tensorflow/python/framework/importer_test.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/tensorflow/python/framework/importer.py b/tensorflow/python/framework/importer.py index fcddd9546d9..ed579224d32 100644 --- a/tensorflow/python/framework/importer.py +++ b/tensorflow/python/framework/importer.py @@ -275,6 +275,9 @@ def import_graph_def(graph_def, input_map=None, return_elements=None, # 1. Add operations without their inputs. for node in graph_def.node: + # Check to see if this op's name matches a previously seen op + if node.name in name_to_op: + raise ValueError('Duplicate name \'%s\' in GraphDef.' % node.name) # Set any default attr values that aren't present. if node.op not in op_dict: raise ValueError('No op named %s in defined operations.' % node.op) diff --git a/tensorflow/python/framework/importer_test.py b/tensorflow/python/framework/importer_test.py index c4ccc3d1892..2b2398f8332 100644 --- a/tensorflow/python/framework/importer_test.py +++ b/tensorflow/python/framework/importer_test.py @@ -685,6 +685,17 @@ class ImportGraphDefTest(test.TestCase): self.assertEqual("return_elements must be a list of strings.", str(e.exception)) + def testDuplicateOperationNames(self): + with ops.Graph().as_default(): + with self.assertRaises(ValueError) as e: + importer.import_graph_def( + self._MakeGraphDef(""" + node { name: 'A' op: 'Oi' } + node { name: 'B' op: 'Oi' } + node { name: 'A' op: 'Oi' } + """)) + self.assertEqual("Duplicate name 'A' in GraphDef.", str(e.exception)) + def testWithExtensionAndAttr(self): with ops.Graph().as_default() as g: c = constant_op.constant(5.0, dtype=dtypes.float32, name="c")