import tensorflow as tf from tensorflow_serving.apis import predict_pb2 from tensorflow_serving.apis import prediction_service_pb2_grpc # Create a gRPC channel to connect to the TensorFlow Serving server channel = tf.grpc.insecure_channel('localhost:8500') stub = prediction_service_pb2_grpc.PredictionServiceStub(channel) # Create a request for inference request = predict_pb2.PredictRequest() request.model_spec.name = 'my_model' request.model_spec.signature_name = 'serving_default' request.inputs['input'].CopyFrom(tf.make_tensor_proto(input_data)) # Send the request and get the response response = stub.Predict(request) output_data = tf.make_ndarray(response.outputs['output']) __ __