diff --git a/hls4ml/converters/keras_to_hls.py b/hls4ml/converters/keras_to_hls.py index a206da4da..aa7bfe886 100644 --- a/hls4ml/converters/keras_to_hls.py +++ b/hls4ml/converters/keras_to_hls.py @@ -1,5 +1,4 @@ import json -from warnings import warn import h5py @@ -231,8 +230,8 @@ def parse_keras_model(model_arch, reader): layer_config = model_arch['config'] if 'layers' in layer_config: # Newer Keras versions have 'layers' in 'config' key layer_config = layer_config['layers'] + # Sequential doesn't have InputLayer in TF < 2.3 (Keras 2.4.0) if layer_config[0]['class_name'] != 'InputLayer': - warn(DeprecationWarning('keras < 2.4.0 (tf 2.3) is deprecated. Please use a newer version.')) input_layer = {} input_layer['name'] = 'input1' input_layer['class_name'] = 'InputLayer' @@ -244,33 +243,25 @@ def parse_keras_model(model_arch, reader): layer_config = model_arch['config']['layers'] input_layers = [inp[0] for inp in model_arch['config']['input_layers']] output_layers = [out[0] for out in model_arch['config']['output_layers']] - else: - raise Exception(f'ERROR: Model class not supported: {model_arch["class_name"]}') # Get input shape and check for unsupported layer type for keras_layer in layer_config: if keras_layer['class_name'] not in supported_layers: - raise Exception(f'ERROR: Unsupported layer type: {keras_layer["class_name"]}') + raise Exception('ERROR: Unsupported layer type: {}'.format(keras_layer['class_name'])) output_shapes = {} output_shape = None print('Topology:') for keras_layer in layer_config: - if 'batch_input_shape' in keras_layer['config'] or 'batch_shape' in keras_layer['config']: + if 'batch_input_shape' in keras_layer['config']: if 'inbound_nodes' in keras_layer and len(keras_layer['inbound_nodes']) > 0: input_shapes = [output_shapes[inbound_node[0]] for inbound_node in keras_layer['inbound_nodes'][0]] else: - _input_shapes = keras_layer['config'].get('batch_input_shape', None) - input_shapes = _input_shapes or keras_layer['config']['batch_shape'] + input_shapes = [keras_layer['config']['batch_input_shape']] else: if 'inbound_nodes' in keras_layer: - if 'args' in keras_layer['inbound_nodes'][0]: - # keras v3 - input_shapes = [arg['config']['shape'] for arg in keras_layer['inbound_nodes'][0]['args']] - else: - # keras v2 - input_shapes = [output_shapes[inbound_node[0]] for inbound_node in keras_layer['inbound_nodes'][0]] + input_shapes = [output_shapes[inbound_node[0]] for inbound_node in keras_layer['inbound_nodes'][0]] else: # Sequential model, so output_shape from the previous layer is still valid input_shapes = [output_shape]