From dffe04ad62335db5396bf5509e402c7e6cd7438d Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sun, 29 Dec 2024 17:50:58 +0100 Subject: [PATCH] Add type annotations to inputs and prepare_inputs method This commit adds explicit type annotations for the `inputs` dictionary and the return value of the `prepare_inputs` method in `model_runner.py`. These changes improve code readability and ensure type consistency, enhancing maintainability and reducing potential errors. --- selfdrive/modeld/runners/model_runner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selfdrive/modeld/runners/model_runner.py b/selfdrive/modeld/runners/model_runner.py index 53da7cfd57..5a30390e48 100644 --- a/selfdrive/modeld/runners/model_runner.py +++ b/selfdrive/modeld/runners/model_runner.py @@ -31,7 +31,7 @@ class ModelRunner(ABC): self.model_metadata = pickle.load(f) self.input_shapes = self.model_metadata['input_shapes'] self.output_slices = self.model_metadata['output_slices'] - self.inputs = {} + self.inputs: dict[str, np.ndarray | Tensor] = {} @abstractmethod def prepare_inputs(self, imgs_cl: dict[str, CLMem], numpy_inputs: dict[str, np.ndarray]) -> dict[str, np.ndarray]: @@ -58,7 +58,7 @@ class TinygradRunner(ModelRunner): with open(MODEL_PKL_PATH, "rb") as f: self.model_run = pickle.load(f) - def prepare_inputs(self, imgs_cl: dict[str, CLMem], numpy_inputs: dict[str, np.ndarray]) -> dict[str, np.ndarray]: + def prepare_inputs(self, imgs_cl: dict[str, CLMem], numpy_inputs: dict[str, np.ndarray]) -> dict[str, Tensor]: # Initialize image tensors if not already done for key in imgs_cl: if key not in self.inputs: