def as_proto(self): """Returns this shape as a `TensorShapeProto`.""" if self._dims is None: return tensor_shape_pb2.TensorShapeProto(unknown_rank=True) else: return tensor_shape_pb2.TensorShapeProto(dim=[ tensor_shape_pb2.TensorShapeProto.Dim( size=-1 if d.value is None else d.value) for d in self._dims ])
def test_build_standardized_signature_def_classify_scores_only(self): """Tests classification without classes tensor.""" input_tensors = { "input-1": array_ops.placeholder(dtypes.string, 1, name="input-tensor-1") } scores = array_ops.placeholder(dtypes.float32, 1, name="output-tensor-scores") export_output = export_output_lib.ClassificationOutput(scores=scores) actual_signature_def = export_output.as_signature_def(input_tensors) expected_signature_def = meta_graph_pb2.SignatureDef() shape = tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]) dtype_float = types_pb2.DataType.Value("DT_FLOAT") dtype_string = types_pb2.DataType.Value("DT_STRING") expected_signature_def.inputs[ signature_constants.CLASSIFY_INPUTS].CopyFrom( meta_graph_pb2.TensorInfo(name="input-tensor-1:0", dtype=dtype_string, tensor_shape=shape)) expected_signature_def.outputs[ signature_constants.CLASSIFY_OUTPUT_SCORES].CopyFrom( meta_graph_pb2.TensorInfo(name="output-tensor-scores:0", dtype=dtype_float, tensor_shape=shape)) expected_signature_def.method_name = ( signature_constants.CLASSIFY_METHOD_NAME) self.assertEqual(actual_signature_def, expected_signature_def)
def make_tensor_proto(data, dtype, size) -> tensor_pb2.TensorProto: dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=size)] tensor_shape_proto = tensor_shape_pb2.TensorShapeProto(dim=dims) tensor_proto = tensor_pb2.TensorProto(dtype=dtype, tensor_shape=tensor_shape_proto, string_val=data) return tensor_proto
def test_build_standardized_signature_def_regression(self): input_tensors = { "input-1": array_ops.placeholder(dtypes.string, 1, name="input-tensor-1") } value = array_ops.placeholder(dtypes.float32, 1, name="output-tensor-1") export_output = export_output_lib.RegressionOutput(value) actual_signature_def = export_output.as_signature_def(input_tensors) expected_signature_def = meta_graph_pb2.SignatureDef() shape = tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]) dtype_float = types_pb2.DataType.Value("DT_FLOAT") dtype_string = types_pb2.DataType.Value("DT_STRING") expected_signature_def.inputs[ signature_constants.REGRESS_INPUTS].CopyFrom( meta_graph_pb2.TensorInfo(name="input-tensor-1:0", dtype=dtype_string, tensor_shape=shape)) expected_signature_def.outputs[ signature_constants.REGRESS_OUTPUTS].CopyFrom( meta_graph_pb2.TensorInfo(name="output-tensor-1:0", dtype=dtype_float, tensor_shape=shape)) expected_signature_def.method_name = signature_constants.REGRESS_METHOD_NAME self.assertEqual(actual_signature_def, expected_signature_def)
def test_build_standardized_signature_def_classify_classes_only(self): """Tests classification with one output tensor.""" with context.graph_mode(): input_tensors = { 'input-1': array_ops.placeholder( dtypes.string, 1, name='input-tensor-1') } classes = array_ops.placeholder(dtypes.string, 1, name='output-tensor-1') export_output = export_output_lib.ClassificationOutput(classes=classes) actual_signature_def = export_output.as_signature_def(input_tensors) expected_signature_def = meta_graph_pb2.SignatureDef() shape = tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]) dtype_string = types_pb2.DataType.Value('DT_STRING') expected_signature_def.inputs[ signature_constants.CLASSIFY_INPUTS].CopyFrom( meta_graph_pb2.TensorInfo(name='input-tensor-1:0', dtype=dtype_string, tensor_shape=shape)) expected_signature_def.outputs[ signature_constants.CLASSIFY_OUTPUT_CLASSES].CopyFrom( meta_graph_pb2.TensorInfo(name='output-tensor-1:0', dtype=dtype_string, tensor_shape=shape)) expected_signature_def.method_name = ( signature_constants.CLASSIFY_METHOD_NAME) self.assertEqual(actual_signature_def, expected_signature_def)
def get_resource_shape(node_name): node_name = get_source_node_name_through_identities(node_name) return tensor_shape_pb2.TensorShapeProto(dim=[ tensor_shape_pb2.TensorShapeProto.Dim(size=dim) for dim in tensor_data[node_name]["data"].shape ])
def test_build_standardized_signature_def_classification(self): """Tests classification with one output tensor.""" input_tensors = { "input-1": array_ops.placeholder(dtypes.string, 1, name="input-tensor-1") } output_tensors = { "output-1": array_ops.placeholder(dtypes.string, 1, name="output-tensor-1") } problem_type = constants.ProblemType.CLASSIFICATION actual_signature_def = ( saved_model_export_utils.build_standardized_signature_def( input_tensors, output_tensors, problem_type)) expected_signature_def = meta_graph_pb2.SignatureDef() shape = tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]) dtype_string = types_pb2.DataType.Value("DT_STRING") expected_signature_def.inputs[signature_constants.CLASSIFY_INPUTS].CopyFrom( meta_graph_pb2.TensorInfo( name="input-tensor-1:0", dtype=dtype_string, tensor_shape=shape)) expected_signature_def.outputs[ signature_constants.CLASSIFY_OUTPUT_CLASSES].CopyFrom( meta_graph_pb2.TensorInfo( name="output-tensor-1:0", dtype=dtype_string, tensor_shape=shape)) expected_signature_def.method_name = ( signature_constants.CLASSIFY_METHOD_NAME) self.assertEqual(actual_signature_def, expected_signature_def)
def construct_tensor(shapes, value): dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=dim) for dim in shapes] tensor_shape = tensor_shape_pb2.TensorShapeProto(dim=dims) tensor = tensor_pb2.TensorProto(dtype=types_pb2.DT_INT32, tensor_shape=tensor_shape, int_val=value) return tensor
def facenet_serving(images): host = '172.20.15.85' port = 8500 channel = implementations.insecure_channel(host, port) stub = prediction_service_pb2.beta_create_PredictionService_stub(channel) request = predict_pb2.PredictRequest() request.model_spec.name = '1' request.model_spec.signature_name = 'calculate_embeddings' image_data_arr = np.asarray(images) #print('image_data_arr',image_data_arr) #print('image_data',image_data_arr.dtype) input_size = image_data_arr.shape[0] dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=input_size)] print('dims',dims) tensor_shape_proto = tensor_shape_pb2.TensorShapeProto(dim=dims) tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DT_STRING, tensor_shape=tensor_shape_proto, string_val=[image_data for image_data in image_data_arr]) print('tensor_proto', tensor_proto) request.inputs['images'].CopyFrom(tensor_proto) result = stub.Predict(request, 10.0) print(MakeNdarray(result.outputs['embeddings'])) return MakeNdarray(result.outputs['embeddings'])
def onet_serving(image, channel): stub = prediction_service_pb2_grpc.PredictionServiceStub(channel) request = predict_pb2.PredictRequest() request.model_spec.name = 'mtcnn' request.model_spec.signature_name = 'onet_predict' image_data_arr = generate_input_string(image) image_data_arr = np.asarray(image_data_arr).squeeze() num_image = image_data_arr.shape[0] dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=num_image)] tensor_shape_proto = tensor_shape_pb2.TensorShapeProto(dim=dims) tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DT_STRING, tensor_shape=tensor_shape_proto, string_val=[image_data for image_data in image_data_arr]) request.inputs['images'].CopyFrom(tensor_proto) result = stub.Predict(request, 10.0) return [ MakeNdarray(result.outputs['result1']), MakeNdarray(result.outputs['result2']), MakeNdarray(result.outputs['result3']) ]
def _add_tf_shape(m, ints): sh = tensor_shape_pb2.TensorShapeProto() for i in ints: dim = tensor_shape_pb2.TensorShapeProto.Dim() dim.size = i sh.dim.extend([dim]) m['_output_shapes'].list.shape.extend([sh])
def main(): if len(sys.argv) != 2: print("error: only 1 argument accepted") sys.exit(1) ch = grpc.insecure_channel(sys.argv[1]) stub = prediction_service_pb2_grpc.PredictionServiceStub(ch) # same example inputs from https://www.tensorflow.org/tfx/serving/docker inputs = [1.0, 2.0, 5.0] input_tensor = tensor_pb2.TensorProto( dtype=types_pb2.DT_FLOAT, tensor_shape=tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=len(inputs), )]), float_val=inputs, ) req = predict_pb2.PredictRequest() req.model_spec.name = "half_plus_two" req.model_spec.signature_name = "serving_default" req.inputs["x"].CopyFrom(input_tensor) res = stub.Predict(req) print(text_format.MessageToString(res)) sys.exit(0)
def test_build_standardized_signature_def(self): input_tensors = { "input-1": array_ops.placeholder(dtypes.float32, 1, name="input-tensor-1") } output_tensors = { "output-1": array_ops.placeholder(dtypes.float32, 1, name="output-tensor-1") } problem_type = constants.ProblemType.LINEAR_REGRESSION regression_signature_def = ( saved_model_export_utils.build_standardized_signature_def( input_tensors, output_tensors, problem_type)) expected_regression_signature_def = meta_graph_pb2.SignatureDef() shape = tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]) dtype = types_pb2.DataType.Value("DT_FLOAT") expected_regression_signature_def.inputs[ signature_constants.REGRESS_INPUTS].CopyFrom( meta_graph_pb2.TensorInfo(name="input-tensor-1:0", dtype=dtype, tensor_shape=shape)) expected_regression_signature_def.outputs[ signature_constants.REGRESS_OUTPUTS].CopyFrom( meta_graph_pb2.TensorInfo(name="output-tensor-1:0", dtype=dtype, tensor_shape=shape)) expected_regression_signature_def.method_name = ( signature_constants.REGRESS_METHOD_NAME) self.assertEqual(regression_signature_def, expected_regression_signature_def)
def rnet_serving(image): host = '192.168.1.253' port = 9000 channel = implementations.insecure_channel(host, port) stub = prediction_service_pb2.beta_create_PredictionService_stub(channel) request = predict_pb2.PredictRequest() request.model_spec.name = 'mtcnn' request.model_spec.signature_name = 'rnet_predict' image_data_arr = generate_input_string(image) image_data_arr = np.asarray(image_data_arr).squeeze() num_image = image_data_arr.shape[0] dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=num_image)] tensor_shape_proto = tensor_shape_pb2.TensorShapeProto(dim=dims) tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DT_STRING, tensor_shape=tensor_shape_proto, string_val=[image_data for image_data in image_data_arr]) request.inputs['images'].CopyFrom(tensor_proto) result = stub.Predict(request, 10.0) return [ MakeNdarray(result.outputs['result1']), MakeNdarray(result.outputs['result2']) ]
def run_inference_for_single_image_grpc(self,image,project): # Get handles to input and output tensors request = predict_pb2.PredictRequest() # Specify model name (must be the same as when the TensorFlow serving serving was started) request.model_spec.name = project.model dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=1)] tensor_shape_proto = tensor_shape_pb2.TensorShapeProto(dim=dims) tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DT_STRING, tensor_shape=tensor_shape_proto, string_val=[image.tobytes()]) # Initalize prediction # Specify signature name (should be the same as specified when exporting model) request.model_spec.signature_name = '' request.inputs['inputs'].CopyFrom( tensor_proto) result = project.stub.Predict(request, 10.0) # Run inference output_dict = {} # all outputs are float32 numpy arrays, so convert types as appropriate output_dict['num_detections'] = np.squeeze(result.outputs['num_detections'].float_val).astype(np.int32) output_dict['detection_classes'] = np.squeeze(result.outputs['detection_classes'].float_val).astype(np.int32) output_dict['detection_boxes'] = np.reshape(result.outputs['detection_boxes'].float_val,[100,4]) output_dict['detection_scores'] = result.outputs['detection_scores'].float_val return output_dict
def testSpecifiedSignature(self): """Test prediction with spedicified signature definition.""" np.random.seed(4444) for key, op in KEYS_AND_OPS: x = np.random.rand() y = np.random.rand() expected_output = op(x, y) inputs = { 'x': meta_graph_pb2.TensorInfo( name='inputs/x:0', dtype=types_pb2.DT_FLOAT, tensor_shape=tensor_shape_pb2.TensorShapeProto()), 'y': meta_graph_pb2.TensorInfo( name='inputs/y:0', dtype=types_pb2.DT_FLOAT, tensor_shape=tensor_shape_pb2.TensorShapeProto()) } outputs = { key: meta_graph_pb2.TensorInfo( name='outputs/{}:0'.format(key), dtype=types_pb2.DT_FLOAT, tensor_shape=tensor_shape_pb2.TensorShapeProto()) } signature_def = signature_def_utils.build_signature_def( inputs=inputs, outputs=outputs, method_name='tensorflow/serving/regress') predictor = saved_model_predictor.SavedModelPredictor( export_dir=self._export_dir, signature_def=signature_def) output_tensor_name = predictor.fetch_tensors[key].name self.assertRegexpMatches(output_tensor_name, key, msg='Unexpected fetch tensor.') output = predictor({'x': x, 'y': y})[key] self.assertAlmostEqual( expected_output, output, places=3, msg='Failed for signature "{}". ' 'Got output {} for x = {} and y = {}'.format( key, output, x, y))
def make_tensor_proto_float(data, shape): dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=i) for i in shape] tensor_shape_proto = tensor_shape_pb2.TensorShapeProto(dim=dims) tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DT_FLOAT, tensor_shape=tensor_shape_proto, float_val=np.array(data).ravel().tolist()) return tensor_proto
def testFormatResourceTypeTensor(self): tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DataType.Value("DT_RESOURCE"), tensor_shape=tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)])) out = tensor_format.format_tensor( debug_data.InconvertibleTensorProto(tensor_proto), "a") self.assertEqual(["Tensor \"a\":", ""], out.lines[:2]) self.assertEqual(str(tensor_proto).split("\n"), out.lines[2:])
def make_tensor_proto(data): shape = data.shape dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=i) for i in shape] proto_shape = tensor_shape_pb2.TensorShapeProto(dim=dims) proto_dtype = dtypes_as_dtype(data.dtype) tensor_proto = tensor_pb2.TensorProto(dtype=proto_dtype, tensor_shape=proto_shape) tensor_proto.tensor_content = data.tostring() return tensor_proto
def make_tensor_shape_proto(shape): """Converts a list of integers to a `TensorShapeProto`. Args: shape: List of integers representing the dimensions of the tensor. Returns: A `TensorShapeProto`. """ return tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=x) for x in shape])
def testFormatUninitializedTensor(self): tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DataType.Value("DT_FLOAT"), tensor_shape=tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)])) out = tensor_format.format_tensor( debug_data.InconvertibleTensorProto(tensor_proto, False), "a") self.assertEqual(["Tensor \"a\":", "", "Uninitialized tensor:"], out.lines[:3]) self.assertEqual(str(tensor_proto).split("\n"), out.lines[3:])
def MakeTensorShapeProto(shape): """Create a TensorShapeProto. Args: shape: List of integers representing the dimensions of the tensor. Returns: A TensorShapeProto. """ return tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=x) for x in shape])
def add_text(self, tag, text, step): """Log a text.""" pluginData = tf.SummaryMetadata.PluginData(plugin_name='text') smd = tf.SummaryMetadata(plugin_data=pluginData) tensor = tensor_pb2.TensorProto(dtype='DT_STRING', string_val=[text.encode(encoding='utf_8')], tensor_shape=tensor_shape_pb2.TensorShapeProto(dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)])) summary = tf.Summary(value=[tf.Summary.Value(tag=tag, metadata=smd, tensor=tensor)]) self._add_summary(summary, step)
def make_tensor_proto(img): tensor_shape = list(img.shape) dims = [ tensor_shape_pb2.TensorShapeProto.Dim(size=dim) for dim in tensor_shape ] tensor_shape = tensor_shape_pb2.TensorShapeProto(dim=dims) tensor = tensor_pb2.TensorProto( dtype=types_pb2.DT_FLOAT, tensor_shape=tensor_shape, float_val=list(img.reshape(-1)), ) return tensor
def testLocateTensorElementAnnotationsUnavailable(self): tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DataType.Value("DT_FLOAT"), tensor_shape=tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)])) out = tensor_format.format_tensor( debug_data.InconvertibleTensorProto(tensor_proto, False), "a") self.assertEqual(["Tensor \"a\":", "", "Uninitialized tensor:"], out.lines[:3]) with self.assertRaisesRegexp( AttributeError, "tensor_metadata is not available in annotations"): tensor_format.locate_tensor_element(out, [0])
def make_tensor_proto(data): # replace tf.make_tensor_proto(data, shape=data.shape) to optimize client request shape = data.shape dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=i) for i in shape] proto_shape= tensor_shape_pb2.TensorShapeProto(dim=dims) proto_dtype = dtypes_as_dtype(data.dtype) tensor_proto = tensor_pb2.TensorProto( dtype=proto_dtype, tensor_shape=proto_shape) tensor_proto.tensor_content = data.tostring() return tensor_proto
def test_build_standardized_signature_def_classification2(self): """Tests multiple output tensors that include classes and probabilities.""" input_tensors = { "input-1": array_ops.placeholder(dtypes.string, 1, name="input-tensor-1") } output_tensors = { "classes": array_ops.placeholder(dtypes.string, 1, name="output-tensor-classes"), # Will be used for CLASSIFY_OUTPUT_SCORES. "probabilities": array_ops.placeholder(dtypes.float32, 1, name="output-tensor-proba"), "logits": array_ops.placeholder(dtypes.float32, 1, name="output-tensor-logits-unused"), } problem_type = constants.ProblemType.CLASSIFICATION actual_signature_def = ( saved_model_export_utils.build_standardized_signature_def( input_tensors, output_tensors, problem_type)) expected_signature_def = meta_graph_pb2.SignatureDef() shape = tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]) dtype_float = types_pb2.DataType.Value("DT_FLOAT") dtype_string = types_pb2.DataType.Value("DT_STRING") expected_signature_def.inputs[ signature_constants.CLASSIFY_INPUTS].CopyFrom( meta_graph_pb2.TensorInfo(name="input-tensor-1:0", dtype=dtype_string, tensor_shape=shape)) expected_signature_def.outputs[ signature_constants.CLASSIFY_OUTPUT_CLASSES].CopyFrom( meta_graph_pb2.TensorInfo(name="output-tensor-classes:0", dtype=dtype_string, tensor_shape=shape)) expected_signature_def.outputs[ signature_constants.CLASSIFY_OUTPUT_SCORES].CopyFrom( meta_graph_pb2.TensorInfo(name="output-tensor-proba:0", dtype=dtype_float, tensor_shape=shape)) expected_signature_def.method_name = ( signature_constants.CLASSIFY_METHOD_NAME) self.assertEqual(actual_signature_def, expected_signature_def)
def convert_variable_to_constant(self, incoming_edge, tensor_data): super(_While, self).convert_variable_to_constant(incoming_edge, tensor_data) node = self.converted_self() node.node.attr["output_shapes"].list.shape[ incoming_edge.destination.index].CopyFrom( tensor_shape_pb2.TensorShapeProto(dim=[ tensor_shape_pb2.TensorShapeProto.Dim(size=dim) for dim in tensor_data.numpy.shape ])) # The while's body inputs and outputs have the same type, so here we can go # ahead and change that function's output type. body_name = self._node.attr["body"].func.name body = self._enclosing_graph.functions[body_name].converted_self().function body.signature.output_arg[ incoming_edge.destination.index].type = tensor_data.dtype
def test_build_standardized_signature_def_classification5(self): """Tests multiple output tensors that include integer classes and scores. Integer classes are dropped out, because Servo classification can only serve string classes. So, only scores are present in the signature. """ input_tensors = { "input-1": array_ops.placeholder(dtypes.string, 1, name="input-tensor-1") } output_tensors = { "classes": array_ops.placeholder(dtypes.int64, 1, name="output-tensor-classes"), "scores": array_ops.placeholder(dtypes.float32, 1, name="output-tensor-scores"), "logits": array_ops.placeholder(dtypes.float32, 1, name="output-tensor-logits-unused"), } problem_type = constants.ProblemType.CLASSIFICATION actual_signature_def = ( saved_model_export_utils.build_standardized_signature_def( input_tensors, output_tensors, problem_type)) expected_signature_def = meta_graph_pb2.SignatureDef() shape = tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]) dtype_float = types_pb2.DataType.Value("DT_FLOAT") dtype_string = types_pb2.DataType.Value("DT_STRING") expected_signature_def.inputs[ signature_constants.CLASSIFY_INPUTS].CopyFrom( meta_graph_pb2.TensorInfo(name="input-tensor-1:0", dtype=dtype_string, tensor_shape=shape)) expected_signature_def.outputs[ signature_constants.CLASSIFY_OUTPUT_SCORES].CopyFrom( meta_graph_pb2.TensorInfo(name="output-tensor-scores:0", dtype=dtype_float, tensor_shape=shape)) expected_signature_def.method_name = ( signature_constants.CLASSIFY_METHOD_NAME) self.assertEqual(actual_signature_def, expected_signature_def)
def test_build_standardized_signature_def_classification6(self): """Tests multiple output tensors that with integer classes and no scores. Servo classification cannot serve integer classes, but no scores are available. So, we fall back to predict signature. """ input_tensors = { "input-1": array_ops.placeholder(dtypes.string, 1, name="input-tensor-1") } output_tensors = { "classes": array_ops.placeholder(dtypes.int64, 1, name="output-tensor-classes"), "logits": array_ops.placeholder(dtypes.float32, 1, name="output-tensor-logits"), } problem_type = constants.ProblemType.CLASSIFICATION actual_signature_def = ( saved_model_export_utils.build_standardized_signature_def( input_tensors, output_tensors, problem_type)) expected_signature_def = meta_graph_pb2.SignatureDef() shape = tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]) dtype_int64 = types_pb2.DataType.Value("DT_INT64") dtype_float = types_pb2.DataType.Value("DT_FLOAT") dtype_string = types_pb2.DataType.Value("DT_STRING") expected_signature_def.inputs["input-1"].CopyFrom( meta_graph_pb2.TensorInfo(name="input-tensor-1:0", dtype=dtype_string, tensor_shape=shape)) expected_signature_def.outputs["classes"].CopyFrom( meta_graph_pb2.TensorInfo(name="output-tensor-classes:0", dtype=dtype_int64, tensor_shape=shape)) expected_signature_def.outputs["logits"].CopyFrom( meta_graph_pb2.TensorInfo(name="output-tensor-logits:0", dtype=dtype_float, tensor_shape=shape)) expected_signature_def.method_name = ( signature_constants.PREDICT_METHOD_NAME) self.assertEqual(actual_signature_def, expected_signature_def)