【发布时间】:2018-02-06 15:26:38
【问题描述】:
我有一个 TF 模型,我想以不同的增量保存它。我用来执行此操作的代码如下。每 100 步我想创建一个新模型,所以我打电话给builder.save()。
问题:每次我想保存时我需要调用整个块 2 还是只需要调用builder.save()?
# For exporting the model in SavedModel format
export_path = os.path.abspath(os.path.join(out_dir, "Model_Exports"))
builder = tf.saved_model.builder.SavedModelBuilder(export_path)
# Create classification signature - describes what model is being exported
tensor_info_x = tf.saved_model.utils.build_tensor_info(cnn.input_x)
tensor_info_y = tf.saved_model.utils.build_tensor_info(cnn.input_y)
classification_signature = (
tf.saved_model.signature_def_utils.build_signature_def(
inputs={'documents': tensor_info_x},
outputs={'scores': tensor_info_y},
method_name=tf.saved_model.signature_constants.CLASSIFY_METHOD_NAME)
)
# BLOCK2 - Adding metagraph and variables to export
builder.add_meta_graph_and_variables(
sess,
[tf.saved_model.tag_constants.SERVING],
signature_def_map={
'classify':
classification_signature,
}
)
【问题讨论】:
标签: python tensorflow machine-learning save builder