Ejemplo n.º 1
0
 def __init__(self, url, verbose=False):
     super(CustomInferenceServerClient, self).__init__(url, verbose=False)
     channel_opt = [('grpc.max_send_message_length', 10 * 3 * 1024 * 1024),
                    ('grpc.max_receive_message_length', 5 * 1024 * 1024)]
     self._channel = grpc.insecure_channel(url, options=channel_opt)
     self._client_stub = grpc_service_pb2_grpc.GRPCInferenceServiceStub(
         self._channel)
     self._verbose = verbose
     self._stream = None
Ejemplo n.º 2
0
    def test_grpc(self):
        channel = grpc.insecure_channel("localhost:8001")
        grpc_stub = grpc_service_pb2_grpc.GRPCInferenceServiceStub(channel)

        # Send request with invalid output name
        for trial in _trials:
            model_name = "{}_nobatch_zero_1_float32".format(trial)
            request = self.requestGenerator(model_name, "DUMMY")
            try:
                response = grpc_stub.ModelInfer(request)
                self.assertTrue(
                    False,
                    "unexpected success for unknown output " + model_name)
            except grpc.RpcError as rpc_error:
                msg = rpc_error.details()
                self.assertTrue(
                    msg.startswith(
                        "unexpected inference output 'DUMMY' for model"))
        default='localhost:8001',
        help='Inference server URL. Default is localhost:8001.')

    FLAGS = parser.parse_args()

    # We use a simple model that takes 2 input tensors of 16 integers
    # each and returns 2 output tensors of 16 integers each. One
    # output tensor is the element-wise sum of the inputs and one
    # output is the element-wise difference.
    model_name = "simple_string"
    model_version = ""
    batch_size = 1

    # Create gRPC stub for communicating with the server
    channel = grpc.insecure_channel(FLAGS.url)
    grpc_stub = grpc_service_pb2_grpc.GRPCInferenceServiceStub(channel)

    # Generate the request
    request = grpc_service_pb2.ModelInferRequest()
    request.model_name = model_name
    request.model_version = model_version

    # Populate the inputs in inference request
    input0 = grpc_service_pb2.ModelInferRequest().InferInputTensor()
    input0.name = "INPUT0"
    input0.datatype = "BYTES"
    input0.shape.extend([1, 16])
    for i in range(16):
        input0.contents.byte_contents.append(('{}'.format(i)).encode('utf-8'))

    input1 = grpc_service_pb2.ModelInferRequest().InferInputTensor()