hls4ml.utils package

Submodules

hls4ml.utils.config module

hls4ml.utils.config.config_from_keras_model(model, granularity='model', default_precision='ap_fixed<16, 6>', default_reuse_factor=1)

Create an HLS conversion config given the Keras model.

This function serves as the initial step in creating the custom conversion configuration. Users are advised to inspect the returned object to tweak the conversion configuration. The return object can be passed as hls_config parameter to convert_from_keras_model.

Parameters
  • model – Keras model

  • granularity (str, optional) –

    Granularity of the created config. Defaults to ‘model’. Can be set to ‘model’, ‘type’ and ‘layer’.

    Granularity can be used to generate a more verbose config that can be fine-tuned. The default granulrity (‘model’) will generate config keys that apply to the whole model, so changes to the keys will affect the entire model. ‘type’ granularity will generate config keys that affect all layers of a given type, while the ‘name’ granularity will generate config keys for every layer separately, allowing for highly specific configuration tweaks.

  • default_precision (str, optional) – Default precision to use. Defaults to ‘ap_fixed<16,6>’.

  • default_reuse_factor (int, optional) – Default reuse factor. Defaults to 1.

Raises

Exception – If Keras model has layers not supported by hls4ml.

Returns

The created config.

Return type

[dict]

hls4ml.utils.config.create_vivado_config(output_dir='my-hls-test', project_name='myproject', fpga_part='xcku115-flvb2104-2-i', clock_period=5, io_type='io_parallel')

hls4ml.utils.example_models module

hls4ml.utils.example_models.fetch_example_list()
hls4ml.utils.example_models.fetch_example_model(model_name)

Download an example model (and example data & configuration if available) from github repo to working directory, and return the corresponding configuration:

https://github.com/hls-fpga-machine-learning/example-models

Use fetch_example_list() to see all the available models.

Parameters

model_name (-) – string, name of the example model in the repo. Example: fetch_example_model(‘KERAS_3layer.json’)

Returns

  • Dictionary that stores the configuration to the model

hls4ml.utils.plot module

Utilities related to model visualization.

hls4ml.utils.plot.add_edge(dot, src, dst)
hls4ml.utils.plot.check_pydot()

Returns True if PyDot and Graphviz are available.

hls4ml.utils.plot.model_to_dot(model, show_shapes=False, show_layer_names=True, show_precision=False, rankdir='TB', dpi=96, subgraph=False)

Convert a HLS model to dot format.

Parameters
  • model – A HLS model instance.

  • show_shapes – whether to display shape information.

  • show_layer_names – whether to display layer names.

  • show_precision – whether to display precision of layer’s variables.

  • rankdirrankdir argument passed to PyDot, a string specifying the format of the plot: ‘TB’ creates a vertical plot; ‘LR’ creates a horizontal plot.

  • dpi – Dots per inch.

  • subgraph – whether to return a pydot.Cluster instance.

Returns

A pydot.Dot instance representing the HLS model or a pydot.Cluster instance representing nested model if subgraph=True.

Raises

ImportError – if graphviz or pydot are not available.

hls4ml.utils.plot.plot_model(model, to_file='model.png', show_shapes=False, show_layer_names=True, show_precision=False, rankdir='TB', dpi=96)

Converts a HLS model to dot format and save to a file.

Parameters
  • model – A HLS model instance

  • to_file – File name of the plot image.

  • show_shapes – whether to display shape information.

  • show_layer_names – whether to display layer names.

  • show_precision – whether to display precision of layer’s variables.

  • rankdirrankdir argument passed to PyDot, a string specifying the format of the plot: ‘TB’ creates a vertical plot; ‘LR’ creates a horizontal plot.

  • dpi – Dots per inch.

Returns

A Jupyter notebook Image object if Jupyter is installed. This enables in-line display of the model plots in notebooks.

Module contents