Repository navigation
fix(compact_mask): Match dense nearest-neighbor resizing - #2697
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2697 +/- ##
=======================================
Coverage 93% 93%
=======================================
Files 81 81
Lines 12228 12238 +10
=======================================
+ Hits 11349 11360 +11
+ Misses 879 878 -1 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The native OpenCV backend rejects the new int32 coordinate grids, breaking non-identity resizing.
1 open finding
What changed in this PR
Fixes CompactMask.resize to match full-image nearest-neighbor sampling.
Changes:
- Uses full-image sampling maps for sparse and dense crops.
- Adds exact pixel-parity regression tests.
- Updates documentation and changelog.
Assessment: Code quality 3/5; testing 4/5; documentation 5/5.
| File | Description |
|---|---|
src/supervision/detection/compact_mask.py |
Implements full-image-grid resizing. |
tests/detection/test_compact_mask.py |
Adds exact parity coverage. |
docs/changelog.md |
Documents the correction. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
The links-check job failed because the existing changelog link to #1502 returned HTTP 500. That link is already present on Could a maintainer rerun the failed link check? GitHub requires repository admin rights for the rerun. |
Changes: - Generate missing _rle_resize row and column maps through the active backend. - Add row and column sampling-boundary regressions and tests preserving a supplied map when the other map is generated. - Correct sampling docstrings and the exact-parity test description; update the PR roboflow#2697 changelog entry. Impact: - Direct RLE resizing matches backend INTER_NEAREST rounding, including the seed-28 case that failed in CI. - Caller-supplied sampling maps remain intact, and sparse resizing avoids decoding a full crop. Verification: - CompactMask unit and integration tests: 356 passed with OpenCV 5.0.0.93 and 356 passed with the NumPy fallback. - uv run --no-sync pytest -p no:xdist --cov=supervision -q with OpenCV 5.0.0.93: 5262 passed, 1 skipped; 92% coverage. - uv run --no-sync pre-commit run --all-files: all hooks passed, including ruff and mypy. - git diff --check: passed. Residual limits: - Verification used macOS/Python 3.12.15; the Linux/Python 3.13.16 CI environment has not been rerun. - The full suite reported 1 skipped test and 39 warnings. --- Co-authored-by: Codex <[email protected]>
…d-agnostic imports Updates to use `resize` and `INTER_NEAREST` directly from `supervision._cv2`, improving readability and consistency.
Brings in #2691 and #2692 (DepthClipRange) as merged, with the maintainer's edits. Adaptations: - changelog: loaders bullet (#2694) sits above the new #2692 and #2697 bullets. - visualize_depth.md front matter: description covers loading and colouring over images and video. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changes: - Integrate target updates for DepthMap loaders and measurement, keypoint mAP, compact-mask resizing, and mAP support with their exports, docs, and tests. - Resolve the changelog collision by preserving the PR mAR entry and target PR roboflow#2694, roboflow#2693, roboflow#2692, and roboflow#2697 entries; update date_modified. Impact: - The PR branch includes the fetched develop changes before report-item work, so follow-up validation runs against integrated code. - The changelog keeps both sets of release notes without dropping target or PR intent. Verification: - git diff --check passed after resolution. - Changelog assertions confirmed the PR and target entries and no conflict markers. - git diff --name-only --diff-filter=U returned no paths. Residual limits: - The full project gate bundle remains before remediation closure. - No source-specific regression tests have run after integration. --- Co-authored-by: Codex <[email protected]>

Description
I fixed
CompactMask.resizelosing foreground pixels and disagreeing with dense nearest-neighbor resizing. A singleton in a 10x10 image stays one pixel after resizing to 100x100 instead of becoming a 10x10 block. A full foreground image grows to only 91x91. Downscaling also keeps crops that the output grid never samples.Motivation and Context
Scaling inclusive crop endpoints shortens enlarged crops. Resampling each crop independently also uses a different sampling origin and ratio from resizing the full image. I use dense
cv2.resize(..., INTER_NEAREST)as the reference.Changes Made
max(abs(diff)) <= 1assertion could not detect a mismatch.Testing
Confirmed pristine source: all 30 regression cases fail for pixel mismatches.
py -3.13 -m pytest tests/detection/test_compact_mask.py -q: 337 passed.py -3.13 -m pytest -p pytest_cov --cov=supervision -q: 5,110 passed, 6 skipped, 40 warnings; total coverage 93%. Pristinedevelophas 5,090 passes and the same skips/warnings.Repository pre-commit hooks and whitespace checks pass.
Identity, empty, all-False, aligned full-foreground downsampling, repeated calls, and source immutability pass on both base and patch.
900 random masks per backend match dense resizing, using native OpenCV and the NumPy resize implementation at the compatibility facade.
Added/updated tests, and the full suite passes locally
Updated docs (docstrings / mkdocs entry) for new or changed public API
Added a changelog entry in
docs/changelog.mdunderUnreleased(skip for lint/type/format-only or pure doc changes)Additional Notes
I kept processing cropped masks because decoding the full mask collection would lose its memory advantage. The sampling arrays add memory: for eight dense 128x160 masks resized to 96x120, traced peak allocation grows from about 750 KiB to 919 KiB. This is a correctness fix, with no memory or speedup claim.
Linux/macOS and a fresh environment without OpenCV remain untested locally. The explicit NumPy resize check above does not replace that environment's full suite.
AI assistance disclosure: AI-assisted development tools were used during investigation and implementation. The reported tests were run against the final diff.