supervision/tests/detection
Copilot e6fab4b7fa
Add out-of-bounds detection warning to InferenceSlicer (#2186)
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.

- 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
- 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)
- Extract warning message into `msg` variable to satisfy E501 line-length limit


---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-03-30 19:26:33 +02:00
..
tools Add out-of-bounds detection warning to InferenceSlicer (#2186) 2026-03-30 19:26:33 +02:00
utils Add `match` arguments to all `pytest.raises` for more precise error validation in tests (#2145) 2026-02-10 21:22:55 +09:00
__init__.py refactor: reorganize project structure and update module imports (#2112) 2026-02-03 15:24:47 +01:00
test_core.py Fix mask_annotate for int dtypes (#1445) 2026-02-20 10:43:56 +01:00
test_csv.py refactor: reorganize project structure and update module imports (#2112) 2026-02-03 15:24:47 +01:00
test_from_adapters.py refactor: reorganize project structure and update module imports (#2112) 2026-02-03 15:24:47 +01:00
test_from_sam.py Add support for SAM3 PVS output (#2152) 2026-02-19 17:09:31 +01:00
test_json.py refactor: reorganize project structure and update module imports (#2112) 2026-02-03 15:24:47 +01:00
test_line_counter.py refactor docstrings in `scr/supervision/detection` (#2162) 2026-03-10 18:40:05 +01:00
test_polygon_zone_annotator.py refactor: reorganize project structure and update module imports (#2112) 2026-02-03 15:24:47 +01:00
test_polygonzone.py fix: prevent single object from appearing in multiple polygon zones (#1991) 2026-03-10 21:19:09 +01:00
test_vlm.py Add `match` arguments to all `pytest.raises` for more precise error validation in tests (#2145) 2026-02-10 21:22:55 +09:00