Add out-of-bounds detection warning to InferenceSlicer#2186
Merged
Conversation
2 tasks
…etections bug When a user's callback accidentally runs inference on the full image instead of the provided slice, detections get incorrect offsets applied, causing a repeating grid pattern. Add a validation check in _run_callback that emits a SupervisionWarnings warning when any detection coordinate exceeds the slice dimensions or is negative. An instance flag prevents repeated warnings across many slices. Agent-Logs-Url: https://github.com/roboflow/supervision/sessions/ee0b16e9-1f0a-4237-ac89-05037c075366 Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix repeat detections with InferenceSlicer
Add out-of-bounds detection warning to InferenceSlicer
Mar 30, 2026
…-detections-inferenceslicer
- Wrap _out_of_slice_bounds_warned check-and-set in threading.Lock to prevent duplicate warnings under ThreadPoolExecutor with thread_workers > 1 - Change stacklevel=2 to stacklevel=1 — under executor.submit the stacklevel=2 frame points into concurrent.futures internals, not user code --- Co-authored-by: Claude Code <noreply@anthropic.com>
…ests - Assert exactly 1 warning fires with thread_workers=4 (validates Lock fix) - Assert no warning for detection touching but not exceeding slice boundary (pins > vs >= semantics) - Assert second slicer call does not re-warn (documents once-per-instance semantic) --- Co-authored-by: Claude Code <noreply@anthropic.com>
--- Co-authored-by: Claude Code <noreply@anthropic.com>
--- Co-authored-by: Claude Code <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2186 +/- ##
=======================================
+ Coverage 76% 77% +1%
=======================================
Files 62 62
Lines 7575 7592 +17
=======================================
+ Hits 5743 5810 +67
+ Misses 1832 1782 -50 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a safety warning to sv.InferenceSlicer to help users detect a common callback mistake where inference is run on the full image instead of the provided slice, which would otherwise produce incorrectly offset/tiled detections.
Changes:
- Add a once-per-instance out-of-slice-bounds check after callback execution, emitting
SupervisionWarningswhen detection coordinates are negative or exceed slice dimensions. - Add thread-safe “warned already” state to prevent warning spam across many slices / multiple threads.
- Add unit tests covering overflow/negative coordinates, single-emission behavior (including multithreaded), and no false positives.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/supervision/detection/tools/inference_slicer.py |
Adds the bounds-check warning logic and a lock/flag to ensure it fires at most once per slicer instance. |
tests/detection/tools/test_inference_slicer.py |
Adds tests validating warning emission behavior and non-emission for in-bounds detections. |
docs/changelog.md |
Documents the new warning behavior in the changelog. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Borda
reviewed
Mar 30, 2026
Borda
reviewed
Mar 30, 2026
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
- Fix SyntaxError: `stacklevel=,` (missing value) → `stacklevel=2`, consistent with other warnings in the codebase - Extract warning message into `msg` variable to satisfy E501 line-length limit --- Co-authored-by: Claude Code <noreply@anthropic.com>
Borda
reviewed
Mar 30, 2026
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.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.
When a user's callback accidentally runs inference on the full image instead of the provided slice, supervision blindly applies slice offsets to coordinates already in full-image space — producing the same detections tiled across a grid with only N unique confidence values for N×slices total detections.
The root cause is a common callback authoring mistake:
Changes
InferenceSlicer._run_callback: After invoking the user callback, checks whether any returned detection coordinate exceeds the slice dimensions or is negative. Either condition indicates the callback is operating on the wrong image. Emits aSupervisionWarningswith an actionable message pointing to the likely cause.InferenceSlicer.__init__: Adds_out_of_slice_bounds_warnedflag so the warning fires at most once per slicer instance, avoiding log spam across hundreds of slices.⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.