Closed ageron closed 1 year ago
I think you're supposed to use the new keras.saving
namespace:
keras.saving.save_model(model, 'model.keras')
Hi @bermeitinger-b ,
Thanks for your response. I believe model.save(...)
is an alias for keras.saving.save_model(model, ...)
. It works fine, but it saves the model using the Keras format. I'd like to export the model to TensorFlow's SavedModel format. It is no longer supported by model.save()
(or by keras.saving.save_model()
) but it should be supported by tf.saved_model.save()
, so I believe there's a bug, either in Keras-Core or in TF. I've updated my bug report to make it clear that I'm trying to export to the SavedModel format.
This seems to be because the KerasVariable within the Dense layer isn't a TF trackable obj like tf.Variable etc. Looks like KerasVariable needs to inherit from tensorflow.python.trackable.base.Trackable to work with tf.saved_model.save? Both the Dense layer and sequential seem to inherit from it, but the weights within Dense don't seem to.
@ageron As per code this format most likely will not be supported just see the internal code below.
if save_format in ["h5", "tf"]:
raise ValueError(
"`'h5'` and `'t5'` formats are no longer supported via the "
"`save_format` option. Please use the new `'keras'` format. "
f"Received: save_format={save_format}"
)
if save_format not in ["keras", "keras_v3"]:
raise ValueError(
"Unknown `save_format` value. Only the `'keras'` format is "
f"currently supported. Received: save_format={save_format}"
)
if not str(filepath).endswith(".keras"):
raise ValueError(
"The filename must end in `.keras`. "
f"Received: filepath={filepath}"
)
maybe in future this can add but not as of now 😕
@asingh9530 , thanks for your message. However I think you are referring to the model.save()
method, whereas I am trying to export the Keras-Core model to the SavedModel format using tf.saved_model.save()
, which is supposed to work (confirmed by @fchollet in personal communication).
The Keras-Core announcement does say that Keras-Core models can be exported to the SavedModel format:
@ageron aah sorry my bad. actually it is a known issue you can check it here
We're looking into this issue. The goal is to have tf.saved_model.save()
work on any Keras model.
It should be fixed now, please check that it works for you.
Awesome, it works now, thanks @fchollet!
I've installed Keras-Core with
pip install keras-core
and created a simpleSequential
model using the TensorFlow backend, and I'm trying to export it to TensorFlow's SavedModel format usingtf.saved_model.save()
, but this failed with the following error:Here is the code to reproduce the error (gist):
I've tried with both TensorFlow 2.12 and 2.13, and got the same error.
And here is the full stacktrace: