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

Error while loading saved model #14265

Closed
pandeyp opened this issue Nov 2, 2020 · 9 comments
Closed

Error while loading saved model #14265

pandeyp opened this issue Nov 2, 2020 · 9 comments

Comments

@pandeyp
Copy link

pandeyp commented Nov 2, 2020

I am using Keras 2.2.4 with Tensorflow 1.14.0, Python 3.6.12. While loading model from architecture and json file as show below, I am getting error given below. Please help.

with open(model_architecture_file, 'r') as f: model = model_from_json(f.read()) model.load_weights(model_weights_file)

Stacktrace:

File "/home/hadoop/run_inference.py", line 58, in
model.load_weights(model_weights_file) ##Issue here!
File "/usr/local/lib64/python3.6/site-packages/keras/engine/saving.py", line 458, in load_wrapper
return load_function(*args, **kwargs)
File "/usr/local/lib64/python3.6/site-packages/keras/engine/network.py", line 1217, in load_weights
f, self.layers, reshape=reshape)
File "/usr/local/lib64/python3.6/site-packages/keras/engine/saving.py", line 1145, in load_weights_from_hdf5_group
original_keras_version = f.attrs['keras_version'].decode('utf8')
AttributeError: 'str' object has no attribute 'decode'

@stephan-hof
Copy link

stephan-hof commented Nov 2, 2020

I had the same issue and was able to fix this by setting h5py < 3.0.0.
Looks like here was a 3.0 release of h5py recently where they changed how strings are stored/read.
https://docs.h5py.org/en/stable/whatsnew/3.0.html#what-s-new-in-h5py-3-0

Note: The h5py file I tried to load was wirtten with h5py version 2.10.0

@stephan-hof
Copy link

The keras built into tensorflow has the same issue:
tensorflow/tensorflow#44467

@pandeyp
Copy link
Author

pandeyp commented Nov 2, 2020

Thanks Stephan. I was able to fix it by setting to a lower h5py version.

@pandeyp pandeyp closed this as completed Nov 2, 2020
@sairohithpasham
Copy link

Thanks Stephan. I was able to fix it by setting to a lower h5py version.

hey, I have the same issue, can you tell me what command did you use in command prompt to set the h5py to lower versions?

@stephan-hof
Copy link

Depends on how you installed keras in the first place. Typically it is done via pip, so the command to downgrade is:
pip install 'h5py<3.0.0'

georgepaw added a commit to graphcore/tensorflow that referenced this issue Dec 8, 2020
Summary:
See keras-team/keras#14265
Ref T29519
TF1.15 Only

Test Plan: CI

Reviewers: hakons, jakeh, jackh, vladimirm, markf, alfiee, #tensorflow, #framework_ip_review_-_any_oss_or_third-party_code_use_has_been_approved

Reviewed By: jakeh, #tensorflow, #framework_ip_review_-_any_oss_or_third-party_code_use_has_been_approved

Maniphest Tasks: T29519

Differential Revision: https://phabricator.sourcevertex.net/D35262
georgepaw added a commit to graphcore/tensorflow that referenced this issue Dec 8, 2020
Summary:
See keras-team/keras#14265
Ref T29519
TF2.1 Only

Test Plan: CI

Reviewers: jakeh, hakons, alfiee, vladimirm, markf, jackh, #tensorflow, #framework_ip_review_-_any_oss_or_third-party_code_use_has_been_approved

Reviewed By: jakeh, #tensorflow, #framework_ip_review_-_any_oss_or_third-party_code_use_has_been_approved

Maniphest Tasks: T29519

Differential Revision: https://phabricator.sourcevertex.net/D35263
TortoiseHam added a commit to TortoiseHam/fastestimator that referenced this issue Dec 14, 2020
vbvg2008 added a commit to fastestimator/fastestimator that referenced this issue Dec 14, 2020
johndpope added a commit to johndpope/StyleSegments that referenced this issue Jan 20, 2021
cesarrodrig added a commit to cesarrodrig/pos-tagger that referenced this issue Feb 16, 2021
@keshamin
Copy link

The solution for me was not only to downgrade h5py lib, but also downgrade python version to 3.6.9 as per this answer on StackOverflow.

@VirgilG72
Copy link

it works for me!

Depends on how you installed keras in the first place. Typically it is done via pip, so the command to downgrade is:
pip install 'h5py<3.0.0'

it works for me!

@microprediction
Copy link

Has anyone got this solution to work on M1? I'm not able to downgrade h5py.

@AlexDavydov357
Copy link

Solution:
Uninstall the original h5py module and install version 2.10. It's really helped me
pip install h5py==2.10 -i https://pypi.tuna.tsinghua.edu.cn/simple/

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

No branches or pull requests

7 participants