Skip to content

Commit f5c19e5

Browse files
Add signature constants for SavedModel in py.
Change: 135691893
1 parent 77bdea6 commit f5c19e5

4 files changed

Lines changed: 78 additions & 5 deletions

File tree

tensorflow/python/saved_model/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ py_library(
1515
srcs_version = "PY2AND3",
1616
)
1717

18+
py_library(
19+
name = "signature_constants",
20+
srcs = ["signature_constants.py"],
21+
srcs_version = "PY2AND3",
22+
)
23+
1824
py_library(
1925
name = "builder",
2026
srcs = ["builder.py"],

tensorflow/python/saved_model/example/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ py_binary(
3535
"//tensorflow/core:protos_all_py",
3636
"//tensorflow/python/saved_model:builder",
3737
"//tensorflow/python/saved_model:constants",
38+
"//tensorflow/python/saved_model:signature_constants",
3839
"//tensorflow/python/saved_model:utils",
3940
],
4041
)

tensorflow/python/saved_model/example/saved_model_half_plus_two.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from tensorflow.core.protobuf import meta_graph_pb2
3535
from tensorflow.python.saved_model import builder as saved_model_builder
3636
from tensorflow.python.saved_model import constants
37+
from tensorflow.python.saved_model import signature_constants
3738
from tensorflow.python.saved_model import utils
3839

3940

@@ -67,19 +68,23 @@ def _generate_saved_model_for_half_plus_two(export_dir, as_text=False):
6768
# specification.
6869
input_tensor = meta_graph_pb2.TensorInfo()
6970
input_tensor.name = serialized_tf_example.name
70-
signature_inputs = {"input": input_tensor}
71+
signature_inputs = {signature_constants.REGRESS_INPUTS: input_tensor}
7172

7273
output_tensor = meta_graph_pb2.TensorInfo()
7374
output_tensor.name = tf.identity(y).name
74-
signature_outputs = {"output": output_tensor}
75-
signature_def = utils.build_signature_def(signature_inputs,
76-
signature_outputs, "regression")
75+
signature_outputs = {signature_constants.REGRESS_OUTPUTS: output_tensor}
76+
signature_def = utils.build_signature_def(
77+
signature_inputs, signature_outputs,
78+
signature_constants.REGRESS_METHOD_NAME)
7779

7880
# Initialize all variables and then save the SavedModel.
7981
sess.run(tf.initialize_all_variables())
8082
builder.add_meta_graph_and_variables(
8183
sess, [constants.TAG_SERVING],
82-
signature_def_map={"regression": signature_def})
84+
signature_def_map={
85+
signature_constants.REGRESS_METHOD_NAME:
86+
signature_def
87+
})
8388
builder.save(as_text)
8489

8590

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Signature constants for SavedModel save and restore operations.
16+
17+
"""
18+
from __future__ import absolute_import
19+
from __future__ import division
20+
from __future__ import print_function
21+
22+
################################################################################
23+
# Classification API constants.
24+
25+
# Classification inputs.
26+
CLASSIFY_INPUTS = "inputs"
27+
28+
# Classification method name used in a SignatureDef.
29+
CLASSIFY_METHOD_NAME = "tensorflow/serving/classify"
30+
31+
# Classification classes output.
32+
CLASSIFY_OUTPUT_CLASSES = "classes"
33+
34+
# Classification scores output.
35+
CLASSIFY_OUTPUT_SCORES = "scores"
36+
37+
################################################################################
38+
# Prediction API constants.
39+
40+
# Predict inputs.
41+
PREDICT_INPUTS = "inputs"
42+
43+
# Prediction method name used in a SignatureDef.
44+
PREDICT_METHOD_NAME = "tensorflow/serving/predict"
45+
46+
# Predict outputs.
47+
PREDICT_OUTPUTS = "outputs"
48+
49+
################################################################################
50+
# Regression API constants.
51+
52+
# Regression inputs.
53+
REGRESS_INPUTS = "inputs"
54+
55+
# Regression method name used in a SignatureDef.
56+
REGRESS_METHOD_NAME = "tensorflow/serving/regress"
57+
58+
# Regression outputs.
59+
REGRESS_OUTPUTS = "outputs"
60+
61+
################################################################################

0 commit comments

Comments
 (0)