Skip to content

feat: declare annotator mask requirements#2370

Open
Borda wants to merge 3 commits into
developfrom
perf-CMask/4
Open

feat: declare annotator mask requirements#2370
Borda wants to merge 3 commits into
developfrom
perf-CMask/4

Conversation

@Borda

@Borda Borda commented Jun 29, 2026

Copy link
Copy Markdown
Member

This pull request introduces a standardized way for annotator classes to declare whether they require the Detections.mask attribute, which helps integrations avoid unnecessary computation when mask data is not needed. It does this by adding a requires_mask class variable to the base annotator class and setting it appropriately in each annotator. Comprehensive tests are also included to ensure the correct policy is declared by all annotators.

Annotator mask requirement policy:

  • Added a requires_mask class variable to BaseAnnotator to indicate whether an annotator requires Detections.mask. This allows integrations to check mask requirements before materializing mask payloads.
  • Set requires_mask = True for MaskAnnotator, PolygonAnnotator, and HaloAnnotator, indicating these annotators require mask data. [1] [2] [3]
  • Set requires_mask = False for ComparisonAnnotator to explicitly indicate it does not require mask data.

Testing:

  • Added TestAnnotatorMaskPolicy tests to verify that all annotators correctly declare their mask requirement policy via the requires_mask attribute.

Add a BaseAnnotator.requires_mask flag so integrations can avoid materializing masks for mask-optional visualizations.

Mark mask-only annotators as requiring masks and cover mask-required versus mask-optional annotators in tests.

Co-authored-by: Codex <codex@openai.com>
@Borda Borda requested a review from Copilot June 29, 2026 08:01
@Borda Borda requested a review from SkalskiP as a code owner June 29, 2026 08:01
@Borda Borda added the enhancement New feature or request label Jun 29, 2026
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83%. Comparing base (934da12) to head (7ed58d9).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2370   +/-   ##
=======================================
  Coverage       83%     83%           
=======================================
  Files           69      69           
  Lines         9616    9621    +5     
=======================================
+ Hits          7941    7946    +5     
  Misses        1675    1675           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a small piece of annotator “capability metadata” (requires_mask) so integrations can decide whether they need to materialize Detections.mask (often expensive) before running a given annotator.

Changes:

  • Added requires_mask to BaseAnnotator as a standardized policy flag.
  • Set requires_mask = True for mask-dependent annotators (MaskAnnotator, PolygonAnnotator, HaloAnnotator) and requires_mask = False for ComparisonAnnotator.
  • Added tests validating the declared mask policy for a representative set of annotators.

Quality scores (n/5):

  • Code quality: 4/5
  • Testing: 4/5
  • Docs: 4/5

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/supervision/annotators/base.py Introduces the requires_mask policy flag on the base annotator interface.
src/supervision/annotators/core.py Declares requires_mask on mask-dependent annotators (and explicitly False for ComparisonAnnotator).
tests/annotators/test_core.py Adds tests asserting the expected requires_mask policy for key annotators.

Comment on lines +2 to +15
from typing import Any, ClassVar

from supervision.detection.core import Detections


class BaseAnnotator(ABC):
"""Base class for annotators that consume :class:`Detections`.

Attributes:
requires_mask: Whether integrations must provide ``Detections.mask`` for
this annotator. Check this before materializing expensive mask payloads.
"""

requires_mask: ClassVar[bool] = False
Comment on lines +56 to +59
def test_mask_required_annotators_declare_mask_requirement(self, annotator):
"""Annotators that require detections.mask expose the requirement."""
assert annotator.requires_mask is True

Comment on lines +73 to +75
def test_mask_optional_annotators_declare_no_mask_requirement(self, annotator):
"""Mask-optional annotators do not require mask materialization."""
assert annotator.requires_mask is False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants