diff --git a/luxonis_ml/data/parsers/base_parser.py b/luxonis_ml/data/parsers/base_parser.py index 5ee0b0b7..37bbd04e 100644 --- a/luxonis_ml/data/parsers/base_parser.py +++ b/luxonis_ml/data/parsers/base_parser.py @@ -5,7 +5,6 @@ from luxonis_ml.data import BaseDataset, DatasetIterator from luxonis_ml.enums.enums import DatasetType -from luxonis_ml.typing import PathType ParserOutput = Tuple[DatasetIterator, Dict[str, Dict], List[Path]] """Type alias for parser output. @@ -151,7 +150,7 @@ def parse_dir(self, dataset_dir: Path, **kwargs) -> BaseDataset: return self.dataset @staticmethod - def _get_added_images(generator: DatasetIterator) -> List[PathType]: + def _get_added_images(generator: DatasetIterator) -> List[Path]: """Returns list of unique images added by the generator function. @@ -162,7 +161,7 @@ def _get_added_images(generator: DatasetIterator) -> List[PathType]: """ return list( set( - item["file"] if isinstance(item, dict) else item.file + Path(item["file"] if isinstance(item, dict) else item.file) for item in generator ) ) diff --git a/luxonis_ml/data/parsers/classification_directory_parser.py b/luxonis_ml/data/parsers/classification_directory_parser.py index d8ec8ae9..0c622d65 100644 --- a/luxonis_ml/data/parsers/classification_directory_parser.py +++ b/luxonis_ml/data/parsers/classification_directory_parser.py @@ -55,7 +55,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: added_train_imgs = self._parse_split(class_dir=dataset_dir / "train") added_val_imgs = self._parse_split(class_dir=dataset_dir / "valid") added_test_imgs = self._parse_split(class_dir=dataset_dir / "test") diff --git a/luxonis_ml/data/parsers/coco_parser.py b/luxonis_ml/data/parsers/coco_parser.py index 65cc0be6..427944c2 100644 --- a/luxonis_ml/data/parsers/coco_parser.py +++ b/luxonis_ml/data/parsers/coco_parser.py @@ -106,7 +106,7 @@ def from_dir( use_keypoint_ann: bool = False, keypoint_ann_paths: Optional[Dict[str, str]] = None, split_val_to_test: bool = True, - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: dir_format, splits = COCOParser._detect_dataset_dir_format(dataset_dir) if dir_format is None: raise ValueError("Dataset is not in any expected format.") diff --git a/luxonis_ml/data/parsers/create_ml_parser.py b/luxonis_ml/data/parsers/create_ml_parser.py index de5c23ec..89a0d183 100644 --- a/luxonis_ml/data/parsers/create_ml_parser.py +++ b/luxonis_ml/data/parsers/create_ml_parser.py @@ -50,7 +50,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: added_train_imgs = self._parse_split( image_dir=dataset_dir / "train", annotation_path=dataset_dir diff --git a/luxonis_ml/data/parsers/darknet_parser.py b/luxonis_ml/data/parsers/darknet_parser.py index cef31c69..e3a7e213 100644 --- a/luxonis_ml/data/parsers/darknet_parser.py +++ b/luxonis_ml/data/parsers/darknet_parser.py @@ -49,7 +49,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: added_train_imgs = self._parse_split( image_dir=dataset_dir / "train", classes_path=dataset_dir / "train" / "_darknet.labels", diff --git a/luxonis_ml/data/parsers/luxonis_parser.py b/luxonis_ml/data/parsers/luxonis_parser.py index 13c1ecf3..ef8560a8 100644 --- a/luxonis_ml/data/parsers/luxonis_parser.py +++ b/luxonis_ml/data/parsers/luxonis_parser.py @@ -144,7 +144,8 @@ def __init__( dataset_name = dataset_name or name.replace(" ", "_").split(".")[0] self.dataset = self.dataset_constructor( - dataset_name=dataset_name, **kwargs + dataset_name=dataset_name, # type: ignore + **kwargs, ) self.parser = self.parsers[self.dataset_type]( self.dataset, self.dataset_type, task_name diff --git a/luxonis_ml/data/parsers/native_parser.py b/luxonis_ml/data/parsers/native_parser.py index 090d26da..b000c168 100644 --- a/luxonis_ml/data/parsers/native_parser.py +++ b/luxonis_ml/data/parsers/native_parser.py @@ -40,7 +40,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: added_train_imgs = self._parse_split( image_dir=dataset_dir / "train", annotation_dir=dataset_dir / "train", diff --git a/luxonis_ml/data/parsers/segmentation_mask_directory_parser.py b/luxonis_ml/data/parsers/segmentation_mask_directory_parser.py index e1f60361..dd6537fc 100644 --- a/luxonis_ml/data/parsers/segmentation_mask_directory_parser.py +++ b/luxonis_ml/data/parsers/segmentation_mask_directory_parser.py @@ -60,7 +60,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: added_train_imgs = self._parse_split( image_dir=dataset_dir / "train", seg_dir=dataset_dir / "train", diff --git a/luxonis_ml/data/parsers/solo_parser.py b/luxonis_ml/data/parsers/solo_parser.py index 318314ef..281b2c4b 100644 --- a/luxonis_ml/data/parsers/solo_parser.py +++ b/luxonis_ml/data/parsers/solo_parser.py @@ -87,12 +87,12 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: """Parses all present data to L{LuxonisDataset} format. @type dataset_dir: str @param dataset_dir: Path to source dataset directory. - @rtype: Tuple[List[str], List[str], List[str]] + @rtype: Tuple[List[Path], List[Path], List[Path]] @return: Tuple with added images for train, valid and test splits. """ @@ -138,7 +138,7 @@ def from_split(self, split_path: Path) -> ParserOutput: ) # TODO: We make an assumption here that bbox class_names are also valid for all other annotation types in the dataset. Is this OK? # TODO: Can we imagine a case where classes between annotation types are different? Which class names to return in this case? - if class_names == []: + if not class_names: raise Exception("No class_names identified. ") keypoint_labels = self._get_solo_keypoint_names( @@ -256,7 +256,7 @@ def generator() -> DatasetIterator: added_images = self._get_added_images(generator()) - return generator(), class_names, skeletons, added_images + return generator(), skeletons, added_images def _get_solo_annotation_types( self, annotation_definitions_dict: dict diff --git a/luxonis_ml/data/parsers/tensorflow_csv_parser.py b/luxonis_ml/data/parsers/tensorflow_csv_parser.py index eb25ab23..0dc979d1 100644 --- a/luxonis_ml/data/parsers/tensorflow_csv_parser.py +++ b/luxonis_ml/data/parsers/tensorflow_csv_parser.py @@ -50,7 +50,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: added_train_imgs = self._parse_split( image_dir=dataset_dir / "train", annotation_path=dataset_dir / "train" / "_annotations.csv", diff --git a/luxonis_ml/data/parsers/voc_parser.py b/luxonis_ml/data/parsers/voc_parser.py index 48799ed6..24c2dc57 100644 --- a/luxonis_ml/data/parsers/voc_parser.py +++ b/luxonis_ml/data/parsers/voc_parser.py @@ -47,7 +47,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: added_train_imgs = self._parse_split( image_dir=dataset_dir / "train", annotation_dir=dataset_dir / "train", diff --git a/luxonis_ml/data/parsers/yolov4_parser.py b/luxonis_ml/data/parsers/yolov4_parser.py index 7a19448d..a19bdc59 100644 --- a/luxonis_ml/data/parsers/yolov4_parser.py +++ b/luxonis_ml/data/parsers/yolov4_parser.py @@ -51,7 +51,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[List[str], List[str], List[str]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: added_train_imgs = self._parse_split( image_dir=dataset_dir / "train", annotation_path=dataset_dir / "train" / "_annotations.txt", diff --git a/luxonis_ml/data/parsers/yolov6_parser.py b/luxonis_ml/data/parsers/yolov6_parser.py index f15a0493..6f56bb70 100644 --- a/luxonis_ml/data/parsers/yolov6_parser.py +++ b/luxonis_ml/data/parsers/yolov6_parser.py @@ -68,7 +68,7 @@ def validate(dataset_dir: Path) -> bool: def from_dir( self, dataset_dir: Path - ) -> Tuple[Optional[List[str]], Optional[List[str]], Optional[List[str]]]: + ) -> Tuple[List[Path], List[Path], List[Path]]: classes_path = dataset_dir / "data.yaml" added_train_imgs = self._parse_split( image_dir=dataset_dir / "images" / "train",