From fbcf145b5f3c4300f1b4349ec11f431a0e4c1aa0 Mon Sep 17 00:00:00 2001 From: Giuseppe Ambrosio Date: Fri, 3 Jan 2025 17:19:47 +0100 Subject: [PATCH] refactor(runtime): remove unused image processing functions to streamline codebase --- focoos/runtime.py | 56 ----------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/focoos/runtime.py b/focoos/runtime.py index c067bed..8233324 100644 --- a/focoos/runtime.py +++ b/focoos/runtime.py @@ -7,9 +7,6 @@ for image preprocessing, postprocessing, and interfacing with the ONNXRuntime library. Functions: - preprocess_image: Preprocesses an image for model input. - postprocess_image: Postprocesses the output image from the model. - image_to_byte_array: Converts a PIL image to a byte array. det_postprocess: Postprocesses detection model outputs into sv.Detections. semseg_postprocess: Postprocesses semantic segmentation model outputs into sv.Detections. get_runtime: Returns an ONNXRuntime instance configured for the given runtime type. @@ -18,7 +15,6 @@ ONNXRuntime: A class that interfaces with ONNX Runtime for model inference. """ -import io from pathlib import Path from time import perf_counter from typing import Tuple @@ -41,58 +37,6 @@ GPU_ID = 0 -def preprocess_image(bytes, dtype=np.float32) -> Tuple[np.ndarray, Image.Image]: - """ - Preprocesses the input image (in bytes) for inference by converting it to a numpy array. - - Args: - bytes (bytes): Image data in bytes format (e.g., JPEG, PNG). - dtype (np.dtype, optional): The data type to cast the image array to. Defaults to np.float32. - - Returns: - Tuple[np.ndarray, Image.Image]: A tuple containing the processed image as a numpy array - and the original PIL image. - """ - pil_img = Image.open(io.BytesIO(bytes)) - img_numpy = np.ascontiguousarray( - np.array(pil_img).transpose(2, 0, 1)[np.newaxis, :] # HWC->CHW - ).astype(dtype) - return img_numpy, pil_img - - -def postprocess_image( - cmapped_image: np.ndarray, input_image: Image.Image -) -> Image.Image: - """ - Postprocesses the output of an inference to blend the results with the original image. - - Args: - cmapped_image (np.ndarray): The processed image, typically with segmentation or detection results. - input_image (Image.Image): The original input image. - - Returns: - Image.Image: The blended image showing the result of postprocessing. - """ - out = Image.fromarray(cmapped_image) - return Image.blend(input_image, out, 0.6) - - -def image_to_byte_array(image: Image.Image) -> bytes: - """ - Converts a PIL Image into a byte array. - - Args: - image (Image.Image): The input image to be converted. - - Returns: - bytes: The byte array representing the image. - """ - img_byte_arr = io.BytesIO() - image.save(img_byte_arr, format="JPEG") - img_byte_arr = img_byte_arr.getvalue() - return img_byte_arr - - def det_postprocess( out: np.ndarray, im0_shape: Tuple[int, int], conf_threshold: float ) -> sv.Detections: