HLS Model Class
This page documents our hls_model class usage. You can generate generate an hls model object from a keras model through
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 your keras model as a hls project to
Compile your hls project.
keras’s predict API, you can get the predictions of
hls_model just by supplying an input
# 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.
hls_model.build() #You can also read the report of the build hls4ml.report.read_vivado_report('hls4ml_prj')
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)