I'm trying PlaidML
, which requires keras==2.2.4
. And I'm having difficulty loading the Saved Model format.
OSError: Unable to open file (unable to open file: name = '<my model path here>', errno = 13, error message = 'Permission denied', flags = 0, o_flags = 0)
I'm sure the model path exists, and files in it are readable.
I think Keras v2.2.4 isn't able to load Saved Model format.
Here is my keras\engine\saving.py
:
def load_model(filepath, custom_objects=None, compile=True):
"""Loads a model saved via `save_model`.
# Arguments
filepath: one of the following:
- string, path to the saved model, or
- h5py.File or h5py.Group object from which to load the model
custom_objects: Optional dictionary mapping names
(strings) to custom classes or functions to be
considered during deserialization.
compile: Boolean, whether to compile the model
after loading.
# Returns
A Keras model instance. If an optimizer was found
as part of the saved model, the model is already
compiled. Otherwise, the model is uncompiled and
a warning will be displayed. When `compile` is set
to False, the compilation is omitted without any
warning.
# Raises
ImportError: if h5py is not available.
ValueError: In case of an invalid savefile.
"""
if h5py is None:
raise ImportError('`load_model` requires h5py.')
model = None
opened_new_file = not isinstance(filepath, h5py.Group)
f = h5dict(filepath, 'r')
try:
model = _deserialize_model(f, custom_objects, compile)
finally:
if opened_new_file:
f.close()
return model
It seems that it just loads the path as a HDF5 file?
I also tried to convert the saved model to a .h5 file.
Then load it in keras v2.2.4, still not working:
Traceback (most recent call last):
File "test_plaidml.py", line 95, in <module>
model = keras.models.load_model(model_path)
File "keras\engine\saving.py", line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File "keras\engine\saving.py", line 224, in _deserialize_model
model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'
Any way to find out what's wrong without v2.2.4 documentation?
(I can't find it online)
Thanks.
Update
I think I known what the problem is, but I don't know how to solve it for now.
I'll try to find a solution.
- So Keras of this version is unable to load saved model (a TF2 feature).
It seems that v2.3.0 started to support TF2 partially. - Incompatible h5py version seems to be the cause of failing to load .h5 file.
Solved it by installing h5py==2.10.0 using Python 3.8. - However, I still got TypeError: init() got an unexpected keyword argument 'ragged', probably because I was using tf.keras, and switching to keras now.
I'm wondering whether it's possible to run a tf2 model on PlaidML / old Keras.