From 979aebb9f69606e07809cbbc5f310c5925e80ec1 Mon Sep 17 00:00:00 2001 From: John Wilkie <124276291+JBWilkie@users.noreply.github.com> Date: Tue, 21 May 2024 12:39:25 +0100 Subject: [PATCH] Typing improvements & better error message (#845) --- darwin/dataset/local_dataset.py | 2 +- darwin/dataset/utils.py | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/darwin/dataset/local_dataset.py b/darwin/dataset/local_dataset.py index f43cdef83..88fc27e64 100644 --- a/darwin/dataset/local_dataset.py +++ b/darwin/dataset/local_dataset.py @@ -159,7 +159,7 @@ def _setup_annotations_and_images( continue else: raise ValueError( - f"Annotation ({annotation_filepath}) does not have a corresponding image" + f"Annotation ({annotation_filepath}) does not have a corresponding image, looking for image path: {image_path}" ) def _initial_setup(self, dataset_path, release_name): diff --git a/darwin/dataset/utils.py b/darwin/dataset/utils.py index 2a410e827..67d4585e6 100644 --- a/darwin/dataset/utils.py +++ b/darwin/dataset/utils.py @@ -404,7 +404,7 @@ def get_annotations( split_type: Optional[str] = None, annotation_type: str = "polygon", release_name: Optional[str] = None, - annotation_format: Optional[str] = "coco", + annotation_format: str = "coco", ignore_inconsistent_examples: bool = False, ) -> Iterator[Dict[str, Any]]: """ @@ -498,7 +498,9 @@ def get_annotations( ) -def _validate_inputs(partition, split_type, annotation_type): +def _validate_inputs( + partition: Union[str, None], split_type: Union[str, None], annotation_type: str +) -> None: """ Validates the input parameters for partition, split_type, and annotation_type. @@ -520,7 +522,13 @@ def _validate_inputs(partition, split_type, annotation_type): ) -def _get_stems_from_split(release_path, split, split_type, annotation_type, partition): +def _get_stems_from_split( + release_path: Path, + split: str, + split_type: Union[str, None], + annotation_type: str, + partition: Union[str, None], +) -> Generator: """ Determines the file stems based on the dataset split and other parameters. @@ -559,8 +567,11 @@ def _get_stems_from_split(release_path, split, split_type, annotation_type, part def _map_annotations_to_images( - stems, annotations_dir, images_dir, ignore_inconsistent_examples -): + stems: List[str], + annotations_dir: Path, + images_dir: Path, + ignore_inconsistent_examples: bool, +) -> Tuple[List[Path], List[Path], List[Path]]: """ Maps annotations to their corresponding images based on the file stems. @@ -599,8 +610,12 @@ def _map_annotations_to_images( def _load_and_format_annotations( - images_paths, annotations_paths, annotation_format, annotation_type, classes -): + images_paths: List[Path], + annotations_paths: List[Path], + annotation_format: str, + annotation_type: str, + classes: List[str], +) -> Generator: """ Loads and formats annotations based on the specified format and type.