Skip to content

Commit

Permalink
Add recursive importers (#1290)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max authored Mar 20, 2020
1 parent 1408443 commit 8efaf58
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
9 changes: 3 additions & 6 deletions datumaro/datumaro/plugins/coco_format/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from datumaro.components.extractor import Importer
from datumaro.util.log_utils import logging_disabled

from .format import CocoTask, CocoPath
from .format import CocoTask


class CocoImporter(Importer):
Expand Down Expand Up @@ -55,11 +55,8 @@ def find_subsets(path):
if path.endswith('.json') and osp.isfile(path):
subset_paths = [path]
else:
subset_paths = glob(osp.join(path, '*_*.json'))

if osp.basename(osp.normpath(path)) != CocoPath.ANNOTATIONS_DIR:
path = osp.join(path, CocoPath.ANNOTATIONS_DIR)
subset_paths += glob(osp.join(path, '*_*.json'))
subset_paths = glob(osp.join(path, '**', '*_*.json'),
recursive=True)

subsets = defaultdict(dict)
for subset_path in subset_paths:
Expand Down
8 changes: 1 addition & 7 deletions datumaro/datumaro/plugins/cvat_format/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

from datumaro.components.extractor import Importer

from .format import CvatPath


class CvatImporter(Importer):
EXTRACTOR_NAME = 'cvat'
Expand Down Expand Up @@ -49,9 +47,5 @@ def find_subsets(path):
if path.endswith('.xml') and osp.isfile(path):
subset_paths = [path]
else:
subset_paths = glob(osp.join(path, '*.xml'))

if osp.basename(osp.normpath(path)) != CvatPath.ANNOTATIONS_DIR:
path = osp.join(path, CvatPath.ANNOTATIONS_DIR)
subset_paths += glob(osp.join(path, '*.xml'))
subset_paths = glob(osp.join(path, '**', '*.xml'), recursive=True)
return subset_paths
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ def find_subsets(path):
if path.endswith('.tfrecord') and osp.isfile(path):
subset_paths = [path]
else:
subset_paths = glob(osp.join(path, '*.tfrecord'))
subset_paths = glob(osp.join(path, '**', '*.tfrecord'),
recursive=True)
return subset_paths
2 changes: 1 addition & 1 deletion datumaro/datumaro/plugins/yolo_format/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def find_configs(path):
if path.endswith('.data') and osp.isfile(path):
config_paths = [path]
else:
config_paths = glob(osp.join(path, '*.data'))
config_paths = glob(osp.join(path, '**', '*.data'), recursive=True)
return config_paths

0 comments on commit 8efaf58

Please sign in to comment.