'Cant properly load saved model and call predict method
I am having trouble loading large model after saving.
have tried all below saveing methods:
tf.saved_model.save(model, model_save_path)
model.save(model_save_path+"_new_save")
tf.keras.models.save_model(model, model_save_path+"_v3")
error when loading :
method 1
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
any help would be appreciated
Solution 1:[1]
Adding compile=False
to the load function will solve the issue:
m2=tf.keras.models.load_model(model_save_path+"_v3", compile=False)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |