From 7d6b781f46ebcf9ded29b77896b31c7e68d04502 Mon Sep 17 00:00:00 2001 From: "Chanwut (Mick) Kittivorawong" Date: Tue, 16 Apr 2024 13:34:15 -0700 Subject: [PATCH] update: fix type --- spatialyze/database.py | 5 +++-- spatialyze/predicate.py | 4 ++-- .../stages/decode_frame/parallel_decode_frame.py | 4 +++- .../video_processor/stages/depth_estimation.py | 2 +- .../stages/detection_2d/ground_truth.py | 12 ++++++------ .../stages/detection_3d/ground_truth.py | 12 ++++++------ spatialyze/video_processor/stages/stage.py | 4 +++- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/spatialyze/database.py b/spatialyze/database.py index add19f0..0c27f3c 100644 --- a/spatialyze/database.py +++ b/spatialyze/database.py @@ -32,8 +32,8 @@ from .video_processor.types import Float33 if TYPE_CHECKING: - from psycopg2 import connection as Connection - from psycopg2 import cursor as Cursor + from psycopg2._psycopg import connection as Connection + from psycopg2._psycopg import cursor as Cursor from .predicate import PredicateNode @@ -313,6 +313,7 @@ def predicate(self, predicate: "PredicateNode", temporal: bool = True): def sql(self, query: str) -> pd.DataFrame: results, cursor = self.execute_and_cursor(query) description = cursor.description + assert description is not None cursor.close() return pd.DataFrame(results, columns=[d.name for d in description]) diff --git a/spatialyze/predicate.py b/spatialyze/predicate.py index d8c68d7..e3e5e79 100644 --- a/spatialyze/predicate.py +++ b/spatialyze/predicate.py @@ -91,11 +91,11 @@ def __or__(self, other): ], ) - def __eq__(self, other): + def __eq__(self, other): # pyright: ignore [reportIncompatibleMethodOverride] other = wrap_literal(other) return CompOpNode(self, "eq", other) - def __ne__(self, other): + def __ne__(self, other): # pyright: ignore [reportIncompatibleMethodOverride] other = wrap_literal(other) return CompOpNode(self, "ne", other) diff --git a/spatialyze/video_processor/stages/decode_frame/parallel_decode_frame.py b/spatialyze/video_processor/stages/decode_frame/parallel_decode_frame.py index 3167a5f..4105d1c 100644 --- a/spatialyze/video_processor/stages/decode_frame/parallel_decode_frame.py +++ b/spatialyze/video_processor/stages/decode_frame/parallel_decode_frame.py @@ -63,4 +63,6 @@ def _r(acc: "tuple[int, list[tuple[int, int]]]", frames: int): return None, {self.classname(): metadata} except BaseException: _, output = DecodeFrame()._run(payload) - return None, {self.classname(): DecodeFrame.get(output)} + images = DecodeFrame.get(output) + assert images is not None + return None, {self.classname(): images} diff --git a/spatialyze/video_processor/stages/depth_estimation.py b/spatialyze/video_processor/stages/depth_estimation.py index 36955a5..8379986 100644 --- a/spatialyze/video_processor/stages/depth_estimation.py +++ b/spatialyze/video_processor/stages/depth_estimation.py @@ -113,7 +113,7 @@ def eval_all(self, input_images: "list[npt.NDArray | None]"): # Load image and preprocess input_image = pil.fromarray(im[:, :, [2, 1, 0]]) original_width, original_height = input_image.size - input_image = input_image.resize((self.feed_width, self.feed_height), pil.LANCZOS) + input_image = input_image.resize((self.feed_width, self.feed_height), pil.Resampling.LANCZOS) input_image = transforms.ToTensor()(input_image).unsqueeze(0) # PREDICTION diff --git a/spatialyze/video_processor/stages/detection_2d/ground_truth.py b/spatialyze/video_processor/stages/detection_2d/ground_truth.py index 08c4e5c..b153eca 100644 --- a/spatialyze/video_processor/stages/detection_2d/ground_truth.py +++ b/spatialyze/video_processor/stages/detection_2d/ground_truth.py @@ -189,7 +189,7 @@ def __init__(self, df_annotations: "pd.DataFrame"): self.class_to_id = {c: i for i, c in enumerate(self.id_to_classes)} def _run(self, payload: "Payload"): - metadata: "list[Metadatum | None]" = [] + metadata: list[Metadatum] = [] dimension = payload.video.dimension for i, cc in enumerate(payload.video._camera_configs): fid = cc.frame_id @@ -222,10 +222,10 @@ def _run(self, payload: "Payload"): if len(tensor) == 0: metadata.append(Metadatum(torch.Tensor([]), yolo_classes, [])) else: - metadata.append( - Metadatum( - torch.Tensor(tensor), yolo_classes, [DetectionId(i, _id) for _id in ids] - ) - ) + metadata.append(Metadatum( + torch.Tensor(tensor), + yolo_classes, + [DetectionId(i, _id) for _id in ids], + )) return None, {self.classname(): metadata} diff --git a/spatialyze/video_processor/stages/detection_3d/ground_truth.py b/spatialyze/video_processor/stages/detection_3d/ground_truth.py index 6918afb..f58770a 100644 --- a/spatialyze/video_processor/stages/detection_3d/ground_truth.py +++ b/spatialyze/video_processor/stages/detection_3d/ground_truth.py @@ -27,7 +27,7 @@ def __init__(self, df_annotations: "pd.DataFrame"): self.class_to_id = {c: i for i, c in enumerate(self.id_to_classes)} def _run(self, payload: "Payload"): - metadata: "list[Metadatum | None]" = [] + metadata: list[Metadatum] = [] dimension = payload.video.dimension for i, cc in enumerate(payload.video._camera_configs): fid = cc.frame_id @@ -79,10 +79,10 @@ def _run(self, payload: "Payload"): if len(tensor) == 0: metadata.append(Metadatum(torch.Tensor([]), yolo_classes, [])) else: - metadata.append( - Metadatum( - torch.Tensor(tensor), yolo_classes, [DetectionId(i, _id) for _id in ids] - ) - ) + metadata.append(Metadatum( + torch.Tensor(tensor), + yolo_classes, + [DetectionId(i, _id) for _id in ids], + )) return None, {self.classname(): metadata} diff --git a/spatialyze/video_processor/stages/stage.py b/spatialyze/video_processor/stages/stage.py index bf93246..0182de5 100644 --- a/spatialyze/video_processor/stages/stage.py +++ b/spatialyze/video_processor/stages/stage.py @@ -90,4 +90,6 @@ def tqdm(cls, iterable: "Iterable[_T2]", *args, **kwargs) -> "Iterable[_T2]": def _get_classnames(cls: "type") -> "list[str]": if cls == Stage: return [] - return [*_get_classnames(cls.__base__), cls.__name__] + base = cls.__base__ + assert base is not None + return [*_get_classnames(base), cls.__name__]