Repository navigation
Conversation
Changes: - `Detections.from_semantic_segmentation` takes `split_components` (default `False`) and passes it to `process_semantic_segmentation`, whose docstrings describe the option - New helper `_split_class_regions` labels each class with `cv2.connectedComponentsWithStats(..., connectivity=8)` and returns one box and mask per patch, sorted by the top-left corner of its box - `process_semantic_segmentation` loops over those regions, so each patch gets its own mask, box and mean confidence, and the class name is built per entry after the loop - Tests in `TestDetectionsFromSemanticSegmentation` cover patch boxes, mask partition, diagonal joining, default behaviour, names, confidence, compact masks, kept background and a background-only map - Changelog entry under Unreleased Impact: - A class made of separate patches, such as water in flood imagery, can load as one detection per patch, so boxes and areas no longer span the land between patches - Default `split_components=False` returns the same entries as before, one per class id Limitations: - Connectivity is fixed at 8 and there is no minimum-area filter for small patches - The changelog entry has no pull request link yet --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> 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 #3032 +/- ##
=======================================
Coverage 95% 95%
=======================================
Files 84 84
Lines 15408 15421 +13
=======================================
+ Hits 14677 14690 +13
Misses 731 731 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Compact component splitting retains a full-image boolean mask for every component before encoding, creating temporary allocations that can exhaust memory even when compact output is requested.
1 open issue
What changed in this PR
Adds optional connected-component splitting to Supervision’s semantic-segmentation loader, preserving the default of one detection per class.
Changes:
- Adds
split_components=Trueto produce one detection per 8-connected patch. - Computes per-patch boxes, masks and confidence scores, with aligned class names and deterministic ordering.
- Adds regression tests and an Unreleased changelog entry.
| File | Description |
|---|---|
tests/detection/test_core.py |
Covers patch splitting, metadata, compact masks, defaults and background handling. |
src/supervision/detection/utils/internal.py |
Extracts connected regions and assembles aligned per-patch detection data. |
src/supervision/detection/core.py |
Exposes, documents and forwards the new option. |
docs/changelog.md |
Announces component splitting and its unchanged default behavior. |
Review effort: Balanced
| for label in range(1, count): | ||
| left, top, width, height = (int(value) for value in stats[label, :4]) | ||
| box = [left, top, left + width - 1, top + height - 1] | ||
| regions.append((box, labels == label)) |
split_components to semantic maps
Changes: - _split_class_regions is now a generator that sorts patch labels by their box corner first, then builds each patch's full-size mask only when it is requested, filling it from the patch's own box - A regression test measures peak traced memory of a compact split of 300 patches on a 1500 by 1500 map and requires it to stay under a third of what 300 dense masks need Impact: - A compact split no longer keeps a full-size boolean mask for every patch before encoding, so peak memory stays near one mask plus the label image - Patch order, boxes, masks and confidence are unchanged, as the existing split tests still pass --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Changes: - The split_components changelog entry ends with a link to its pull request Impact: - The entry meets the changelog rule that a functional change links its pull request --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
This branch has not been deployed
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.

Changes:
Detections.from_semantic_segmentationtakessplit_components(defaultFalse) and passes it toprocess_semantic_segmentation, whose docstrings describe the option_split_class_regionslabels each class withcv2.connectedComponentsWithStats(..., connectivity=8)and returns one box and mask per patch, sorted by the top-left corner of its boxprocess_semantic_segmentationloops over those regions, so each patch gets its own mask, box and mean confidence, and the class name is built per entry after the loopTestDetectionsFromSemanticSegmentationcover patch boxes, mask partition, diagonal joining, default behaviour, names, confidence, compact masks, kept background and a background-only mapImpact:
split_components=Falsereturns the same entries as before, one per class idLimitations: