fastmachinelearning / hls4ml

Machine learning on FPGAs using HLS
https://fastmachinelearning.org/hls4ml
Apache License 2.0
1.25k stars 407 forks source link

Fix keras model loading issue with loading model with KerasH5 #664

Closed calad0i closed 2 years ago

calad0i commented 2 years ago

A# Description

In the current version of hls4ml, if one use the key "KerasH5" and not supplying the json model file to load the Keras model, the framework will try to decode the string in h5.attrs[ ] in utf-8 and fails. This PR patchs this issue by doing a type check first.

Type of change

For a new feature or function, please create an issue first to discuss it with us before submitting a pull request.

Note: Please delete options that are not relevant.

Tests

:memo: Please describe the tests that you ran to verify your changes.

  • Provide instructions so we can reproduce.
  • Please also list any relevant details for your test configuration.

Test Configuration: Unit test added for KerasH5 loader at test/pytest/test_keras_h5_loader.py Create any keras model, save it to .h5 and use only the KerasH5 without providing the in the config dictionary (or command line interface) to load it model json -> crash

Checklist

vloncar commented 2 years ago

This is probably due to changes in the h5py. What version are you using?

calad0i commented 2 years ago

Currently 3.7.0.