Skip to content

Instantly share code, notes, and snippets.

@jmduarte
Created April 9, 2023 04:44
Show Gist options
  • Save jmduarte/41a6afcd412dbd7c39cdbd0e2a1a01a3 to your computer and use it in GitHub Desktop.
Save jmduarte/41a6afcd412dbd7c39cdbd0e2a1a01a3 to your computer and use it in GitHub Desktop.
from tensorflow.keras.layers import Input, Conv2D
from tensorflow.keras.models import Model
import numpy as np
import hls4ml
def main():
x_in = Input(shape=(4, 4, 1))
x_out = x = Conv2D(
4,
(3, 3),
use_bias=True,
name="conv1",
)(x_in)
model1 = Model(inputs=x_in, outputs=x_out)
model1.summary()
hls_config = hls4ml.utils.config_from_keras_model(model1, granularity="name")
hls_config["Model"]["Strategy"] = "Resource"
hls_config["IOTtype"] = "io_stream"
hls_model = hls4ml.converters.convert_from_keras_model(
model1,
hls_config=hls_config,
output_dir="model_pynq/hls4ml_prj_zcu104",
backend="VivadoAccelerator",
board="zcu104",
)
hls_model.compile()
y_hls = hls_model.predict(np.zeros((1, 4, 4, 1)))
print(y_hls)
hls_model.build(synth=True, export=True, bitfile=True)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment