Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Datumaro] fixes #1137

Merged
merged 6 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datumaro/datumaro/cli/contexts/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def import_command(args):
extra_args = {}
try:
env = Environment()
importer = env.importers.get(args.format)
importer = env.make_importer(args.format)
if hasattr(importer, 'from_cmdline'):
extra_args = importer.from_cmdline(args.extra_args)
except KeyError:
Expand Down
1 change: 1 addition & 0 deletions datumaro/datumaro/components/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ def _save_branch_project(self, extractor, save_dir=None):
dst_project = Project(Config(self.config))
dst_project.config.remove('project_dir')
dst_project.config.remove('sources')
dst_project.config.project_name = osp.basename(save_dir)

dst_dataset = dst_project.make_dataset()
dst_dataset.define_categories(extractor.categories())
Expand Down
15 changes: 10 additions & 5 deletions datumaro/datumaro/plugins/coco_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,20 +609,25 @@ def __call__(self, extractor, save_dir):

class CocoInstancesConverter(CocoConverter):
def __init__(self, **kwargs):
super().__init__(CocoTask.instances, **kwargs)
kwargs['tasks'] = CocoTask.instances
super().__init__(**kwargs)

class CocoImageInfoConverter(CocoConverter):
def __init__(self, **kwargs):
super().__init__(CocoTask.image_info, **kwargs)
kwargs['tasks'] = CocoTask.image_info
super().__init__(**kwargs)

class CocoPersonKeypointsConverter(CocoConverter):
def __init__(self, **kwargs):
super().__init__(CocoTask.person_keypoints, **kwargs)
kwargs['tasks'] = CocoTask.person_keypoints
super().__init__(**kwargs)

class CocoCaptionsConverter(CocoConverter):
def __init__(self, **kwargs):
super().__init__(CocoTask.captions, **kwargs)
kwargs['tasks'] = CocoTask.captions
super().__init__(**kwargs)

class CocoLabelsConverter(CocoConverter):
def __init__(self, **kwargs):
super().__init__(CocoTask.labels, **kwargs)
kwargs['tasks'] = CocoTask.labels
super().__init__(**kwargs)
26 changes: 18 additions & 8 deletions datumaro/datumaro/plugins/cvat_format/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ def __init__(self, path):
super().__init__()

assert osp.isfile(path)
rootpath = path.rsplit(CvatPath.ANNOTATIONS_DIR, maxsplit=1)[0]
self._path = rootpath
rootpath = ''
if path.endswith(osp.join(CvatPath.ANNOTATIONS_DIR, osp.basename(path))):
rootpath = path.rsplit(CvatPath.ANNOTATIONS_DIR, maxsplit=1)[0]
images_dir = ''
if rootpath and osp.isdir(osp.join(rootpath, CvatPath.IMAGES_DIR)):
images_dir = osp.join(rootpath, CvatPath.IMAGES_DIR)
self._images_dir = images_dir
self._path = path

subset = osp.splitext(osp.basename(path))[0]
if subset == DEFAULT_SUBSET_NAME:
Expand Down Expand Up @@ -275,19 +281,23 @@ def _load_items(self, parsed):
file_name = item_desc.get('name')
if not file_name:
file_name = item_id
file_name += CvatPath.IMAGE_EXT
image = self._find_image(file_name)

parsed[item_id] = DatasetItem(id=item_id, subset=self._subset,
image=image, annotations=item_desc.get('annotations', None))
return parsed

def _find_image(self, file_name):
images_dir = osp.join(self._path, CvatPath.IMAGES_DIR)
search_paths = [
osp.join(images_dir, file_name),
osp.join(images_dir, self._subset or DEFAULT_SUBSET_NAME, file_name),
osp.join(osp.dirname(self._path), file_name)
]
if self._images_dir:
search_paths += [
osp.join(self._images_dir, file_name),
osp.join(self._images_dir, self._subset or DEFAULT_SUBSET_NAME,
file_name),
]
for image_path in search_paths:
if osp.exists(image_path):
return lazy_image(image_path)
if osp.isfile(image_path):
return lazy_image(image_path)
return None
15 changes: 10 additions & 5 deletions datumaro/datumaro/plugins/voc_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,20 +548,25 @@ def __call__(self, extractor, save_dir):

class VocClassificationConverter(VocConverter):
def __init__(self, **kwargs):
super().__init__(VocTask.classification, **kwargs)
kwargs['tasks'] = VocTask.classification
super().__init__(**kwargs)

class VocDetectionConverter(VocConverter):
def __init__(self, **kwargs):
super().__init__(VocTask.detection, **kwargs)
kwargs['tasks'] = VocTask.detection
super().__init__(**kwargs)

class VocLayoutConverter(VocConverter):
def __init__(self, **kwargs):
super().__init__(VocTask.person_layout, **kwargs)
kwargs['tasks'] = VocTask.person_layout
super().__init__(**kwargs)

class VocActionConverter(VocConverter):
def __init__(self, **kwargs):
super().__init__(VocTask.action_classification, **kwargs)
kwargs['tasks'] = VocTask.action_classification
super().__init__(**kwargs)

class VocSegmentationConverter(VocConverter):
def __init__(self, **kwargs):
super().__init__(VocTask.segmentation, **kwargs)
kwargs['tasks'] = VocTask.segmentation
super().__init__(**kwargs)
4 changes: 2 additions & 2 deletions datumaro/datumaro/plugins/voc_format/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def parse_label_map(path):
assert len(color) == 3, \
"Label '%s' has wrong color, expected 'r,g,b', got '%s'" % \
(name, color)
color = tuple([int(c) for c in color][::-1])
color = tuple([int(c) for c in color])
else:
color = None

Expand All @@ -164,7 +164,7 @@ def write_label_map(path, label_map):
f.write('# label:color_rgb:parts:actions\n')
for label_name, label_desc in label_map.items():
if label_desc[0]:
color_rgb = ','.join(str(c) for c in label_desc[0][::-1])
color_rgb = ','.join(str(c) for c in label_desc[0])
else:
color_rgb = ''

Expand Down