supervision/tests
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
..
annotators perf(annotators): share mask painting and give HaloAnnotator the CompactMask path (#2339) 2026-06-18 12:37:11 +02:00
assets feat: replace print statements with structured logging (#2154) 2026-02-20 13:14:53 +01:00
classification refactor docstrings in `draw`, `classification`, and `key_points` (#2161) 2026-03-10 18:07:39 +01:00
dataset fix(dataset): stop Pascal VOC export from mutating source detections (#2341) 2026-06-18 15:29:37 +02:00
detection fix(vlm): handle malformed Gemini/Qwen model output without crashing (#2342) 2026-06-18 15:31:31 +02:00
draw feat: add support for hexadecimal RGBA color format (#2004) 2026-03-30 15:57:18 +02:00
geometry Extend docstrings to test cases for enhanced readability (#2130) 2026-02-03 17:28:33 +01:00
key_points feat: add `KeyPoints.with_nms()` method (#2338) 2026-06-18 10:42:43 +02:00
metrics fix(metrics): count false positives on background images and absent classes (#2331) 2026-06-17 19:46:10 +02:00
tracker Fix external track ids (#1364) 2026-02-20 00:58:55 +01:00
utils fix: normalize file extension filters (#2298) 2026-06-08 13:41:25 +02:00
__init__.py
conftest.py ci(tests): disable matplotlib GUI and exclude non-test dirs from collection (#2262) 2026-05-20 23:40:21 +02:00
helpers.py refactor: enrich `KeyPoints` with visibility mask, split confidence fields, and redesign uncertainty annotator (#2286) 2026-06-11 18:34:33 +02:00
test_validate_deprecations.py refactor: privatize validation helpers (#2294) 2026-06-06 13:15:54 -06:00