有没有重新训练SavedModel的示例?他们声称在许多地方可以代替使用检查点,但是没有提供示例。当我尝试执行时,模型的变量保持不变:
...
model_save_path = "test.pb"
with tf.Session(graph=tf.Graph()) as net:
...
for e in range(epochs):
# Train the model
...
builder = saved_model.builder.SavedModelBuilder(model_save_path)
signature = predict_signature_def(inputs={'myInput': X, 'errorInput': Y},
outputs={'myOutput': out, 'errorOutput': mse})
builder.add_meta_graph_and_variables(sess=net,
tags=[tag_constants.TRAINING],
signature_def_map={'predict': signature})
builder.save()
print(error)
上面的代码训练模型,将每个交互存储在模型中,并打印相关的错误。该代码的输出错误正在改善:
2773.6885
291.35968
263.40912
255.27612
当我们再次加载它并尝试对其进行训练时,错误保持不变:
...
# Load the model
model_save_path = "test.pb"
loaded = tf.saved_model.load(net, ["train"], model_save_path)
graph = tf.get_default_graph()
...
with tf.Session(graph=tf.Graph()) as net:
...
for e in range(epochs):
# Train the model
...
builder = saved_model.builder.SavedModelBuilder(model_save_path)
signature = predict_signature_def(inputs={'myInput': X, 'errorInput': Y},
outputs={'myOutput': out, 'errorOutput': mse})
builder.add_meta_graph_and_variables(sess=net,
tags=[tag_constants.TRAINING],
signature_def_map={'predict': signature})
builder.save()
print(error)
输出总是来自初始训练的错误:
255.27612
255.27612
255.27612
255.27612