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

Enhance DatasetItem annotations for semantic segmentation model training use case #1503

Conversation

vinnamkim
Copy link
Contributor

@vinnamkim vinnamkim commented May 21, 2024

Summary

  • Ticket no. 141410
  • Datumaro has been maintaining every mask as a binary mask representation. This is because of flexibility on manipulating dataset level management (e.g., label remapping). However, this design can bring performance degradation in case of model training use case. For example, semantic segmentation model training uses 2d mask filled in an integer value for each pixel. However, during importing a dataset, Datumaro should convert it to a collection of binary masks. It makes impossible to use the integer mask directly, so that it requires a 2d complexity computation cost to merge the imported binary masks into an integer mask.
  • To resolve this performance degradation, this PR introduces a new interface on dataset_item.annotations by introducing Annotation(list[Annotation]) class. This class extends the pure Python list to equip more utility functions. At the same time, the utility function we introduce this time is dataset_item.annotations.get_semantic_seg_mask(). This function bypasses binary mask conversion to construct an integer mask used for semantic segmentation model training.

How to test

  • Added unit tests to cover this change (mainly in tests/unit/test_annotation.py).
  • This is a performance test on the semantic segmentation model training use case. Throughput improvement on getting a semantic segmentation mask is ~3x (31.38 it/s -> 99.31 it/s).
    image

Checklist

  • I have added unit tests to cover my changes.​
  • I have added integration tests to cover my changes.​
  • I have added the description of my changes into CHANGELOG.​
  • I have updated the documentation accordingly

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) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT

Signed-off-by: Kim, Vinnam <[email protected]>
@vinnamkim vinnamkim requested review from a team as code owners May 21, 2024 05:00
@vinnamkim vinnamkim requested review from sooahleex and removed request for a team May 21, 2024 05:00
@vinnamkim vinnamkim changed the title Enhance DatasetItem annotations for training use case Enhance DatasetItem annotations for semantic segmentation model training use case May 21, 2024
Signed-off-by: Kim, Vinnam <[email protected]>
Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 79.31034% with 6 lines in your changes are missing coverage. Please review.

Please upload report for BASE (releases/1.7.0@3501e97). Learn more about missing BASE report.

Files Patch % Lines
src/datumaro/components/annotation.py 76.92% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##             releases/1.7.0    #1503   +/-   ##
=================================================
  Coverage                  ?   80.78%           
=================================================
  Files                     ?      276           
  Lines                     ?    31511           
  Branches                  ?     6356           
=================================================
  Hits                      ?    25456           
  Misses                    ?     4643           
  Partials                  ?     1412           
Flag Coverage Δ
ubuntu-20.04_Python-3.10 80.77% <79.31%> (?)
windows-2022_Python-3.10 80.75% <79.31%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Kim, Vinnam <[email protected]>
@@ -157,7 +157,7 @@ def _load_items(self, path):
attributes[attr] = bbox_list[i]
i += 1

annotations.append(
items[item_id].annotations.append(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only Widerface is affected by this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this line, annotations: List is created


Then, this annotations is used to construct DatasetItem here
items[item_id] = DatasetItem(
id=item_id,
subset=self._subset,
media=Image.from_file(path=image_path),
annotations=annotations,
)

However, in the following lines, Bbox is pushed into annotations, not items[item_id].annotations,
annotations.append(
Bbox(
float(bbox_list[0]),
float(bbox_list[1]),
float(bbox_list[2]),
float(bbox_list[3]),
attributes=attributes,
label=label,
)
)

Previously, it should work because id(annotations) == id(items[item_id].annotations) (same Python object). However, after this PR change,

annotations: List
items[item_id].annotations: Annotations
=>
id(annotations) != id(items[item_id].annotations)

, so that widerface.py#L160-L169 above will be not working.

@vinnamkim vinnamkim merged commit 232eea5 into openvinotoolkit:releases/1.7.0 May 22, 2024
8 checks passed
@vinnamkim vinnamkim deleted the enhance-ditem-annotations-for-training-usecase branch May 22, 2024 01:24
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