Skip to content

Commit

Permalink
more type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlov721 committed Jan 6, 2025
1 parent aef54f6 commit afbb69a
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 18 deletions.
5 changes: 2 additions & 3 deletions luxonis_ml/data/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
)
)
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/classification_directory_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/coco_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/create_ml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/darknet_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion luxonis_ml/data/parsers/luxonis_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/native_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 44 in luxonis_ml/data/parsers/native_parser.py

View check run for this annotation

Codecov / codecov/patch

luxonis_ml/data/parsers/native_parser.py#L44

Added line #L44 was not covered by tests
image_dir=dataset_dir / "train",
annotation_dir=dataset_dir / "train",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions luxonis_ml/data/parsers/solo_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/tensorflow_csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/voc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/yolov4_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion luxonis_ml/data/parsers/yolov6_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit afbb69a

Please sign in to comment.