@@ -141,7 +141,7 @@ def is_nhwc(self):
141
141
142
142
def is_const (self ):
143
143
"""Return True if node is a constant."""
144
- return self .type in ["Const" , "ConstV2" , "Constant" ]
144
+ return self .type in ["Const" , "ConstV2" ]
145
145
146
146
def is_graph_input (self ):
147
147
return self .type in ["Placeholder" , "PlaceholderWithDefault" , "PlaceholderV2" ]
@@ -862,6 +862,7 @@ def make_graph(self, doc, graph_name="tf2onnx"):
862
862
for op in self .get_nodes ():
863
863
if op .is_const ():
864
864
const_ops .append (op )
865
+ continue
865
866
elif op .is_graph_input ():
866
867
if op not in self ._order_sensitive_inputs :
867
868
order_non_sensitive_placeholders .append (op )
@@ -871,6 +872,7 @@ def make_graph(self, doc, graph_name="tf2onnx"):
871
872
872
873
# create initializers for placeholder with default nodes
873
874
initializers = []
875
+ placeholder_default_const_ops = []
874
876
for op in placeholder_ops :
875
877
if op .type == "PlaceholderWithDefault" :
876
878
utils .make_sure (op .inputs [0 ] is not None , "Cannot find node with output {}" .format (op .input [0 ]))
@@ -880,24 +882,18 @@ def make_graph(self, doc, graph_name="tf2onnx"):
880
882
value = op .inputs [0 ].get_tensor_value (as_list = False )
881
883
tensor = numpy_helper .from_array (value , op .output [0 ])
882
884
initializers .append (tensor )
883
- const_ops .remove (op .inputs [0 ])
884
- ops .remove (op .inputs [0 ])
885
+ placeholder_default_const_ops .append (op .inputs [0 ])
885
886
886
887
# create initializers for constant nodes
888
+ const_ops = [op for op in const_ops if op not in placeholder_default_const_ops ]
887
889
for op in const_ops :
888
- # Constant support more dtypes after opset 9
889
- if self .opset < 9 :
890
- # not to use numpy_helper.from_array to create a new tensor
891
- # because sometimes onnx will have a bug that only check the tensor data in specific field
892
- # such as at upsample it only checks the float_data field.
893
- t = op .get_attr ("value" )
894
- tensor = helper .get_attribute_value (t )
895
- tensor .name = op .output [0 ]
896
- initializers .append (tensor )
897
- ops .remove (op )
898
- else :
899
- op .type = "Constant"
900
- op .update_proto ()
890
+ # not to use numpy_helper.from_array to create a new tensor
891
+ # because sometimes onnx will have a bug that only check the tensor data in specific field
892
+ # such as at upsample it only checks the float_data field.
893
+ t = op .get_attr ("value" )
894
+ tensor = helper .get_attribute_value (t )
895
+ tensor .name = op .output [0 ]
896
+ initializers .append (tensor )
901
897
902
898
# create input_tensor_values
903
899
input_ids = [op .output [0 ] for op in placeholder_ops ]
0 commit comments