Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 17, 2022

Conversation

calad0i
Copy link
Contributor

@calad0i calad0i commented Oct 14, 2022

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.

  • 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

📝 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

  • 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.
  • I have added tests that prove my fix is effective or that my feature works.B

@vloncar
Copy link
Contributor

vloncar commented Oct 14, 2022

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

@calad0i
Copy link
Contributor Author

calad0i commented Oct 15, 2022

Currently 3.7.0.

@@ -232,7 +232,10 @@ def keras_to_hls(config):
if model_arch is None:
raise ValueError('No model found in config file.')
else:
model_arch = json.loads(model_arch.decode('utf-8'))
# model_arch should be a string by default. Keeping this if just for compatibility.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this, and it seems to be an issue dating back to h5py version 3.0.0. Can you update this comment to include that? It will be easier in the future when we decide to clean up the codebase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tasting this out. I have updated the comment here.

Copy link
Contributor

@vloncar vloncar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@vloncar vloncar merged commit 0d1bc8b into fastmachinelearning:main Oct 17, 2022
calad0i added a commit to calad0i/hls4ml that referenced this pull request Jul 1, 2023
…chinelearning#664)

* Fix keras model loading issue with loading model with KerasH5

* Add unit test for KerasH5 loader

* comment on h5py version causing KerasH5 loading issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants