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

Open Images: add segmentation mask support #388

Merged
merged 7 commits into from
Jul 30, 2021
Merged

Open Images: add segmentation mask support #388

merged 7 commits into from
Jul 30, 2021

Conversation

IRDonch
Copy link

@IRDonch IRDonch commented Jul 27, 2021

Summary

Yet another step to implementing #274.

How to test

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT


from datumaro.cli.util import make_file_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think importing from cli is good here. Probably, this function is better be moved to the core utils (and it is done in the versioning PR).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough. I'll probably steal your move patch (unless you want to submit it as a separate PR).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch stolen. 🙂

datumaro/plugins/open_images_format.py Outdated Show resolved Hide resolved

if box is not None:
if item.has_image and item.image.size is not None:
image_meta[item.id] = (height, width) = item.image.size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discourage using multiple assignment pattern.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, for the same reason we don't write lines like do_one(); do_another(); x = foo(); y = bar();. This make the code clearer and reduces load on the reader.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not quite the same thing, because it reduces duplication. But eh, I can change it if you want.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

if all(mask_description[f] for f in [
'BoxXMin' ,'BoxXMax', 'BoxYMin', 'BoxYMax',
]):
box = attributes['box'] = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to include it as an attribute? Can these values be distinct from what is in the mask? If possible, let's stick to simple type attributes.
If you want to have a bbox attached to a mask, the current approach is to have it as another annotation in the list with the same group as the corresponding mask and no label. It complicates processing a bit, though, check COCO converter or https://github.com/openvinotoolkit/datumaro/blob/develop/datumaro/util/annotation_util.py#L15. I'd vote for exclusion of this information completely, because it can be computed without great overhead, and masks have such method.

Copy link
Author

@IRDonch IRDonch Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to include it as an attribute? Can these values be distinct from what is in the mask?

To quote the Open Images website:

"Note that this is not the bounding box of the mask, but the starting box from which the mask was annotated. These coordinates can be used to relate the mask data with the boxes data."

If you want to have a bbox attached to a mask, the current approach is to have it as another annotation in the list with the same group as the corresponding mask and no label.

Okay, that seems quite doable. I can assign a distinct group to every box annotation and then find the matching box annotation for every mask annotation when loading them.

I could, of course, just not load this information at all, but according to the dataset description, it's not something that just can be computed, so it seems useful to have.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that seems quite doable. I can assign a distinct group to every box annotation and then find the matching box annotation for every mask annotation when loading them.

Implemented this.

box_id = mask_description['BoxID']
if _RE_INVALID_PATH_COMPONENT.fullmatch(box_id):
raise UnsupportedBoxIdError(item_id=item.id, box_id=box_id)
attributes['box_id'] = box_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these ids should be mask ids?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're called box IDs in the dataset; I don't think we need to rename them. 🤷

Mask(label=0, image=np.eye(8)),
Mask(label=1, image=np.ones((8, 8)), group=1, attributes={
'box_id': '00000000',
'box': {'x': 2, 'y': 3, 'w': 6, 'h': 1},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'box': {'x': 2, 'y': 3, 'w': 6, 'h': 1},

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

Roman Donchenko added 2 commits July 30, 2021 13:12
@zhiltsov-max zhiltsov-max merged commit 6a2022e into openvinotoolkit:develop Jul 30, 2021
@IRDonch IRDonch deleted the open-images-masks branch August 4, 2021 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants