hls4ml icon indicating copy to clipboard operation
hls4ml copied to clipboard

Fix keras model loading issue with loading model with KerasH5

Open calad0i opened this issue 2 years ago • 1 comments

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.

  • [x] Bug fix (non-breaking change that fixes an issue)
  • [ ] Documentation update
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] A new research paper code implementation
  • [ ] Other (Specify)

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

  • [x] I have read the guidelines for contributing.
  • [ ] I have commented my code, particularly in hard-to-understand areas.
  • [ ] I have made corresponding changes to the documentation.
  • [ ] My changes generate no new warnings.
  • [x] I have added tests that prove my fix is effective or that my feature works.B

calad0i avatar Oct 14 '22 19:10 calad0i

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

vloncar avatar Oct 14 '22 21:10 vloncar

Currently 3.7.0.

calad0i avatar Oct 15 '22 08:10 calad0i