Skip to content

Commit c6d531c

Browse files
author
wayuanho
authored
Merge pull request #632 from zhijxu-MS/enhance
enhance check_integrity
2 parents dbd3569 + 75fcb7d commit c6d531c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tf2onnx/graph.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ def reset_nodes(self, ops):
575575
self._dtypes = remained_dtypes
576576
self._output_shapes = remained_shapes
577577

578+
def is_empty_input(self, name):
579+
# in ONNX, operation may have optional input and an empty string may be used
580+
# in the place of an actual argument's name to indicate a missing argument
581+
return name == utils.ONNX_EMPTY_INPUT
582+
578583
def check_integrity(self):
579584
"""
580585
Check graph integrity. Every node's input needs to associate with a node.
@@ -583,7 +588,7 @@ def check_integrity(self):
583588
broken_outputs = set()
584589
for node in self.get_nodes():
585590
for inp in node.input:
586-
if self.get_node_by_output(inp) is None:
591+
if self.get_node_by_output(inp) is None and not self.is_empty_input(inp):
587592
broken_outputs.add(inp)
588593
return list(broken_outputs)
589594

@@ -603,11 +608,12 @@ def update_node_shape_dtype(self, node, override=False):
603608
initializers = []
604609
for i, inp in enumerate(node.inputs):
605610
if inp is None:
606-
if logger.isEnabledFor(logging.INFO):
607-
logger.warning(
608-
"[%s] infer a inexistent node: [%s], please check the code",
609-
node.name, node.input[i]
610-
)
611+
if not self.is_empty_input(node.input[i]):
612+
if logger.isEnabledFor(logging.INFO):
613+
logger.warning(
614+
"[%s] infer a inexistent node: [%s], please check the code",
615+
node.name, node.input[i]
616+
)
611617
continue
612618
if inp.is_const():
613619
t = inp.get_attr("value")

0 commit comments

Comments
 (0)