Skip to content

Commit

Permalink
Typing improvements & better error message (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWilkie committed May 21, 2024
1 parent 9e19407 commit 979aebb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion darwin/dataset/local_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
29 changes: 22 additions & 7 deletions darwin/dataset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
"""
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 979aebb

Please sign in to comment.