【发布时间】:2020-07-08 07:22:28
【问题描述】:
系统信息 是否编写了自定义代码:是 操作系统平台和发行版:Windows 10 移动设备:没有 TensorFlow 安装自:conda install tensorflow TensorFlow 版本:2.1.0(仅限 CPU) Python版本:3 描述当前行为 我训练了一个 TF Keras 模型(总结如下)并将其用于插槽分类,效果很好。
然后我使用:tf.saved_model.save(joint_model, 'BERT2.tf') 保存它
然后我加载模型:bertmodel = tf.keras.models.load_model('BERT2.tf', compile=False)
它使用与保存模型相同的参数进行编译。
然后尝试使用与以前相同的函数进行预测,但出现以下错误:ValueError: Could not find matching function to call loaded from the SavedModel
描述预期的行为 我使用相同的函数运行预测,但加载的模型给出了错误。 我尝试安装 nightly tensorflow build 但没有成功。
重现问题的独立代码 提供一个可重现的测试用例,这是生成所需的最低限度 问题。如果可能,请分享指向 Colab/Jupyter/任何笔记本的链接。 型号:
培训:
joint_model.compile(optimizer=opt, loss=losses, metrics=metrics)
history = joint_model.fit(encoded_train, slot_train, epochs=15, batch_size=32)
Function for predictions:
def show_predictions(text, tokenizer, model, slot_names):
其他信息/日志包括任何有助于 诊断问题。如果包括回溯,请包括完整的 追溯。应附上大型日志和文件。
ValueError: Could not find matching function to call loaded from the SavedModel. Got:
Positional arguments (1 total):
* Tensor("inputs:0", shape=(1, 8), dtype=int32)
Keyword arguments: {'training': False}
Expected these arguments to match one of the following 4 option(s):
Option 1:
Positional arguments (1 total):
* {'attention_masks': TensorSpec(shape=(None, 25), dtype=tf.int32, name='inputs/attention_masks'), 'input_ids': TensorSpec(shape=(None, 25), dtype=tf.int32, name='inputs/input_ids')}
Keyword arguments: {'training': False}
Option 2:
Positional arguments (1 total):
* {'attention_masks': TensorSpec(shape=(None, 25), dtype=tf.int32, name='attention_masks'), 'input_ids': TensorSpec(shape=(None, 25), dtype=tf.int32, name='input_ids')}
Keyword arguments: {'training': False}
Option 3:
Positional arguments (1 total):
* {'attention_masks': TensorSpec(shape=(None, 25), dtype=tf.int32, name='inputs/attention_masks'), 'input_ids': TensorSpec(shape=(None, 25), dtype=tf.int32, name='inputs/input_ids')}
Keyword arguments: {'training': True}
Option 4:
Positional arguments (1 total):
* {'attention_masks': TensorSpec(shape=(None, 25), dtype=tf.int32, name='attention_masks'), 'input_ids': TensorSpec(shape=(None, 25), dtype=tf.int32, name='input_ids')}
Keyword arguments: {'training': True}
【问题讨论】:
标签: tensorflow keras save tf.keras