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] Fix image merging #1301

Merged
merged 2 commits into from
Mar 24, 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
3 changes: 2 additions & 1 deletion datumaro/datumaro/cli/contexts/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def import_command(args):
env = Environment()
log.info("Importing project from '%s'" % args.source)

extra_args = {}
if not args.format:
if args.extra_args:
raise CliException("Extra args can not be used without format")
Expand Down Expand Up @@ -210,7 +211,7 @@ def import_command(args):
log.info("Importing project as '%s'" % args.format)

source = osp.abspath(args.source)
project = importer(source, **locals().get('extra_args', {}))
project = importer(source, **extra_args)
project.config.project_name = project_name
project.config.project_dir = project_dir

Expand Down
25 changes: 13 additions & 12 deletions datumaro/datumaro/components/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ def _lazy_image(item):

@classmethod
def _merge_items(cls, existing_item, current_item, path=None):
return existing_item.wrap(path=path,
image=cls._merge_images(existing_item, current_item),
annotations=cls._merge_anno(
existing_item.annotations, current_item.annotations))

@staticmethod
def _merge_images(existing_item, current_item):
image = None
if existing_item.has_image and current_item.has_image:
if existing_item.image.has_data:
Expand All @@ -433,9 +440,7 @@ def _merge_items(cls, existing_item, current_item, path=None):
else:
image = current_item.image

return existing_item.wrap(path=path,
image=image, annotations=cls._merge_anno(
existing_item.annotations, current_item.annotations))
return image

@staticmethod
def _merge_anno(a, b):
Expand Down Expand Up @@ -527,15 +532,11 @@ def __init__(self, project):
if own_source is not None:
log.debug("Loading own dataset...")
for item in own_source:
if not item.has_image:
existing_item = subsets[item.subset].items.get(item.id)
if existing_item is not None:
image = None
if existing_item.has_image:
# TODO: think of image comparison
image = self._lazy_image(existing_item)
item = item.wrap(path=None,
annotations=item.annotations, image=image)
existing_item = subsets[item.subset].items.get(item.id)
if existing_item is not None:
item = item.wrap(path=None,
image=self._merge_images(existing_item, item),
annotations=item.annotations)

subsets[item.subset].items[item.id] = item

Expand Down