perf: avoid compact mask materialization in polygon annotator#2369
Open
Borda wants to merge 3 commits into
Open
perf: avoid compact mask materialization in polygon annotator#2369Borda wants to merge 3 commits into
Borda wants to merge 3 commits into
Conversation
Use CompactMask crops for polygon extraction and offset crop-local contours back into image coordinates. Add a regression test covering tight crops, disconnected contours, empty masks, dense parity, and no integer CompactMask indexing. Co-authored-by: Codex <codex@openai.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2369 +/- ##
=======================================
Coverage 83% 83%
=======================================
Files 69 69
Lines 9616 9624 +8
=======================================
+ Hits 7941 7949 +8
Misses 1675 1675 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves PolygonAnnotator performance and correctness for CompactMask by avoiding full-frame mask materialization: it now decodes per-detection crops and applies the stored crop offset before drawing polygons, keeping output consistent with dense-mask behavior.
Changes:
- Updated
PolygonAnnotator.annotate()to useCompactMask.crop()and addCompactMask.offsets[detection_idx]to polygon coordinates before drawing. - Added a regression test ensuring compact-mask annotation avoids integer indexing into
CompactMaskand matches dense-mask output exactly.
Assessment (n/5):
- Code quality: 5/5
- Testing: 5/5
- Documentation: 5/5
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/supervision/annotators/core.py | Uses CompactMask.crop() + offsetting to draw polygons without dense mask indexing/materialization. |
| tests/annotators/test_core.py | Adds coverage asserting compact-mask path uses crops (not __getitem__ int indexing) and matches dense output. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances the handling and testing of compact mask annotations in the
PolygonAnnotator. The main change is ensuring that when aCompactMaskis used, the annotation logic utilizes cropped masks and applies the correct offset, instead of relying on dense mask indexing. Additionally, a new test verifies this behavior and ensures compatibility between dense and compact masks.Improvements to mask annotation logic:
annotateincore.pyto detect when aCompactMaskis used, apply the appropriate crop for each detection, and add the offset to polygons before drawing. This ensures annotations are correctly positioned for compact masks. [1] [2]Testing and validation:
test_compact_mask_uses_crops_and_matches_dense_maskto verify that the annotator usesCompactMask.crop(not dense mask indexing) and that the output matches the dense mask annotation. The test also ensures that using integer indexing onCompactMaskraises an error, enforcing the correct usage pattern.