h5py 3.0 incompatibility with TensorFlow model serialization (multiple versions)
See original GitHub issue- Operating System: Linux (Ubuntu 18.04), macOS
- Python version: 3.6, 3.7
- Where Python was acquired: System (Linux), Pyenv (macOS)
- h5py version: 3.0.0
- HDF5 version: 1.12.0
- The full traceback/stack trace shown:
Traceback (most recent call last):
File "test.py", line 5, in <module>
model.save('test.h5')
File "/Users/tgaddair/.venv/horovod/stable/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 1171, in save
signatures)
File "/Users/tgaddair/.venv/horovod/stable/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 109, in save_model
model, filepath, overwrite, include_optimizer)
File "/Users/tgaddair/.venv/horovod/stable/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 103, in save_model_to_hdf5
save_weights_to_hdf5_group(model_weights_group, model_layers)
File "/Users/tgaddair/.venv/horovod/stable/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 625, in save_weights_to_hdf5_group
param_dset = g.create_dataset(name, val.shape, dtype=val.dtype)
File "/Users/tgaddair/.venv/horovod/stable/lib/python3.7/site-packages/h5py/_hl/group.py", line 143, in create_dataset
if '/' in name:
TypeError: a bytes-like object is required, not 'str'
Here are the parameter values being passed from TensorFlow into create_dataset
:
self = <Closed HDF5 group>, name = b'dense/kernel:0', shape = (3, 2)
dtype = dtype('float32'), data = None, kwds = {'track_order': False}
group = <Closed HDF5 group>
As you can see, TensorFlow is providing the name as bytes type, not a str, which seems to be the crux of the issue here.
Repro script (tested with TensorFlow 1.15.0 and 2.3.1):
import tensorflow as tf
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(2, input_shape=(3,)))
model.save('test.h5')
Rolling back to h5py==2.10.0
works fine.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:8 (4 by maintainers)
Top Results From Across the Web
TensorFlow version compatibility
Version skew in distributed Tensorflow: Running two different versions of TensorFlow in a single cluster is unsupported. There are no guarantees ...
Read more >tensorflow 2.5.0 has requirement h5py~=3.1.0, but you'll have ...
2, but you'll have numpy 1.21.0 which is incompatible. I am installing it in Programming Environment with Python 3.8.5, pip 20.0.2, Ubuntu 20.04 ......
Read more >tensorflow bug requires h5py < 3.0 / Applications & Desktop ...
Hi all,. There is a bug in tensorflow and the suggested workaround is to use h5py < 3.0. The community/python-h5py version is 3.1.0...
Read more >What's new in h5py 3.0
h5py now requires Python 3.6 or above; it is no longer compatible with Python 2.7. The default mode for opening files is now...
Read more >Source code for tensorflow.python.keras.engine.training
There are two ways to instantiate a `Model`: 1 - With the "Functional API", where you start from `Input`, you chain layer calls...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@takluyver Do have any idea about https://github.com/tensorflow/tensorflow/pull/45380 fails?
Seems that something diverged between Linux and Win/Macosx with h5py 3.x. With exactly the same code we have now
AttributeError: 'str' object has no attribute 'decode'
but only on Win/MacosxI’m not aware of anything in h5py that would make it platform dependent.
You might want to use
h5dump
(command line tool) to see what’s really in the HDF5 file you’re trying to read.