DeepCTR
DeepCTR copied to clipboard
din模型训练成功并且能保存pb模型但是无法加载训练好的pb模型
Please refer to the FAQ in doc and search for the related issues before you ask the question.
Describe the question(问题描述) 运行: if name == "main": x, y, feature_columns, behavior_feature_list = get_xy_fd() model = DIN(feature_columns, behavior_feature_list) # model = BST(feature_columns, behavior_feature_list,att_head_num=4) model.compile('adam', 'binary_crossentropy', metrics=['binary_crossentropy']) history = model.fit(x, y, verbose=1, epochs=10, validation_split=0.5) # 训练成功 model.save("./mydinModel") # 可以正常保存 reloadModel = models.load_model("mydinModel") # 此处报错
报错信息: `ValueError: Could not find matching function to call loaded from the SavedModel. Got: Positional arguments (2 total): * Tensor("x:0", shape=(None, 1, 8), dtype=float32) * None Keyword arguments: {'training': True}
Expected these arguments to match one of the following 8 option(s):
Option 1: Positional arguments (2 total): * TensorSpec(shape=(None, 1, 8), dtype=tf.float32, name='x') * TensorSpec(shape=(None, 1), dtype=tf.bool, name='mask') Keyword arguments: {'training': True}
Option 2: Positional arguments (2 total): * TensorSpec(shape=(None, 1, 4), dtype=tf.float32, name='x') * TensorSpec(shape=(None, 1), dtype=tf.bool, name='mask') Keyword arguments: {'training': False}
Option 3: Positional arguments (2 total): * TensorSpec(shape=(None, 1, 10), dtype=tf.float32, name='x') * None Keyword arguments: {'training': True}
Option 4: Positional arguments (2 total): * TensorSpec(shape=(None, 1, 4), dtype=tf.float32, name='x') * TensorSpec(shape=(None, 1), dtype=tf.bool, name='mask') Keyword arguments: {'training': True}
Option 5: Positional arguments (2 total): * TensorSpec(shape=(None, 1, 4), dtype=tf.float32, name='x') * None Keyword arguments: {'training': False}
Option 6: Positional arguments (2 total): * TensorSpec(shape=(None, 1, 8), dtype=tf.float32, name='x') * TensorSpec(shape=(None, 1), dtype=tf.bool, name='mask') Keyword arguments: {'training': False}
Option 7: Positional arguments (2 total): * TensorSpec(shape=(None, 1, 4), dtype=tf.float32, name='x') * None Keyword arguments: {'training': True}
Option 8: Positional arguments (2 total): * TensorSpec(shape=(None, 1, 10), dtype=tf.float32, name='x') * None Keyword arguments: {'training': False}
Process finished with exit code 1 `
Additional context Add any other context about the problem here.
Operating environment(运行环境):
- windows10 操作系统
- python version [3.6]
- tensorflow version [2.1.0]
- deepctr version [0.9.1]
其他模型也有类似情况,PB格式模型用tensorflow.python.keras.models.load_model加载的时候就报这个,用Java等语言加载则正常;如果还是用Python处理的话H5格式模型我这边加载正常。
https://github.com/shenweichen/DeepCTR/blob/master/docs/source/FAQ.md
pass in custom_objects when loading model
load_model(model_path, custom_objects)