HLS Model Class


This page documents our hls_model class usage. You can generate generate an hls model object from a keras model through hls4ml's API:

import hls4ml

# Generate a simple configuration from keras model
config = hls4ml.utils.config_from_keras_model(keras_model, granularity='name')

# Convert to an hls model
hls_model = hls4ml.converters.convert_from_keras_model(keras_model, hls_config=config, output_dir='test_prj')

After that, you can use several methods in that object. Here is a list of all the methods:

Similar functionalities are also supported through command line interface. If you prefer using them, please refer to Command Help section.


write method

Write your keras model as a hls project to hls_model's output_dir:

hls_model.write()

compile method

Compile your hls project.

hls_model.compile()

predict method

Similar to keras's predict API, you can get the predictions of hls_model just by supplying an input numpy array:

# Suppose that you already have input array X
# Note that you have to do hls_model.compile() before using predict

y = hls_model.predict(X)

This is similar to doing csim simulation, but you can get your prediction results much faster. It's very helpful when you want to quickly prototype different configurations for your model.


build method

hls_model.build()

#You can also read the report of the build 
hls4ml.report.read_vivado_report('hls4ml_prj')

trace method

The trace method is an advanced version of the predict method. It's used to trace individual outputs from each layer of the hls_model. This is useful for debugging and setting the appropriate configuration.

Return: A dictionary where the keys are the names of the layers, and its values are the layers's outputs.

predict_ouputs, trace_outputs =  hls_model.trace(X)

#We also support a similar function for keras
keras_trace = hls4ml.model.profiling.get_ymodel_keras(keras_model, X)

results matching ""

    No results matching ""