(
self, file: UploadFile, inference_params: Dict[str, Any]
)
| 34 | |
| 35 | @torch.no_grad() |
| 36 | async def run( |
| 37 | self, file: UploadFile, inference_params: Dict[str, Any] |
| 38 | ) -> Dict[str, Any]: |
| 39 | logger.info("Run SAMImageEncoder.") |
| 40 | image = await file.read() |
| 41 | |
| 42 | # Preprocess |
| 43 | input_image = self.preprocess(image) |
| 44 | |
| 45 | # Prepare for inference. |
| 46 | triton_inputs = [grpcclient.InferInput("INPUT__0", input_image.shape, "FP32")] |
| 47 | triton_inputs[0].set_data_from_numpy(input_image) |
| 48 | triton_outputs = [grpcclient.InferRequestedOutput("OUTPUT__0")] |
| 49 | |
| 50 | # Run the inference. |
| 51 | result = await self.triton_client.infer( |
| 52 | inputs=triton_inputs, |
| 53 | outputs=triton_outputs, |
| 54 | **inference_params, |
| 55 | ) |
| 56 | # image embedding: numpy.ndarray [B, 256, 64, 64] |
| 57 | image_embedding = result.as_numpy("OUTPUT__0") |
| 58 | |
| 59 | # Postprocess |
| 60 | outputs = self.postprocess(image_embedding) |
| 61 | |
| 62 | return outputs |
| 63 | |
| 64 | def preprocess(self, image_byte, target_size=1024) -> torch.Tensor: |
| 65 | """ |
no test coverage detected