Python tensorflow.python.saved_model.signature_constants.REGRESS_METHOD_NAME Examples
The following are 16
code examples of tensorflow.python.saved_model.signature_constants.REGRESS_METHOD_NAME().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.saved_model.signature_constants
, or try the search function
.
Example #1
Source File: signature_def_utils_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testRegressionSignatureDef(self): input1 = constant_op.constant("a", name="input-1") output1 = constant_op.constant("b", name="output-1") signature_def = signature_def_utils.regression_signature_def(input1, output1) self.assertEqual(signature_constants.REGRESS_METHOD_NAME, signature_def.method_name) # Check inputs in signature def. self.assertEqual(1, len(signature_def.inputs)) x_tensor_info_actual = ( signature_def.inputs[signature_constants.REGRESS_INPUTS]) self.assertEqual("input-1:0", x_tensor_info_actual.name) self.assertEqual(types_pb2.DT_STRING, x_tensor_info_actual.dtype) self.assertEqual(0, len(x_tensor_info_actual.tensor_shape.dim)) # Check outputs in signature def. self.assertEqual(1, len(signature_def.outputs)) y_tensor_info_actual = ( signature_def.outputs[signature_constants.REGRESS_OUTPUTS]) self.assertEqual("output-1:0", y_tensor_info_actual.name) self.assertEqual(types_pb2.DT_STRING, y_tensor_info_actual.dtype) self.assertEqual(0, len(y_tensor_info_actual.tensor_shape.dim))
Example #2
Source File: bundle_shim_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testConvertDefaultSignatureRegressionToSignatureDef(self): signatures_proto = manifest_pb2.Signatures() regression_signature = manifest_pb2.RegressionSignature() regression_signature.input.CopyFrom( manifest_pb2.TensorBinding( tensor_name=signature_constants.REGRESS_INPUTS)) regression_signature.output.CopyFrom( manifest_pb2.TensorBinding( tensor_name=signature_constants.REGRESS_OUTPUTS)) signatures_proto.default_signature.regression_signature.CopyFrom( regression_signature) signature_def = bundle_shim._convert_default_signature_to_signature_def( signatures_proto) # Validate regression signature correctly copied over. self.assertEqual(signature_def.method_name, signature_constants.REGRESS_METHOD_NAME) self.assertEqual(len(signature_def.inputs), 1) self.assertEqual(len(signature_def.outputs), 1) self.assertProtoEquals( signature_def.inputs[signature_constants.REGRESS_INPUTS], meta_graph_pb2.TensorInfo(name=signature_constants.REGRESS_INPUTS)) self.assertProtoEquals( signature_def.outputs[signature_constants.REGRESS_OUTPUTS], meta_graph_pb2.TensorInfo(name=signature_constants.REGRESS_OUTPUTS))
Example #3
Source File: bundle_shim_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testSavedModelBasic(self): base_path = test.test_src_dir_path(SAVED_MODEL_PATH) ops.reset_default_graph() sess, meta_graph_def = ( bundle_shim.load_session_bundle_or_saved_model_bundle_from_path( base_path, tags=[tag_constants.SERVING], target="", config=config_pb2.ConfigProto(device_count={"CPU": 2}))) self.assertTrue(sess) # Check basic signature def property. signature_def = meta_graph_def.signature_def self.assertEqual(len(signature_def), 2) self.assertEqual( signature_def[signature_constants.REGRESS_METHOD_NAME].method_name, signature_constants.REGRESS_METHOD_NAME) signature = signature_def["tensorflow/serving/regress"] asset_path = os.path.join(base_path, saved_model_constants.ASSETS_DIRECTORY) with sess.as_default(): output1 = sess.run(["filename_tensor:0"]) self.assertEqual(["foo.txt"], output1)
Example #4
Source File: signature_def_utils_impl.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def _is_valid_regression_signature(signature_def): """Determine whether the argument is a servable 'regress' SignatureDef.""" if signature_def.method_name != signature_constants.REGRESS_METHOD_NAME: return False if (set(signature_def.inputs.keys()) != set([signature_constants.REGRESS_INPUTS])): return False if (signature_def.inputs[signature_constants.REGRESS_INPUTS].dtype != types_pb2.DT_STRING): return False if (set(signature_def.outputs.keys()) != set([signature_constants.REGRESS_OUTPUTS])): return False if (signature_def.outputs[signature_constants.REGRESS_OUTPUTS].dtype != types_pb2.DT_FLOAT): return False return True
Example #5
Source File: signature_def_utils_test.py From keras-lambda with MIT License | 6 votes |
def testRegressionSignatureDef(self): input1 = constant_op.constant("a", name="input-1") output1 = constant_op.constant("b", name="output-1") signature_def = signature_def_utils.regression_signature_def(input1, output1) self.assertEqual(signature_constants.REGRESS_METHOD_NAME, signature_def.method_name) # Check inputs in signature def. self.assertEqual(1, len(signature_def.inputs)) x_tensor_info_actual = ( signature_def.inputs[signature_constants.REGRESS_INPUTS]) self.assertEqual("input-1:0", x_tensor_info_actual.name) self.assertEqual(types_pb2.DT_STRING, x_tensor_info_actual.dtype) self.assertEqual(0, len(x_tensor_info_actual.tensor_shape.dim)) # Check outputs in signature def. self.assertEqual(1, len(signature_def.outputs)) y_tensor_info_actual = ( signature_def.outputs[signature_constants.REGRESS_OUTPUTS]) self.assertEqual("output-1:0", y_tensor_info_actual.name) self.assertEqual(types_pb2.DT_STRING, y_tensor_info_actual.dtype) self.assertEqual(0, len(y_tensor_info_actual.tensor_shape.dim))
Example #6
Source File: bundle_shim_test.py From keras-lambda with MIT License | 6 votes |
def testConvertDefaultSignatureRegressionToSignatureDef(self): signatures_proto = manifest_pb2.Signatures() regression_signature = manifest_pb2.RegressionSignature() regression_signature.input.CopyFrom( manifest_pb2.TensorBinding( tensor_name=signature_constants.REGRESS_INPUTS)) regression_signature.output.CopyFrom( manifest_pb2.TensorBinding( tensor_name=signature_constants.REGRESS_OUTPUTS)) signatures_proto.default_signature.regression_signature.CopyFrom( regression_signature) signature_def = bundle_shim._convert_default_signature_to_signature_def( signatures_proto) # Validate regression signature correctly copied over. self.assertEqual(signature_def.method_name, signature_constants.REGRESS_METHOD_NAME) self.assertEqual(len(signature_def.inputs), 1) self.assertEqual(len(signature_def.outputs), 1) self.assertProtoEquals( signature_def.inputs[signature_constants.REGRESS_INPUTS], meta_graph_pb2.TensorInfo(name=signature_constants.REGRESS_INPUTS)) self.assertProtoEquals( signature_def.outputs[signature_constants.REGRESS_OUTPUTS], meta_graph_pb2.TensorInfo(name=signature_constants.REGRESS_OUTPUTS))
Example #7
Source File: bundle_shim_test.py From keras-lambda with MIT License | 6 votes |
def testSavedModelBasic(self): base_path = test.test_src_dir_path(SAVED_MODEL_PATH) ops.reset_default_graph() sess, meta_graph_def = ( bundle_shim.load_session_bundle_or_saved_model_bundle_from_path( base_path, tags=[tag_constants.SERVING], target="", config=config_pb2.ConfigProto(device_count={"CPU": 2}))) self.assertTrue(sess) # Check basic signature def property. signature_def = meta_graph_def.signature_def self.assertEqual(len(signature_def), 2) self.assertEqual( signature_def[signature_constants.REGRESS_METHOD_NAME].method_name, signature_constants.REGRESS_METHOD_NAME) signature = signature_def["tensorflow/serving/regress"] asset_path = os.path.join(base_path, saved_model_constants.ASSETS_DIRECTORY) with sess.as_default(): output1 = sess.run(["filename_tensor:0"]) self.assertEqual(["foo.txt"], output1)
Example #8
Source File: signature_def_utils_impl.py From lambda-packs with MIT License | 5 votes |
def regression_signature_def(examples, predictions): """Creates regression signature from given examples and predictions. Args: examples: `Tensor`. predictions: `Tensor`. Returns: A regression-flavored signature_def. Raises: ValueError: If examples is `None`. """ if examples is None: raise ValueError('examples cannot be None for regression.') if predictions is None: raise ValueError('predictions cannot be None for regression.') input_tensor_info = utils.build_tensor_info(examples) signature_inputs = {signature_constants.REGRESS_INPUTS: input_tensor_info} output_tensor_info = utils.build_tensor_info(predictions) signature_outputs = {signature_constants.REGRESS_OUTPUTS: output_tensor_info} signature_def = build_signature_def( signature_inputs, signature_outputs, signature_constants.REGRESS_METHOD_NAME) return signature_def
Example #9
Source File: signature_def_utils_impl.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def regression_signature_def(examples, predictions): """Creates regression signature from given examples and predictions. Args: examples: `Tensor`. predictions: `Tensor`. Returns: A regression-flavored signature_def. Raises: ValueError: If examples is `None`. """ if examples is None: raise ValueError('examples cannot be None for regression.') if predictions is None: raise ValueError('predictions cannot be None for regression.') input_tensor_info = utils.build_tensor_info(examples) signature_inputs = {signature_constants.REGRESS_INPUTS: input_tensor_info} output_tensor_info = utils.build_tensor_info(predictions) signature_outputs = {signature_constants.REGRESS_OUTPUTS: output_tensor_info} signature_def = build_signature_def( signature_inputs, signature_outputs, signature_constants.REGRESS_METHOD_NAME) return signature_def
Example #10
Source File: signature_def_utils_impl.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def regression_signature_def(examples, predictions): """Creates regression signature from given examples and predictions. Args: examples: `Tensor`. predictions: `Tensor`. Returns: A regression-flavored signature_def. Raises: ValueError: If examples is `None`. """ if examples is None: raise ValueError('Regression examples cannot be None.') if not isinstance(examples, ops.Tensor): raise ValueError('Regression examples must be a string Tensor.') if predictions is None: raise ValueError('Regression predictions cannot be None.') input_tensor_info = utils.build_tensor_info(examples) if input_tensor_info.dtype != types_pb2.DT_STRING: raise ValueError('Regression examples must be a string Tensor.') signature_inputs = {signature_constants.REGRESS_INPUTS: input_tensor_info} output_tensor_info = utils.build_tensor_info(predictions) if output_tensor_info.dtype != types_pb2.DT_FLOAT: raise ValueError('Regression output must be a float Tensor.') signature_outputs = {signature_constants.REGRESS_OUTPUTS: output_tensor_info} signature_def = build_signature_def( signature_inputs, signature_outputs, signature_constants.REGRESS_METHOD_NAME) return signature_def
Example #11
Source File: signature_def_utils_impl.py From keras-lambda with MIT License | 5 votes |
def regression_signature_def(examples, predictions): """Creates regression signature from given examples and predictions. Args: examples: `Tensor`. predictions: `Tensor`. Returns: A regression-flavored signature_def. Raises: ValueError: If examples is `None`. """ if examples is None: raise ValueError('examples cannot be None for regression.') if predictions is None: raise ValueError('predictions cannot be None for regression.') input_tensor_info = utils.build_tensor_info(examples) signature_inputs = {signature_constants.REGRESS_INPUTS: input_tensor_info} output_tensor_info = utils.build_tensor_info(predictions) signature_outputs = {signature_constants.REGRESS_OUTPUTS: output_tensor_info} signature_def = build_signature_def( signature_inputs, signature_outputs, signature_constants.REGRESS_METHOD_NAME) return signature_def
Example #12
Source File: bundle_shim.py From lambda-packs with MIT License | 4 votes |
def _convert_default_signature_to_signature_def(signatures): """Convert default signature to object of type SignatureDef. Args: signatures: object of type manifest_pb2.Signatures() Returns: object of type SignatureDef which contains a converted version of default signature from input signatures object Returns None if signature is of generic type because it cannot be converted to SignatureDef. """ default_signature = signatures.default_signature signature_def = meta_graph_pb2.SignatureDef() if default_signature.WhichOneof("type") == "regression_signature": regression_signature = default_signature.regression_signature signature_def.method_name = signature_constants.REGRESS_METHOD_NAME _add_input_to_signature_def(regression_signature.input.tensor_name, signature_constants.REGRESS_INPUTS, signature_def) _add_output_to_signature_def(regression_signature.output.tensor_name, signature_constants.REGRESS_OUTPUTS, signature_def) elif default_signature.WhichOneof("type") == "classification_signature": classification_signature = default_signature.classification_signature signature_def.method_name = signature_constants.CLASSIFY_METHOD_NAME _add_input_to_signature_def(classification_signature.input.tensor_name, signature_constants.CLASSIFY_INPUTS, signature_def) _add_output_to_signature_def(classification_signature.classes.tensor_name, signature_constants.CLASSIFY_OUTPUT_CLASSES, signature_def) _add_output_to_signature_def(classification_signature.scores.tensor_name, signature_constants.CLASSIFY_OUTPUT_SCORES, signature_def) else: logging.error("Only classification and regression default signatures " "are supported for up-conversion. %s is not " "supported" % default_signature.WhichOneof("type")) return None return signature_def
Example #13
Source File: bundle_shim_test.py From auto-alt-text-lambda-api with MIT License | 4 votes |
def testConvertSignaturesToSignatureDefs(self): base_path = test.test_src_dir_path(SESSION_BUNDLE_PATH) meta_graph_filename = os.path.join(base_path, constants.META_GRAPH_DEF_FILENAME) metagraph_def = meta_graph.read_meta_graph_file(meta_graph_filename) default_signature_def, named_signature_def = ( bundle_shim._convert_signatures_to_signature_defs(metagraph_def)) self.assertEqual(default_signature_def.method_name, signature_constants.REGRESS_METHOD_NAME) self.assertEqual(len(default_signature_def.inputs), 1) self.assertEqual(len(default_signature_def.outputs), 1) self.assertProtoEquals( default_signature_def.inputs[signature_constants.REGRESS_INPUTS], meta_graph_pb2.TensorInfo(name="tf_example:0")) self.assertProtoEquals( default_signature_def.outputs[signature_constants.REGRESS_OUTPUTS], meta_graph_pb2.TensorInfo(name="Identity:0")) self.assertEqual(named_signature_def.method_name, signature_constants.PREDICT_METHOD_NAME) self.assertEqual(len(named_signature_def.inputs), 1) self.assertEqual(len(named_signature_def.outputs), 1) self.assertProtoEquals( named_signature_def.inputs["x"], meta_graph_pb2.TensorInfo(name="x:0")) self.assertProtoEquals( named_signature_def.outputs["y"], meta_graph_pb2.TensorInfo(name="y:0")) # Now try default signature only collection_def = metagraph_def.collection_def signatures_proto = manifest_pb2.Signatures() signatures = collection_def[constants.SIGNATURES_KEY].any_list.value[0] signatures.Unpack(signatures_proto) named_only_signatures_proto = manifest_pb2.Signatures() named_only_signatures_proto.CopyFrom(signatures_proto) default_only_signatures_proto = manifest_pb2.Signatures() default_only_signatures_proto.CopyFrom(signatures_proto) default_only_signatures_proto.named_signatures.clear() default_only_signatures_proto.ClearField("named_signatures") metagraph_def.collection_def[constants.SIGNATURES_KEY].any_list.value[ 0].Pack(default_only_signatures_proto) default_signature_def, named_signature_def = ( bundle_shim._convert_signatures_to_signature_defs(metagraph_def)) self.assertEqual(default_signature_def.method_name, signature_constants.REGRESS_METHOD_NAME) self.assertEqual(named_signature_def, None) named_only_signatures_proto.ClearField("default_signature") metagraph_def.collection_def[constants.SIGNATURES_KEY].any_list.value[ 0].Pack(named_only_signatures_proto) default_signature_def, named_signature_def = ( bundle_shim._convert_signatures_to_signature_defs(metagraph_def)) self.assertEqual(named_signature_def.method_name, signature_constants.PREDICT_METHOD_NAME) self.assertEqual(default_signature_def, None)
Example #14
Source File: rnn_classifier.py From text-antispam with MIT License | 4 votes |
def export(model_version, model_dir, sess, x, y_op): """导出tensorflow_serving可用的模型 SavedModel(tensorflow.python.saved_model)提供了一种跨语言格式来保存和恢复训练后的TensorFlow模型。它使用方法签名来定义Graph的输入和输出,使上层系统能够更方便地生成、调用或转换TensorFlow模型。 SavedModelBuilder类提供保存Graphs、Variables及Assets的方法。所保存的Graphs必须标注用途标签。在这个实例中我们打算将模型用于服务而非训练,因此我们用SavedModel预定义好的tag_constant.Serving标签。 为了方便地构建签名,SavedModel提供了signature_def_utils API。我们通过signature_def_utils.build_signature_def()来构建predict_signature。一个predict_signature至少包含以下参数: * inputs = {'x': tensor_info_x} 指定输入的tensor信息 * outputs = {'y': tensor_info_y} 指定输出的tensor信息 * method_name = signature_constants.PREDICT_METHOD_NAME method_name定义方法名,它的值应该是tensorflow/serving/predict、tensorflow/serving/classify和tensorflow/serving/regress三者之一。Builder标签用来明确Meta Graph被加载的方式,只接受serve和train两种类型。 """ if model_version <= 0: logging.warning('Please specify a positive value for version number.') sys.exit() path = os.path.dirname(os.path.abspath(model_dir)) if os.path.isdir(path) == False: logging.warning('Path (%s) not exists, making directories...', path) os.makedirs(path) export_path = os.path.join( compat.as_bytes(model_dir), compat.as_bytes(str(model_version))) if os.path.isdir(export_path) == True: logging.warning('Path (%s) exists, removing directories...', export_path) shutil.rmtree(export_path) builder = saved_model_builder.SavedModelBuilder(export_path) tensor_info_x = utils.build_tensor_info(x) tensor_info_y = utils.build_tensor_info(y_op) prediction_signature = signature_def_utils.build_signature_def( inputs={'x': tensor_info_x}, outputs={'y': tensor_info_y}, # signature_constants.CLASSIFY_METHOD_NAME = "tensorflow/serving/classify" # signature_constants.PREDICT_METHOD_NAME = "tensorflow/serving/predict" # signature_constants.REGRESS_METHOD_NAME = "tensorflow/serving/regress" # 如果缺失method_name会报错: # grpc.framework.interfaces.face.face.AbortionError: AbortionError(code=StatusCode.INTERNAL, details="Expected prediction signature method_name to be one of {tensorflow/serving/predict, tensorflow/serving/classify, tensorflow/serving/regress}. Was: ") method_name=signature_constants.PREDICT_METHOD_NAME) builder.add_meta_graph_and_variables( sess, # tag_constants.SERVING = "serve" # tag_constants.TRAINING = "train" # 如果只有train标签,TensorFlow Serving加载时会报错: # E tensorflow_serving/core/aspired_versions_manager.cc:351] Servable {name: default version: 2} cannot be loaded: Not found: Could not find meta graph def matching supplied tags. [tag_constants.SERVING], signature_def_map={ 'predict_text': prediction_signature, # 如果缺失会报错: # grpc.framework.interfaces.face.face.AbortionError: AbortionError(code=StatusCode.FAILED_PRECONDITION, details="Default serving signature key not found.") signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: prediction_signature }) builder.save()
Example #15
Source File: cnn_classifier.py From text-antispam with MIT License | 4 votes |
def export(model_version, model_dir, sess, x, y_op): """导出tensorflow_serving可用的模型 SavedModel(tensorflow.python.saved_model)提供了一种跨语言格式来保存和恢复训练后的TensorFlow模型。它使用方法签名来定义Graph的输入和输出,使上层系统能够更方便地生成、调用或转换TensorFlow模型。 SavedModelBuilder类提供保存Graphs、Variables及Assets的方法。所保存的Graphs必须标注用途标签。在这个实例中我们打算将模型用于服务而非训练,因此我们用SavedModel预定义好的tag_constant.Serving标签。 为了方便地构建签名,SavedModel提供了signature_def_utils API。我们通过signature_def_utils.build_signature_def()来构建predict_signature。一个predict_signature至少包含以下参数: * inputs = {'x': tensor_info_x} 指定输入的tensor信息 * outputs = {'y': tensor_info_y} 指定输出的tensor信息 * method_name = signature_constants.PREDICT_METHOD_NAME method_name定义方法名,它的值应该是tensorflow/serving/predict、tensorflow/serving/classify和tensorflow/serving/regress三者之一。Builder标签用来明确Meta Graph被加载的方式,只接受serve和train两种类型。 """ if model_version <= 0: logging.warning('Please specify a positive value for version number.') sys.exit() path = os.path.dirname(os.path.abspath(model_dir)) if os.path.isdir(path) == False: logging.warning('Path (%s) not exists, making directories...', path) os.makedirs(path) export_path = os.path.join( compat.as_bytes(model_dir), compat.as_bytes(str(model_version))) if os.path.isdir(export_path) == True: logging.warning('Path (%s) exists, removing directories...', export_path) shutil.rmtree(export_path) builder = saved_model_builder.SavedModelBuilder(export_path) tensor_info_x = utils.build_tensor_info(x) tensor_info_y = utils.build_tensor_info(y_op) prediction_signature = signature_def_utils.build_signature_def( inputs={'x': tensor_info_x}, outputs={'y': tensor_info_y}, # signature_constants.CLASSIFY_METHOD_NAME = "tensorflow/serving/classify" # signature_constants.PREDICT_METHOD_NAME = "tensorflow/serving/predict" # signature_constants.REGRESS_METHOD_NAME = "tensorflow/serving/regress" # 如果缺失method_name会报错: # grpc.framework.interfaces.face.face.AbortionError: AbortionError(code=StatusCode.INTERNAL, details="Expected prediction signature method_name to be one of {tensorflow/serving/predict, tensorflow/serving/classify, tensorflow/serving/regress}. Was: ") method_name=signature_constants.PREDICT_METHOD_NAME) builder.add_meta_graph_and_variables( sess, # tag_constants.SERVING = "serve" # tag_constants.TRAINING = "train" # 如果只有train标签,TensorFlow Serving加载时会报错: # E tensorflow_serving/core/aspired_versions_manager.cc:351] Servable {name: default version: 2} cannot be loaded: Not found: Could not find meta graph def matching supplied tags. [tag_constants.SERVING], signature_def_map={ 'predict_text': prediction_signature, # 如果缺失会报错: # grpc.framework.interfaces.face.face.AbortionError: AbortionError(code=StatusCode.FAILED_PRECONDITION, details="Default serving signature key not found.") signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: prediction_signature }) builder.save()
Example #16
Source File: bundle_shim_test.py From keras-lambda with MIT License | 4 votes |
def testConvertSignaturesToSignatureDefs(self): base_path = test.test_src_dir_path(SESSION_BUNDLE_PATH) meta_graph_filename = os.path.join(base_path, constants.META_GRAPH_DEF_FILENAME) metagraph_def = meta_graph.read_meta_graph_file(meta_graph_filename) default_signature_def, named_signature_def = ( bundle_shim._convert_signatures_to_signature_defs(metagraph_def)) self.assertEqual(default_signature_def.method_name, signature_constants.REGRESS_METHOD_NAME) self.assertEqual(len(default_signature_def.inputs), 1) self.assertEqual(len(default_signature_def.outputs), 1) self.assertProtoEquals( default_signature_def.inputs[signature_constants.REGRESS_INPUTS], meta_graph_pb2.TensorInfo(name="tf_example:0")) self.assertProtoEquals( default_signature_def.outputs[signature_constants.REGRESS_OUTPUTS], meta_graph_pb2.TensorInfo(name="Identity:0")) self.assertEqual(named_signature_def.method_name, signature_constants.PREDICT_METHOD_NAME) self.assertEqual(len(named_signature_def.inputs), 1) self.assertEqual(len(named_signature_def.outputs), 1) self.assertProtoEquals( named_signature_def.inputs["x"], meta_graph_pb2.TensorInfo(name="x:0")) self.assertProtoEquals( named_signature_def.outputs["y"], meta_graph_pb2.TensorInfo(name="y:0")) # Now try default signature only collection_def = metagraph_def.collection_def signatures_proto = manifest_pb2.Signatures() signatures = collection_def[constants.SIGNATURES_KEY].any_list.value[0] signatures.Unpack(signatures_proto) named_only_signatures_proto = manifest_pb2.Signatures() named_only_signatures_proto.CopyFrom(signatures_proto) default_only_signatures_proto = manifest_pb2.Signatures() default_only_signatures_proto.CopyFrom(signatures_proto) default_only_signatures_proto.named_signatures.clear() default_only_signatures_proto.ClearField("named_signatures") metagraph_def.collection_def[constants.SIGNATURES_KEY].any_list.value[ 0].Pack(default_only_signatures_proto) default_signature_def, named_signature_def = ( bundle_shim._convert_signatures_to_signature_defs(metagraph_def)) self.assertEqual(default_signature_def.method_name, signature_constants.REGRESS_METHOD_NAME) self.assertEqual(named_signature_def, None) named_only_signatures_proto.ClearField("default_signature") metagraph_def.collection_def[constants.SIGNATURES_KEY].any_list.value[ 0].Pack(named_only_signatures_proto) default_signature_def, named_signature_def = ( bundle_shim._convert_signatures_to_signature_defs(metagraph_def)) self.assertEqual(named_signature_def.method_name, signature_constants.PREDICT_METHOD_NAME) self.assertEqual(default_signature_def, None)