這篇看錯方向,看到 tf v1 的文件去了,之後會再把內容更新成 v2 的。
builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(export_path)
# Build the signature_def_map.
classification_inputs = tf.compat.v1.saved_model.utils.build_tensor_info(
serialized_tf_example)
classification_outputs_classes = tf.compat.v1.saved_model.utils.build_tensor_info(
prediction_classes)
classification_outputs_scores = tf.compat.v1.saved_model.utils.build_tensor_info(
values)
classification_signature = (
tf.compat.v1.saved_model.signature_def_utils.build_signature_def(
inputs={
tf.compat.v1.saved_model.signature_constants.CLASSIFY_INPUTS:
classification_inputs
},
outputs={
tf.compat.v1.saved_model.signature_constants
.CLASSIFY_OUTPUT_CLASSES:
classification_outputs_classes,
tf.compat.v1.saved_model.signature_constants
.CLASSIFY_OUTPUT_SCORES:
classification_outputs_scores
},
method_name=tf.compat.v1.saved_model.signature_constants
.CLASSIFY_METHOD_NAME))
tensor_info_x = tf.compat.v1.saved_model.utils.build_tensor_info(x)
tensor_info_y = tf.compat.v1.saved_model.utils.build_tensor_info(y)
prediction_signature = (
tf.compat.v1.saved_model.signature_def_utils.build_signature_def(
inputs={'images': tensor_info_x},
outputs={'scores': tensor_info_y},
method_name=tf.compat.v1.saved_model.signature_constants
.PREDICT_METHOD_NAME))
builder.add_meta_graph_and_variables(
sess, [tf.compat.v1.saved_model.tag_constants.SERVING],
signature_def_map={
'predict_images':
prediction_signature,
tf.compat.v1.saved_model.signature_constants
.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
classification_signature,
},
main_op=tf.compat.v1.tables_initializer(),
strip_default_attrs=True)
builder.save()