Exemplo n.º 1
0
    def make_request(model_name,
                     inputs: Iterable[Union[np.ndarray, torch.Tensor]],
                     meta=None):
        inputs = list(inputs)
        example = inputs[0]
        if meta is None:
            meta = dict()

        if isinstance(example, np.ndarray):
            to_byte = bytes
            torch_flag = False
        elif isinstance(example, torch.Tensor):
            to_byte = compose(bytes, torch.Tensor.numpy)
            torch_flag = True
        else:
            raise ValueError(
                'Argument `image` is expected to be an iterative numpy array, or an iterative torch Tensor'
            )

        raw_input = list(map(to_byte, inputs))
        shape = example.shape
        dtype = type_to_data_type(example.dtype).value
        meta = json_update(
            {
                'shape': shape,
                'dtype': dtype,
                'torch_flag': torch_flag
            }, meta)

        return InferRequest(model_name=model_name,
                            raw_input=raw_input,
                            meta=json.dumps(meta))
Exemplo n.º 2
0
 def infer(self, input_batch):
     example = input_batch[0]
     meta = dict()
     raw_input = list(map(bytes, input_batch))
     shape = example.shape
     dtype = type_to_data_type(example.dtype).value
     meta = json_update({'shape': shape, 'dtype': dtype, 'torch_flag': True}, meta)
     self.stub.Infer(InferRequest(model_name='resnet50', raw_input=raw_input, meta=json.dumps(meta)))