简体   繁体   English

使用 tf.saved_model 保存和加载 model 时会发生什么变化

[英]What changes when saving and loading a model using tf.saved_model

I was following the official TensorFlow quick start tutorial and I wanted to save and load the model, but the following code raises on the final line我正在关注官方 TensorFlow 快速入门教程,我想保存并加载 model,但最后一行出现以下代码

ValueError: Could not find matching function to call loaded from the SavedModel. Got:
  Positional arguments (3 total):
    * Tensor("inputs:0", shape=(1, 28, 28), dtype=float64)
    * False
    * None
  Keyword arguments: {}

with declaring a keras sequential model and saving like so:声明一个 keras 顺序 model 并像这样保存:

print(model(x_train[:1]))
tf.saved_model.save(model, export_path)
loaded_model = tf.saved_model.load(export_path)
print(loaded_model(x_train[:1]))

I was able to work around the problem by using model.save(export_path) and tf.keras.load_model(export_path) respectively.我能够通过分别使用model.save(export_path)tf.keras.load_model(export_path)来解决这个问题。 The relevant documentation can be found here .相关文档可以在这里找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM