@@ -490,7 +490,13 @@ def make_consts(self, values, np_type=np.int64, skip_conversion=False, raw=True)
490
490
consts = []
491
491
for value in values :
492
492
np_val = np .array (value ).astype (np_type )
493
- consts .append (self .make_const (utils .make_name ("const" ), np_val , skip_conversion , raw ).output [0 ])
493
+ key = str (np_val ) + "_" + str (np_val .dtype )
494
+ if key in self ._consts :
495
+ consts .append (self ._consts [key ])
496
+ else :
497
+ const_node = self .make_const (utils .make_name ("const" ), np_val , skip_conversion , raw )
498
+ self ._consts [key ] = const_node .output [0 ]
499
+ consts .append (const_node .output [0 ])
494
500
return consts
495
501
496
502
def make_const (self , name , np_val , skip_conversion = False , raw = True ):
@@ -501,11 +507,6 @@ def make_const(self, name, np_val, skip_conversion=False, raw=True):
501
507
skip_conversion: bool, indicate whether this created node would be mapped during conversion.
502
508
raw: whether to store data at field of raw_data or the specific field according to its dtype
503
509
"""
504
-
505
- key = str (np_val ) + "_" + str (np_val .dtype )
506
- if key in self ._consts :
507
- return self ._consts [key ]
508
-
509
510
if raw :
510
511
onnx_tensor = numpy_helper .from_array (np_val , name )
511
512
else :
@@ -514,8 +515,6 @@ def make_const(self, name, np_val, skip_conversion=False, raw=True):
514
515
dtype = onnx_tensor .data_type
515
516
node = self .make_node ("Const" , [], outputs = [name ], name = name , attr = {"value" : onnx_tensor },
516
517
skip_conversion = skip_conversion , dtypes = [dtype ], infer_shape_dtype = False )
517
-
518
- self ._consts [key ] = node
519
518
self .set_shape (name , np_val .shape )
520
519
self .set_dtype (name , utils .map_numpy_to_onnx_dtype (np_val .dtype ))
521
520
return node
0 commit comments