Skip to content

Commit

Permalink
progress reporting on import
Browse files Browse the repository at this point in the history
  • Loading branch information
Eldies committed Jul 26, 2024
1 parent e8812fe commit d577b20
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions datumaro/plugins/yolo_format/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ def __init__(
# called 'classes', 'names' and 'backup'.
subsets = {k: v for k, v in self._config.items() if k not in self.RESERVED_CONFIG_KEYS}

for subset_name, list_path in subsets.items():
pbars = self._ctx.progress_reporter.split(len(subsets))
for (subset_name, list_path), pbar in zip(subsets.items(), pbars):
subset = YoloExtractor.Subset(subset_name, self)
subset.items = OrderedDict(
(self.name_from_path(p), self.localize_path(p))
for p in self._iterate_over_image_paths(subset_name, list_path)
for p in pbar.iter(
self._iterate_over_image_paths(subset_name, list_path),
desc=f"Importing '{subset_name}'",
)
)
subsets[subset_name] = subset

Expand All @@ -125,7 +129,7 @@ def _iterate_over_image_paths(self, subset_name: str, list_path: str):
raise InvalidAnnotationError(f"Can't find '{subset_name}' subset list file")

with open(list_path, "r", encoding="utf-8") as f:
yield from (p for p in f if p.strip())
return [stripped for p in f if (stripped := p.strip())]

@cached_property
def _config(self) -> Dict[str, str]:
Expand Down Expand Up @@ -381,19 +385,19 @@ def _iterate_over_image_paths(
):
if isinstance(subset_images_source, str):
if subset_images_source.endswith(YoloPath.SUBSET_LIST_EXT):
yield from super()._iterate_over_image_paths(subset_name, subset_images_source)
return super()._iterate_over_image_paths(subset_name, subset_images_source)
else:
path = osp.join(self._path, self.localize_path(subset_images_source))
if not osp.isdir(path):
raise InvalidAnnotationError(f"Can't find '{subset_name}' subset image folder")
yield from (
return [
osp.relpath(osp.join(root, file), self._path)
for root, dirs, files in os.walk(path)
for file in files
if osp.isfile(osp.join(root, file))
)
]
else:
yield from subset_images_source
return subset_images_source


class Yolo8SegmentationExtractor(Yolo8Extractor):
Expand Down

0 comments on commit d577b20

Please sign in to comment.