无法正确加载保存的模型并通话预测方法

发布于 2025-01-24 04:18:31 字数 1370 浏览 0 评论 0原文

保存后,我很难加载大型型号。

已经尝试了所有以下所有保存方法:

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")

加载时错误:

方法1

m2=tf.keras.models.load_model(model_save_path+"_v3")
error:
 __init__() got an unexpected keyword argument 'reduction'

方法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`.

方法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

任何帮助将不胜感激

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2025-01-31 04:18:31

compile = false添加到加载函数将解决问题:

m2=tf.keras.models.load_model(model_save_path+"_v3", compile=False)

Adding compile=False to the load function will solve the issue:

m2=tf.keras.models.load_model(model_save_path+"_v3", compile=False)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文