In [11]:
!pip install tensorflow-serving-api
In [1]:
import tensorflow as tf
In [2]:
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('/tmp/tensorflow/alex/mnist/input_data', one_hot=True)
In [4]:
from grpc.beta import implementations
from tensorflow_serving.apis import prediction_service_pb2
channel = implementations.insecure_channel('10.8.58.87', 8500)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
In [13]:
from grpc.beta import implementations
from tensorflow_serving.apis import prediction_service_pb2
channel = implementations.insecure_channel('10.8.58.87', 8500)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
In [ ]:
channel = implementations.insecure_channel('10.8.58.87', 8500)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
for _ in range(num_tests):
request = predict_pb2.PredictRequest()
request.model_spec.name = 'mnist'
request.model_spec.signature_name = 'predict_images'
image, label = mnist.test.next_batch(1)
request.inputs['images'].CopyFrom(tf.contrib.util.make_tensor_proto(image[0], shape=[1, image[0].size]))
result_counter.throttle()
result_future = stub.Predict.future(request, 5.0) # 5 seconds
result_future.add_done_callback(_create_rpc_callback(label[0], result_counter))
return result_counter.get_error_rate()