apple / tensorflow_macos

TensorFlow for macOS 11.0+ accelerated using Apple's ML Compute framework.
Other
3.66k stars 308 forks source link

Can't load a keras model compiled using h5py=2.1.0 #213

Open MikeTuomas opened 3 years ago

MikeTuomas commented 3 years ago

I have setup conda env following instroductions in https://github.com/apple/tensorflow_macos/issues/153

When trying to load a whole model or weights created in google collab following error shows up: AttributeError: 'str' object has no attribute 'decode'

Seems like the only fix is to use h5py<3.0.0 . https://github.com/tensorflow/tensorflow/issues/44467

There is no such a package in miniforge for arm at the moment.

pro55b commented 3 years ago

I had this issue also making following modifications to the hdf5_format.py solved the problem. Obviously not the recommended way but if you need a quick solution this works.

if 'keras_version' in f.attrs:

original_keras_version = f.attrs['keras_version'].decode('utf8')

original_keras_version = f.attrs['keras_version']

else: original_keras_version = '1' if 'backend' in f.attrs:

original_backend = f.attrs['backend'].decode('utf8')

original_backend = f.attrs['backend']

else: original_backend = None