You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
h5py==3.0.0 causes issues with keras model loads in tensorflow 2.1.0 #44467
File "/databricks/python/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 146, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "/databricks/python/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 166, in load_model_from_hdf5
model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'
It looks like in version 2.1.0 the h5py version is not pinned (it is pinned in master), which is causing the issue.
Reacted by Joshua Newton, Ovidiu-Co, Chih-Hsuan Yen, Lukasz Stolcman, Olaf Wied, Danny Nemer, harsh-dialpad, JaledMC, Michael Liu, Augusto Bottelli and 42 more
@bhack I'm not going to add any more messages after this, but I think you can see based on these other issues the Keras API is essentially broken because h5py new release. I'm not sure why the version was not pinned as it is in master, but I strongly advise that you pin to h5py==2.10.0 this for all TF >= 2.1.
Reacted by vikram, bang.vo, Egor Eremeev, Minesh A. Jethva, abdulwaheedsoudagar, Tom, RobbinBouwmeester, Meisam, Spencer Hayes-Laverdiere, bharath and 36 more
Reacted by bharath and Faraz Ahmad
Reacted by Meisam, bharath, Faraz Ahmad and mohammad-ghahramani-ila
Reacted by bharath, JusesCheng, Faraz Ahmad, Roberto Panai, mohammad-ghahramani-ila and Talha Qureshi
Reacted by Meisam, bharath, Faraz Ahmad, LJLLDQ, Roberto Panai and mohammad-ghahramani-ila
Reacted by bharath, Cyril Gainon and mohammad-ghahramani-ila
FWIW, I got a similar error message with h5py 3.0, and removing .decode('utf-8') from tensorflow/python/keras/saving/hdf5_format.py allows me to load Keras models as before.
Reacted by keertika-11, mamrouche, HaiQW, nemasu, sundaycrunk, Robert Pickle, Bilal Ghanem, PS, Denis Akhiyarov, minakshimathpal and 2 more
I went around doing this:
Edit the hdf5_format.py file to delete all the references to .decode('utf-8') e.g: model_config = json.loads(model_config). Once you get the model loaded save the model in a json file and the weights in a h5 file. Then load the model like this:
With that, you won't have the problem with the decode('utf-8') and moreover, it is 10x faster than loading the whole model and the weights from an h5 file
After you can restore the original hdf5_format.py to the original one.
Where is hdf5_format.py located, was unable to find it in "h5py" folder.
Thanks!
The error message quotes the location of the file with the error.
Look at the error message python is printing. About the third last line will be:
File: "/path/to/your/hdf5_format.py" line NNN in load_model_from_hdf5
Your hdf5_format.py file is in directory /path/to/your/.
I am facing the same issue. Is there any solution came out to fix this bug:
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/network.py", line 1424, in load_weights saving.load_weights_from_hdf5_group(f, self.layers) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/hdf5_format.py", line 711, in load_weights_from_hdf5_group original_keras_version = f.attrs['keras_version'].decode('utf8') AttributeError: 'str' object has no attribute 'decode' python-BaseException
TF 2.1.x is no longer supported. TF 2.4.x was supposed to have this fixed (but also is no longer updated). Any version of TF above 2.4.0 should not have this issue. If there is a similar issue, please open a new issue.
Edit: locking to prevent notifications being sent to everyone that followed this issue over its lifetime and are no longer affected
Activity
bhack commentedon Oct 30, 2020
I think it will be hard to expect a backport on 2.1.0.
danzafar commentedon Oct 30, 2020
the new h5py version just came out today: https://pypi.org/project/h5py/#history
Pinning it to a version <3.0.0 (or at least throwing a warning) is a very lightweight change with no risk.
bhack commentedon Oct 30, 2020
Yes but as you know generally we had very few patch releases (e.g. 2.1.x) so It Is quite hard to have wheels with these fixes on old versions.
danzafar commentedon Oct 31, 2020
@bhack I'm not going to add any more messages after this, but I think you can see based on these other issues the Keras API is essentially broken because h5py new release. I'm not sure why the version was not pinned as it is in master, but I strongly advise that you pin to h5py==2.10.0 this for all TF >= 2.1.
bhack commentedon Oct 31, 2020
/cc @mihaimaruseac @angerson there are many Dockerfile and other file not constrained.
yan12125 commentedon Nov 1, 2020
FWIW, I got a similar error message with h5py 3.0, and removing
.decode('utf-8')fromtensorflow/python/keras/saving/hdf5_format.pyallows me to load Keras models as before.mihaimaruseac commentedon Nov 2, 2020
We cannot pin the versions without doing a patch release. We only do patch releases for security issues.
This issue has a quick workaround:
pip install tensorflow h5py<3.0.0.We are in the process of releasing TF 2.4 which should not be affected by this issue.
google-ml-butler commentedon Nov 2, 2020
Are you satisfied with the resolution of your issue?
Yes
No
55 remaining items
emerth commentedon Mar 18, 2021
The error message quotes the location of the file with the error.
Look at the error message python is printing. About the third last line will be:
File: "/path/to/your/hdf5_format.py" line NNN in load_model_from_hdf5Your hdf5_format.py file is in directory /path/to/your/.
CMCDragonkai commentedon Apr 8, 2021
Is this still a problem in TF 2.4.0? I still get the error in this case. Need to downgrade h5py.
bhack commentedon Apr 8, 2021
https://pypi.org/project/tensorflow/2.5.0rc0/
- pin the h5py version to < 3.0 (tensorflow/tensorflow#44467)
[Docker] Updated tensorflow/tflite version to 2.4.2
[Docker] Update tensorflow/tflite/xgboost versions (#8306)
Remheob commentedon Jul 1, 2021
Hey guys, when Iam trying to downgrade the version of h5py I get the follwing error:
ERROR: Failed building wheel for h5py
Running setup.py clean for h5py
Failed to build h5py
WARNING: Ignoring invalid distribution -ip (d:\tensorflow object detection\tfodcourse\tfod\lib\site-packages)
Installing collected packages: h5py
Attempting uninstall: h5py
WARNING: Ignoring invalid distribution -ip (d:\tensorflow object detection\tfodcourse\tfod\lib\site-packages)
Found existing installation: h5py 3.1.0
Uninstalling h5py-3.1.0:
Successfully uninstalled h5py-3.1.0
Running setup.py install for h5py ... error
ERROR: Command errored out with exit status 1:
command: 'd:\tensorflow object detection\tfodcourse\tfod\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = "C:\Users\Arne'"'"'s PC\AppData\Local\Temp\pip-install-8sioo065\h5py_f1f64cd207fd4e3fbbc73e1ddc4b40d2\setup.py"; file="C:\Users\Arne'"'"'s PC\AppData\Local\Temp\pip-install-8sioo065\h5py_f1f64cd207fd4e3fbbc73e1ddc4b40d2\setup.py";f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\Arne'"'"'s PC\AppData\Local\Temp\pip-record-prai98me\install-record.txt' --single-version-externally-managed --compile --install-headers 'd:\tensorflow object detection\tfodcourse\tfod\include\site\python3.9\h5py'
cwd: C:\Users\Arne's PC\AppData\Local\Temp\pip-install-8sioo065\h5py_f1f64cd207fd4e3fbbc73e1ddc4b40d2\
Rolling back uninstall of h5py
Moving to d:\tensorflow object detection\tfodcourse\tfod\lib\site-packages\h5py-3.1.0.dist-info
from D:\Tensorflow Object Detection\TFODCourse\tfod\Lib\site-packages~5py-3.1.0.dist-info
Moving to d:\tensorflow object detection\tfodcourse\tfod\lib\site-packages\h5py
from D:\Tensorflow Object Detection\TFODCourse\tfod\Lib\site-packages~5py
ERROR: Command errored out with exit status 1: 'd:\tensorflow object detection\tfodcourse\tfod\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = "C:\Users\Arne'"'"'s PC\AppData\Local\Temp\pip-install-8sioo065\h5py_f1f64cd207fd4e3fbbc73e1ddc4b40d2\setup.py"; file="C:\Users\Arne'"'"'s PC\AppData\Local\Temp\pip-install-8sioo065\h5py_f1f64cd207fd4e3fbbc73e1ddc4b40d2\setup.py";f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\Arne'"'"'s PC\AppData\Local\Temp\pip-record-prai98me\install-record.txt' --single-version-externally-managed --compile --install-headers 'd:\tensorflow object detection\tfodcourse\tfod\include\site\python3.9\h5py' Check the logs for full command output.
WARNING: Ignoring invalid distribution -ip (d:\tensorflow object detection\tfodcourse\tfod\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\tensorflow object detection\tfodcourse\tfod\lib\site-packages)
Would be awesome if someone can help me! :)
Bump modules and delete some conda/pip deps on Traverse
[Docker] Update tensorflow/tflite/xgboost versions (apache#8306)
Nafees-060 commentedon Oct 27, 2021
I am facing the same issue. Is there any solution came out to fix this bug:
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/network.py", line 1424, in load_weights saving.load_weights_from_hdf5_group(f, self.layers) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/hdf5_format.py", line 711, in load_weights_from_hdf5_group original_keras_version = f.attrs['keras_version'].decode('utf8') AttributeError: 'str' object has no attribute 'decode' python-BaseExceptionmeta.yaml: repin h5py
Re-pin h5py, because tensorflow/tensorflow#44467 is a gift that keeps…
60south commentedon Jan 5, 2022
Wait, why is this closed? I'm certainly still having the problem. Reverting to an earlier version of h5py is not a solution, it's a work-around.
mihaimaruseac commentedon Jan 5, 2022
TF 2.1.x is no longer supported. TF 2.4.x was supposed to have this fixed (but also is no longer updated). Any version of TF above 2.4.0 should not have this issue. If there is a similar issue, please open a new issue.
Edit: locking to prevent notifications being sent to everyone that followed this issue over its lifetime and are no longer affected