tensorflow_serving/model_servers/test_util/tensorflow_model_server_test_base.py
def VerifyPredictRequest(
      self,
      model_server_address,
      expected_output,
      expected_version,
      model_name='default',
      specify_output=True,
      batch_input=False,
      signature_name=signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY,
      rpc_timeout=RPC_TIMEOUT):
    """Send PredictionService.Predict request and verify output."""
    print('Sending Predict request...')
    # Prepare request
    request = predict_pb2.PredictRequest()
    request.model_spec.name = model_name
    request.model_spec.signature_name = signature_name
    request.inputs['x'].dtype = types_pb2.DT_FLOAT
    request.inputs['x'].float_val.append(2.0)
    dim = request.inputs['x'].tensor_shape.dim.add()
    dim.size = 1
    if batch_input:
      request.inputs['x'].tensor_shape.dim.add().size = 1

    if specify_output:
      request.output_filter.append('y')
    # Send request
    channel = grpc.insecure_channel(model_server_address)
    stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
    result = stub.Predict(request, rpc_timeout)  # 5 secs timeout
    # Verify response
    self.assertTrue('y' in result.outputs)
    self.assertEqual(types_pb2.DT_FLOAT, result.outputs['y'].dtype)
    self.assertEqual(1, len(result.outputs['y'].float_val))
    self.assertEqual(expected_output, result.outputs['y'].float_val[0])
    self._VerifyModelSpec(result.model_spec, request.model_spec.name,
                          signature_name, expected_version)
Send PredictionService.Predict request and verify output.
Send PredictionService.Predict request and verify output.
Send PredictionService . Predict request and verify output .
def VerifyPredictRequest(
      self,
      model_server_address,
      expected_output,
      expected_version,
      model_name='default',
      specify_output=True,
      batch_input=False,
      signature_name=signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY,
      rpc_timeout=RPC_TIMEOUT):
    print('Sending Predict request...')
    request = predict_pb2.PredictRequest()
    request.model_spec.name = model_name
    request.model_spec.signature_name = signature_name
    request.inputs['x'].dtype = types_pb2.DT_FLOAT
    request.inputs['x'].float_val.append(2.0)
    dim = request.inputs['x'].tensor_shape.dim.add()
    dim.size = 1
    if batch_input:
      request.inputs['x'].tensor_shape.dim.add().size = 1
    if specify_output:
      request.output_filter.append('y')
    channel = grpc.insecure_channel(model_server_address)
    stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
    result = stub.Predict(request, rpc_timeout)  
    self.assertTrue('y' in result.outputs)
    self.assertEqual(types_pb2.DT_FLOAT, result.outputs['y'].dtype)
    self.assertEqual(1, len(result.outputs['y'].float_val))
    self.assertEqual(expected_output, result.outputs['y'].float_val[0])
    self._VerifyModelSpec(result.model_spec, request.model_spec.name,
                          signature_name, expected_version)
def VerifyPredictRequest ( self , model_server_address , expected_output , expected_version , model_name = 'default' , specify_output = True , batch_input = False , signature_name = signature_constants . DEFAULT_SERVING_SIGNATURE_DEF_KEY , rpc_timeout = RPC_TIMEOUT ) : print ( 'Sending Predict request...' ) request = predict_pb2 . PredictRequest ( ) request . model_spec . name = model_name request . model_spec . signature_name = signature_name request . inputs [ 'x' ] . dtype = types_pb2 . DT_FLOAT request . inputs [ 'x' ] . float_val . append ( 2.0 ) dim = request . inputs [ 'x' ] . tensor_shape . dim . add ( ) dim . size = 1 if batch_input : request . inputs [ 'x' ] . tensor_shape . dim . add ( ) . size = 1 if specify_output : request . output_filter . append ( 'y' ) channel = grpc . insecure_channel ( model_server_address ) stub = prediction_service_pb2_grpc . PredictionServiceStub ( channel ) result = stub . Predict ( request , rpc_timeout ) self . assertTrue ( 'y' in result . outputs ) self . assertEqual ( types_pb2 . DT_FLOAT , result . outputs [ 'y' ] . dtype ) self . assertEqual ( 1 , len ( result . outputs [ 'y' ] . float_val ) ) self . assertEqual ( expected_output , result . outputs [ 'y' ] . float_val [ 0 ] ) self . _VerifyModelSpec ( result . model_spec , request . model_spec . name , signature_name , expected_version )
Send PredictionService.Predict request and verify output.
Send PredictionService . Predict request and verify output .
"""Send PredictionService.Predict request and verify output.""" # Prepare request # Send request # 5 secs timeout # Verify response
self
model_server_address
expected_output
expected_version
model_name
specify_output
batch_input
signature_name
rpc_timeout