fix: close out remaining review findings - #2418
Merged
Merged
Conversation
Re-verify remaining supervision review backlog against develop HEAD; most items were already resolved by an intervening commit, only genuinely-open gaps got new fixes. Fix float32 precision loss in box_iou_batch for large coordinates (GeoTIFF-scale) by accumulating in float64. Raise ValueError instead of a strippable assert in EvaluationDataset.load_predictions for unknown image ids. Add HeatMapAnnotator.reset() to clear accumulated heat for annotator reuse. Add missing coverage: labelme export basename collisions, _greedy_match matcher, metrics.core ABC/enum contracts, metrics.utils.utils pandas guard; remove a global RNG-seed pollution site in a metrics test. Document the last two undocumented public exports (calculate_masks_centroids, is_compressed_rle) and add usage examples to 17 previously-example-less public functions/classes (NMS/NMM helpers, draw utils, PolygonZoneAnnotator, mask/polygon converters). --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2418 +/- ##
=======================================
Coverage 87% 87%
=======================================
Files 71 71
Lines 10446 10458 +12
=======================================
+ Hits 9048 9071 +23
+ Misses 1398 1387 -11 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request tightens up several API behaviors in supervision while improving user-facing documentation and examples, with a focus on metrics/annotators usability and numerical stability in overlap computations.
Changes:
- Added
HeatMapAnnotator.reset()to explicitly clear accumulated heat for reuse across independent streams. - Improved
box_iou_batchnumerical robustness for large coordinate magnitudes by using higher-precision intermediates and added a regression test. - Expanded docstrings, docs pages, and changelog entries; added/updated tests for metrics utilities and dataset export validation.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/metrics/utils/test_utils.py | Adds coverage for the pandas “metrics extra” guard (ensure_pandas_installed). |
| tests/metrics/utils/test_matching.py | Adds unit tests for greedy one-to-one IoU matching behavior. |
| tests/metrics/test_mean_average_recall.py | Switches to default_rng for deterministic, local RNG use in integration test. |
| tests/metrics/test_mean_average_precision.py | Adds validation test for EvaluationDataset.load_predictions unknown image IDs. |
| tests/metrics/test_core.py | Adds tests for Metric ABC behavior and shared enums. |
| tests/detection/utils/test_iou_and_nms.py | Adds regression test for box_iou_batch precision above float32’s integer-exact limit. |
| tests/detection/test_compact_mask.py | Improves parametrization IDs and adds/clarifies test docstrings for CompactMask behaviors. |
| tests/dataset/formats/test_labelme.py | Adds test to ensure LabelMe export rejects basename/stem collisions. |
| tests/annotators/test_core.py | Adds test verifying HeatMapAnnotator.reset() clears accumulated heat. |
| src/supervision/utils/conversion.py | Adds docstring usage examples for Pillow↔OpenCV conversion helpers. |
| src/supervision/metrics/mean_average_precision.py | Replaces an assert with a ValueError for invalid prediction image IDs (robust under python -O). |
| src/supervision/draw/utils.py | Adds usage examples to core drawing utilities. |
| src/supervision/detection/utils/polygons.py | Adds docstring example for polygon area filtering. |
| src/supervision/detection/utils/masks.py | Adds docstring examples for centroid calculation and ROI extraction. |
| src/supervision/detection/utils/iou_and_nms.py | Uses float64 intermediates for large-coordinate IoU computations; adds multiple docstring examples. |
| src/supervision/detection/utils/converters.py | Adds docstring examples for box/polygon/mask conversion helpers. |
| src/supervision/detection/tools/polygon_zone.py | Adds a docstring example for PolygonZoneAnnotator. |
| src/supervision/dataset/formats/coco.py | Adds a docstring example for COCO class index mapping helper. |
| src/supervision/annotators/utils.py | Adds docstring examples for hex/RGBA conversion and validation helpers. |
| src/supervision/annotators/core.py | Adds HeatMapAnnotator.reset() to clear accumulated heat mask. |
| docs/detection/utils/masks.md | Adds docs entry for calculate_masks_centroids. |
| docs/detection/utils/converters.md | Adds docs entry for is_compressed_rle. |
| docs/changelog.md | Documents the new/reset behavior, precision fix, and the updated validation behavior. |
kounelisagis
reviewed
Jul 8, 2026
kounelisagis
left a comment
Contributor
There was a problem hiding this comment.
Left a couple of notes inline, nothing blocking.
[resolve group] PR #2418 — items 4, 10 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve group] PR #2418 — items 1, 5, 9, 11 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
[resolve group] PR #2418 — items 2, 3, 6 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
[resolve group] PR #2418 — items 7, 8 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
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 introduces several improvements and fixes across the codebase, focusing on enhancing documentation, improving API usability, and increasing numerical precision for large-scale image processing. The main highlights are the addition of usage examples to many public functions, a new
reset()method for theHeatMapAnnotator, and improved precision in thebox_iou_batchfunction for handling large coordinate values.API Improvements and Fixes:
sv.HeatMapAnnotatornow includes areset()method to clear accumulated heat, allowing the same annotator instance to be reused across independent streams without carrying over state.sv.box_iou_batchnow performs area and intersection calculations infloat64before returningfloat32, preserving precision for very large coordinates (such as those found in GeoTIFF images). [1] [2]sv.MeanAveragePrecisionnow raises aValueErrorif predictions reference image IDs not present in the ground-truth COCO set, rather than relying on anassertthat could be skipped in optimized Python mode.Documentation Enhancements:
hex_to_rgba,rgba_to_hex,is_valid_hex), COCO utilities, mask and polygon conversion functions, NMS utilities, and drawing functions. These examples make it easier for users to understand and adopt the API. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19]Changelog Updates:
docs/changelog.md) has been updated to reflect the new features, bug fixes, and deprecation warnings, ensuring users are informed about the latest changes and migration notes.Documentation Structure:
is_compressed_rleandcalculate_masks_centroidshave been added, improving discoverability of these utilities. [1] [2]These changes collectively improve the reliability, usability, and user-friendliness of the codebase.