@@ -98,8 +98,9 @@ def add_layer_into_RModel(rmodel, layer_data):
9898
9999 fLayerType = layer_data ['layerType' ]
100100
101- # reshape and flatten layers don't have weights, but they are needed inside the list of initialized
102- # tensor list in the Rmodel
101+ print ('Model: adding layer' ,fLayerType )
102+
103+ # reshape and flatten layers don't have weights, but they need constant tensor for the shape
103104 if fLayerType == "Reshape" or fLayerType == "Flatten" :
104105 Attributes = layer_data ['layerAttributes' ]
105106 if keras_version < '2.16' :
@@ -108,8 +109,8 @@ def add_layer_into_RModel(rmodel, layer_data):
108109 LayerName = Attributes ['name' ]
109110
110111 if fLayerType == "Reshape" :
111- TargetShape = np .asarray (Attributes ['target_shape' ]).astype ("int " )
112- TargetShape = np .insert (TargetShape ,0 ,0 )
112+ TargetShape = np .asarray (Attributes ['target_shape' ]).astype ("int64 " )
113+ TargetShape = np .insert (TargetShape ,0 ,1 )
113114 else :
114115 if '_build_input_shape' in Attributes .keys ():
115116 input_shape = Attributes ['_build_input_shape' ]
@@ -124,8 +125,14 @@ def add_layer_into_RModel(rmodel, layer_data):
124125
125126 # since the AddInitializedTensor method in RModel requires unique pointer, we call a helper function
126127 # in c++ that does the conversion from a regular pointer to unique one in c++
127- rmodel .AddInitializedTensor ['long' ](LayerName + "ReshapeAxes" , [len (TargetShape )], TargetShape )
128-
128+ #print('adding initialized tensor..',LayerName, TargetShape)
129+ shape_tensor_name = LayerName + "_shape"
130+ shape_data = TargetShape .data
131+ print (TargetShape , shape_data )
132+ print (len (TargetShape ))
133+ rmodel .AddInitializedTensor ['int64_t' ](shape_tensor_name , [len (TargetShape )], shape_data )
134+
135+ print ('check other layers...' )
129136 # These layers only have one operator - excluding the recurrent layers, in which the activation function(s)
130137 # are included in the recurrent operator
131138 if fLayerType in mapKerasLayer .keys ():
@@ -340,7 +347,6 @@ def Parse(filename, batch_size=1): # If a model does not have a defined batch s
340347 # and output names
341348 layer_iter = 0
342349 is_functional_model = True if keras_model .__class__ .__name__ == 'Functional' else False
343- prev_layer_name = "input"
344350 for layer in keras_model .layers :
345351 layer_data = {}
346352 layer_data ['layerType' ]= layer .__class__ .__name__
@@ -365,14 +371,13 @@ def Parse(filename, batch_size=1): # If a model does not have a defined batch s
365371 if keras_version < '2.16' or is_functional_model :
366372 layer_data ['layerOutput' ]= [x .name for x in layer .output ] if isinstance (layer .output ,list ) else [layer .output .name ]
367373 else :
368- #sequentiall model in Keras3
374+ #sequential model in Keras3
369375 output_layer_name = "tensor_output_" + layer .name
370376 layer_data ['layerOutput' ]= [x .name for x in layer .output ] if isinstance (layer .output ,list ) else [output_layer_name ]
371377
372378 layer_iter += 1
373379 fLayerType = layer_data ['layerType' ]
374380 layer_data ['layerDType' ] = layer .dtype
375- prev_layer_name = layer .name
376381
377382 if len (layer .weights ) > 0 :
378383 if keras_version < '2.16' :
0 commit comments