Skip to content

Commit d2ccfb4

Browse files
committed
revert keras v2 converter
1 parent 3f8acb5 commit d2ccfb4

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

hls4ml/converters/keras_to_hls.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from warnings import warn
32

43
import h5py
54

@@ -231,8 +230,8 @@ def parse_keras_model(model_arch, reader):
231230
layer_config = model_arch['config']
232231
if 'layers' in layer_config: # Newer Keras versions have 'layers' in 'config' key
233232
layer_config = layer_config['layers']
233+
# Sequential doesn't have InputLayer in TF < 2.3 (Keras 2.4.0)
234234
if layer_config[0]['class_name'] != 'InputLayer':
235-
warn(DeprecationWarning('keras < 2.4.0 (tf 2.3) is deprecated. Please use a newer version.'))
236235
input_layer = {}
237236
input_layer['name'] = 'input1'
238237
input_layer['class_name'] = 'InputLayer'
@@ -244,33 +243,25 @@ def parse_keras_model(model_arch, reader):
244243
layer_config = model_arch['config']['layers']
245244
input_layers = [inp[0] for inp in model_arch['config']['input_layers']]
246245
output_layers = [out[0] for out in model_arch['config']['output_layers']]
247-
else:
248-
raise Exception(f'ERROR: Model class not supported: {model_arch["class_name"]}')
249246

250247
# Get input shape and check for unsupported layer type
251248
for keras_layer in layer_config:
252249
if keras_layer['class_name'] not in supported_layers:
253-
raise Exception(f'ERROR: Unsupported layer type: {keras_layer["class_name"]}')
250+
raise Exception('ERROR: Unsupported layer type: {}'.format(keras_layer['class_name']))
254251

255252
output_shapes = {}
256253
output_shape = None
257254

258255
print('Topology:')
259256
for keras_layer in layer_config:
260-
if 'batch_input_shape' in keras_layer['config'] or 'batch_shape' in keras_layer['config']:
257+
if 'batch_input_shape' in keras_layer['config']:
261258
if 'inbound_nodes' in keras_layer and len(keras_layer['inbound_nodes']) > 0:
262259
input_shapes = [output_shapes[inbound_node[0]] for inbound_node in keras_layer['inbound_nodes'][0]]
263260
else:
264-
_input_shapes = keras_layer['config'].get('batch_input_shape', None)
265-
input_shapes = _input_shapes or keras_layer['config']['batch_shape']
261+
input_shapes = [keras_layer['config']['batch_input_shape']]
266262
else:
267263
if 'inbound_nodes' in keras_layer:
268-
if 'args' in keras_layer['inbound_nodes'][0]:
269-
# keras v3
270-
input_shapes = [arg['config']['shape'] for arg in keras_layer['inbound_nodes'][0]['args']]
271-
else:
272-
# keras v2
273-
input_shapes = [output_shapes[inbound_node[0]] for inbound_node in keras_layer['inbound_nodes'][0]]
264+
input_shapes = [output_shapes[inbound_node[0]] for inbound_node in keras_layer['inbound_nodes'][0]]
274265
else:
275266
# Sequential model, so output_shape from the previous layer is still valid
276267
input_shapes = [output_shape]

0 commit comments

Comments
 (0)