m2=tf.keras.models.load_model(model_save_path+"_v3")
error:
__init__() got an unexpected keyword argument 'reduction'
method 2
m3=tf.keras.models.load_model(model_save_path
error:
ARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), *NOT* tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
ValueError: Unable to create a Keras model from SavedModel at xxxx . This SavedModel was exported with `tf.saved_model.save`, and lacks the Keras metadata file. Please save your Keras model by calling `model.save`or `tf.keras.models.save_model`. Note that you can still load this SavedModel with `tf.saved_model.load`.
method 3
m4=tf.saved_model.load(model_save_path)
this works but m4 object has no predict method
and not able to use
model.signatures["serving_default"](**input_data)
or
model.__call__(input_data,training=False)
to predict on data
# This gives you a vanilla SavedModel
tf.saved_model.save(model, model_save_path)
# This gives you a keras-SavedModel
model.save(model_save_path)
You canât load a vanilla savedmodel as a keras-model.
For the other errors, It would help if you were a little more clear.
error:
__init__() got an unexpected keyword argument 'reduction'
This could happen if youâre using custom layers and your âget_configâ and âfrom_configâ donât work well together.
tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), *NOT* tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
What versions of tensorflow are you using to save/load the model?
but m4 object has no predict method
and not able to use
model.signatures["serving_default"](**input_data)
or
model.__call__(input_data,training=False)
to predict on data
Someone else asked me to clarify what I meant about get_config and from_config:
Okay, so .get_config is supposed to return a json-serializable object. That should only save the layerâs configuration, not its variable values.
So layers.Dense(units=5).get_config() returns {'units': 5}. Keras, basically, saves the class name and the config so that it can later rebuild the layer, and then restore a checkpoint into it to restore the weights.
from_config is a classmethod that recieves the json dict that was saved earlier, and needs to create the layer. The default implementation is: