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

Improve get_area() for polygons through Shoelace formula #1507

Merged
merged 4 commits into from
May 28, 2024

Conversation

wonjuleee
Copy link
Contributor

@wonjuleee wonjuleee commented May 28, 2024

Summary

image

about 25 times faster computation compared to previous RLE mask based area computation

How to test

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

@wonjuleee wonjuleee requested review from a team as code owners May 28, 2024 05:22
@wonjuleee wonjuleee requested review from jihyeonyi and removed request for a team May 28, 2024 05:22
Copy link

codecov bot commented May 28, 2024

Codecov Report

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

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

Files Patch % Lines
src/datumaro/components/annotation.py 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##             releases/1.7.0    #1507   +/-   ##
=================================================
  Coverage                  ?   80.77%           
=================================================
  Files                     ?      275           
  Lines                     ?    31514           
  Branches                  ?     6358           
=================================================
  Hits                      ?    25456           
  Misses                    ?     4644           
  Partials                  ?     1414           
Flag Coverage Δ
ubuntu-20.04_Python-3.10 80.76% <84.61%> (?)
windows-2022_Python-3.10 80.75% <84.61%> (?)

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.

@wonjuleee wonjuleee requested a review from vinnamkim May 28, 2024 06:00
@@ -812,11 +812,12 @@ def __attrs_post_init__(self):
)

def get_area(self):
import pycocotools.mask as mask_utils
# import pycocotools.mask as mask_utils
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
# import pycocotools.mask as mask_utils

Comment on lines +817 to +819
# x, y, w, h = self.get_bbox()
# rle = mask_utils.frPyObjects([self.points], y + h, x + w)
# area = mask_utils.area(rle)[0]
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
# x, y, w, h = self.get_bbox()
# rle = mask_utils.frPyObjects([self.points], y + h, x + w)
# area = mask_utils.area(rle)[0]

@@ -842,6 +843,21 @@ def __eq__(self, other):
inter_area = self_polygon.intersection(other_polygon).area
return abs(self_polygon.area - inter_area) < CHECK_POLYGON_EQ_EPSILONE

def _get_shoelace_area(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

@sooahleex
If you are still interested in Rust, porting this Python function into Rust would be a good starting point.

Copy link
Contributor

@vinnamkim vinnamkim left a comment

Choose a reason for hiding this comment

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

LGTM.

@wonjuleee wonjuleee merged commit 294c0e5 into openvinotoolkit:releases/1.7.0 May 28, 2024
8 checks passed
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