使用 tf.saved_model 保存和加载模型时发生了什么变化
What changes when saving and loading a model using tf.saved_model
我是按照官方的TensorFlow快速入门教程来的,我想保存和加载模型,但是下面的代码在最后一行出现了
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: {}
声明一个 keras 顺序模型并像这样保存:
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]))
我分别使用 model.save(export_path)
和 tf.keras.load_model(export_path)
解决了这个问题。可以找到相关文档 here.
我是按照官方的TensorFlow快速入门教程来的,我想保存和加载模型,但是下面的代码在最后一行出现了
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: {}
声明一个 keras 顺序模型并像这样保存:
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]))
我分别使用 model.save(export_path)
和 tf.keras.load_model(export_path)
解决了这个问题。可以找到相关文档 here.