tensorflow_serving/example/mnist_client.py
def do_inference(hostport, work_dir, concurrency, num_tests):
  """Tests PredictionService with concurrent requests.

  Args:
    hostport: Host:port address of the PredictionService.
    work_dir: The full path of working directory for test data set.
    concurrency: Maximum number of concurrent requests.
    num_tests: Number of test images to use.

  Returns:
    The classification error rate.

  Raises:
    IOError: An error occurred processing test data set.
  """
  test_data_set = mnist_input_data.read_data_sets(work_dir).test
  channel = grpc.insecure_channel(hostport)
  stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
  result_counter = _ResultCounter(num_tests, concurrency)
  for _ in range(num_tests):
    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'mnist'
    request.model_spec.signature_name = 'predict_images'
    image, label = test_data_set.next_batch(1)
    request.inputs['images'].CopyFrom(
        tf.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()
Tests PredictionService with concurrent requests.

  Args:
    hostport: Host:port address of the PredictionService.
    work_dir: The full path of working directory for test data set.
    concurrency: Maximum number of concurrent requests.
    num_tests: Number of test images to use.

  Returns:
    The classification error rate.

  Raises:
    IOError: An error occurred processing test data set.
  
Tests PredictionService with concurrent requests.
Tests PredictionService with concurrent requests .
def do_inference(hostport, work_dir, concurrency, num_tests):
  test_data_set = mnist_input_data.read_data_sets(work_dir).test
  channel = grpc.insecure_channel(hostport)
  stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
  result_counter = _ResultCounter(num_tests, concurrency)
  for _ in range(num_tests):
    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'mnist'
    request.model_spec.signature_name = 'predict_images'
    image, label = test_data_set.next_batch(1)
    request.inputs['images'].CopyFrom(
        tf.make_tensor_proto(image[0], shape=[1, image[0].size]))
    result_counter.throttle()
    result_future = stub.Predict.future(request, 5.0)  
    result_future.add_done_callback(
        _create_rpc_callback(label[0], result_counter))
  return result_counter.get_error_rate()
def do_inference ( hostport , work_dir , concurrency , num_tests ) : test_data_set = mnist_input_data . read_data_sets ( work_dir ) . test channel = grpc . insecure_channel ( hostport ) stub = prediction_service_pb2_grpc . PredictionServiceStub ( channel ) result_counter = _ResultCounter ( num_tests , concurrency ) for _ in range ( num_tests ) : request = predict_pb2 . PredictRequest ( ) request . model_spec . name = 'mnist' request . model_spec . signature_name = 'predict_images' image , label = test_data_set . next_batch ( 1 ) request . inputs [ 'images' ] . CopyFrom ( tf . make_tensor_proto ( image [ 0 ] , shape = [ 1 , image [ 0 ] . size ] ) ) result_counter . throttle ( ) result_future = stub . Predict . future ( request , 5.0 ) result_future . add_done_callback ( _create_rpc_callback ( label [ 0 ] , result_counter ) ) return result_counter . get_error_rate ( )
Tests PredictionService with concurrent requests.
Tests PredictionService with concurrent requests .
"""Tests PredictionService with concurrent requests.

  Args:
    hostport: Host:port address of the PredictionService.
    work_dir: The full path of working directory for test data set.
    concurrency: Maximum number of concurrent requests.
    num_tests: Number of test images to use.

  Returns:
    The classification error rate.

  Raises:
    IOError: An error occurred processing test data set.
  """ # 5 seconds
The classification error rate.
The classification error rate .
An error occurred processing test data set.
An error occurred processing test data set .
IOError
hostport
port address of the PredictionService.
port address of the PredictionService .
work_dir
The full path of working directory for test data set.
The full path of working directory for test data set .
concurrency
Maximum number of concurrent requests.
Maximum number of concurrent requests .
num_tests
Number of test images to use.
Number of test images to use .