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

faster sv.MaskAnnotator #426

Merged
merged 5 commits into from
Oct 6, 2023
Merged

Conversation

kapter
Copy link

@kapter kapter commented Oct 5, 2023

Description

This PR is related to #417
I've made some enhancements to sv.MaskAnnotator.

  1. calc bgr color once for color mask creation
  2. replace np.where with cv2.add operation for scene with hole and colored object

Result

speed up two times

@CLAassistant
Copy link

CLAassistant commented Oct 5, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap.

@@ -95,6 +95,7 @@ def __init__(
color: Union[Color, ColorPalette] = ColorPalette.default(),
opacity: float = 0.5,
color_map: str = "class",
ver: str = "v1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove that extra argument.

@SkalskiP SkalskiP self-requested a review October 6, 2023 08:25
@SkalskiP SkalskiP added enhancement New feature or request version: 0.16.0 Feature to be added in `0.16.0` release api:annotator Annotators hacktoberfest Open for contributions during the annual Hacktoberfest event, aimed at encouraging open-source parti labels Oct 6, 2023
@SkalskiP SkalskiP linked an issue Oct 6, 2023 that may be closed by this pull request
@SkalskiP
Copy link
Collaborator

SkalskiP commented Oct 6, 2023

Hi @kapter 👋🏻, I've been busy making tests of this change. Here is what I got:

  1. Consistency of obtained results
  • develop

    download - 2023-10-06T180358 646

  • kapter:Make-MaskAnnotator-faster

    download - 2023-10-06T180405 617

  1. Drawing speed

Annotation speed depends on external factors - other processes running on the machine and varies between test runs. To validate the results, I performed 4 tests with the code in the current develop and 4 with the code from kapter:Make-MaskAnnotator-faster. I averaged the results.

  • develop

    baseline (only inference) inference + box annotation inference + mask annotation
    108 sec 127 sec 451 sec
    103 sec 108 sec 465 sec
    129 sec 114 sec 475 sec
    128 sec 127 sec 476 sec
    117 sec (average) 119 sec (average) 467 sec (average)

    Annotation overhead: 467 - 117 = 350
    Per frame annotation overhead: 350 / 341 = 1.03
    Google Colab - link

  • kapter:Make-MaskAnnotator-faster

    baseline (only inference) inference + box annotation inference + mask annotation
    104 sec 103 sec 279 sec
    99 sec 98 sec 296 sec
    96 sec 104 sec 281 sec
    102 sec 104 sec 266 sec
    100 sec (average) 102 sec (average) 280 sec (average)

    Annotation overhead: 280 - 100 = 180
    Per frame annotation overhead: 180 / 341 = 0.52
    Google Colab - link

  1. Summary:
  • Results are consistent - no visual difference
  • Updated MaskAnnotator is 0.5 s per frame faster

@SkalskiP
Copy link
Collaborator

SkalskiP commented Oct 6, 2023

@kapter I'm curious if we can make it even faster. 🤔 💭 0.5 sec per frame is 2x faster than the current implementation, but it is still 0.5 sec. It is far from real-time annotation.

Having said that, I'm merging this PR. It is a clear improvement.

Maybe we could somehow sacrifice the quality of annotation to get a speed boost.

@SkalskiP SkalskiP merged commit 456655c into roboflow:develop Oct 6, 2023
6 checks passed
@onuralpszr onuralpszr mentioned this pull request Oct 6, 2023
3 tasks
@onuralpszr onuralpszr added the hacktoberfest-accepted Contribute to the notion of open-source this October! label Oct 6, 2023
@kapter
Copy link
Author

kapter commented Oct 9, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:annotator Annotators enhancement New feature or request hacktoberfest Open for contributions during the annual Hacktoberfest event, aimed at encouraging open-source parti hacktoberfest-accepted Contribute to the notion of open-source this October! version: 0.16.0 Feature to be added in `0.16.0` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sv.MaskAnnotator faster! 🏎️💨
4 participants