supervision/tests/detection
Ruben 44546a13f2
fix(vlm): handle malformed Gemini/Qwen model output without crashing (#2342)
Two ways the VLM parsers crashed on adversarial model output instead of
degrading gracefully (the contract they already honor for invalid JSON):

1. Gemini 2.5: a mask value that is not a 'data:image/png;base64,' string
   appended an empty mask and then 'continue'd, skipping the confidence
   handler at the bottom of the loop. The item's box was recorded but its
   confidence was not, so the confidence array ended up shorter than xyxy
   and Detections.from_vlm raised a shape ValueError. Replaced the
   'continue' with an if/else so the confidence handler always runs.

2. Gemini 2.0 / Gemini 2.5 / Qwen 2.5: valid JSON whose top level is not a
   list, or whose elements are not dicts (e.g. '[1, 2, 3]'), raised
   TypeError from the 'key not in item' membership test. Added a top-level
   list guard (Gemini 2.0/2.5; Qwen already had one) and a per-element
   dict guard so wrong-shaped JSON degrades to empty Detections.

Add regression tests for the mask/confidence alignment and for graceful
degradation across all three parsers.

---------

Co-authored-by: jirka <6035284+Borda@users.noreply.github.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-06-18 15:31:31 +02:00
..
tools fix(smoother): handle detections without confidence (#2333) 2026-06-17 21:16:43 +02:00
utils perf(detection): compute mask IoU via matmul instead of an (N, M, H, W) intermediate (#2323) 2026-06-18 10:45:56 +02:00
__init__.py refactor: reorganize project structure and update module imports (#2112) 2026-02-03 15:24:47 +01:00
test_compact_mask.py feat(compact_mask): add `resize()` method and benchmark stage (#2227) 2026-04-22 15:34:12 +02:00
test_compact_mask_integration.py feat: add CompactMask for memory-efficient crop-RLE mask storage (#2159) 2026-04-13 11:10:12 +02:00
test_compact_mask_iou.py feat: add CompactMask for memory-efficient crop-RLE mask storage (#2159) 2026-04-13 11:10:12 +02:00
test_core.py fix(detection): make `oriented_box_iou_batch` exact and gate non-overlapping pairs (#2317) 2026-06-15 20:54:06 +02:00
test_csv.py fix(sinks): slice list and tuple custom_data values per row (#2216) 2026-04-18 00:24:36 +02: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_inference_slicer_compact.py feat: add CompactMask for memory-efficient crop-RLE mask storage (#2159) 2026-04-13 11:10:12 +02:00
test_json.py fix(json_sink): serialize NumPy scalars in `custom_data` (#2334) 2026-06-17 22:27:03 +02: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 fix(vlm): handle malformed Gemini/Qwen model output without crashing (#2342) 2026-06-18 15:31:31 +02:00