hls4ml.converters package

Submodules

hls4ml.converters.keras_to_hls module

class hls4ml.converters.keras_to_hls.KerasFileReader(config)

Bases: object

get_weights_data(layer_name, var_name)
get_weights_shape(layer_name, var_name)
class hls4ml.converters.keras_to_hls.KerasModelReader(keras_model)

Bases: object

get_weights_data(layer_name, var_name)
get_weights_shape(layer_name, var_name)
hls4ml.converters.keras_to_hls.compute_padding_1d(pad_type, in_size, stride, filt_size)
hls4ml.converters.keras_to_hls.compute_padding_2d(pad_type, in_height, in_width, stride_height, stride_width, filt_height, filt_width)
hls4ml.converters.keras_to_hls.get_qkeras_quantization(layer, keras_layer)
hls4ml.converters.keras_to_hls.get_supported_keras_layers()
hls4ml.converters.keras_to_hls.keras_handler(*args)
hls4ml.converters.keras_to_hls.keras_to_hls(config)
hls4ml.converters.keras_to_hls.parse_data_format(input_shape, data_format='channels_last')
hls4ml.converters.keras_to_hls.parse_default_keras_layer(keras_layer, input_names)
hls4ml.converters.keras_to_hls.register_keras_layer_handler(layer_name, handler_func)

hls4ml.converters.onnx_to_hls module

hls4ml.converters.pytorch_to_hls module

hls4ml.converters.tf_to_hls module

Module contents

hls4ml.converters.convert_from_config(config)

Convert to hls4ml model based on the provided configuration.

Parameters

config – A string containing the path to the YAML configuration file on the filesystem or a dict containig the parsed configuration.

Returns

hls4ml model.

Return type

HLSModel

hls4ml.converters.convert_from_keras_model(model, output_dir='my-hls-test', project_name='myproject', fpga_part='xcku115-flvb2104-2-i', clock_period=5, io_type='io_parallel', hls_config={})

Convert to hls4ml model based on the provided configuration.

Parameters
  • model – Keras model to convert

  • output_dir (str, optional) – Output directory of the generated HLS project. Defaults to ‘my-hls-test’.

  • project_name (str, optional) – Name of the HLS project. Defaults to ‘myproject’.

  • fpga_part (str, optional) – The target FPGA device. Defaults to ‘xcku115-flvb2104-2-i’.

  • clock_period (int, optional) – Clock period of the design. Defaults to 5.

  • io_type (str, optional) – Type of implementation used. One of ‘io_parallel’ or ‘io_serial’. Defaults to ‘io_parallel’.

  • hls_config (dict, optional) – The HLS config.

Raises

Exception – If precision and reuse factor are not present in ‘hls_config’

Returns

hls4ml model.

Return type

HLSModel

hls4ml.converters.parse_yaml_config(config_file)

Parse conversion configuration from the provided YAML file.

This function parses the conversion configuration contained in the YAML file provided as an argument. It ensures proper serialization of hls4ml objects and should be called on YAML files created by hls4ml. A minimal valid YAML file may look like this:

KerasH5: my_keras_model.h5
OutputDir: my-hls-test
ProjectName: myproject
XilinxPart: xcku115-flvb2104-2-i
ClockPeriod: 5
IOType: io_stream
HLSConfig:
    Model:
    Precision: ap_fixed<16,6>
    ReuseFactor: 10

Please refer to the docs for more examples of valid YAML configurations.

Parameters

config_file (str) – Location of the file on the filesystem.

Returns

Parsed configuration.

Return type

dict