Skip to content

fix: return empty int ndarray instead of None for class_id on empty VLM parse#2239

Open
YousefZahran1 wants to merge 1 commit intoroboflow:developfrom
YousefZahran1:youssef/fix-vlm-parser-class-id-consistency
Open

fix: return empty int ndarray instead of None for class_id on empty VLM parse#2239
YousefZahran1 wants to merge 1 commit intoroboflow:developfrom
YousefZahran1:youssef/fix-vlm-parser-class-id-consistency

Conversation

@YousefZahran1
Copy link
Copy Markdown

What

On empty-parse paths in two VLM parsers, class_id was returned as None instead of a zero-length ndarray of dtype int, inconsistent with every other exit point in these functions and with the convention established by from_google_gemini_2_5, from_qwen_2_5_vl, and from_qwen_3_vl.

Affected code paths

Function Condition Before After
from_paligemma regex finds no matches None np.empty((0,), dtype=int)
from_google_gemini_2_0 JSONDecodeError None np.empty((0,), dtype=int)
from_google_gemini_2_0 empty bounding-box list None np.empty((0,), dtype=int)

Why it matters

Callers that do class_id.shape, len(class_id), or class_id[mask] immediately after parsing will get an AttributeError / TypeError whenever zero detections are returned — a very common path in production (frame with nothing to detect). Downstream Detections.from_vlm(...) pipelines hit this at runtime while unit tests may pass because they check happy paths.

Changes

  • src/supervision/detection/vlm.py — 3 one-line fixes (no logic change)
  • tests/detection/test_vlm.py — updated 10 test expectations to match the new contract

All 88 tests in tests/detection/test_vlm.py pass.

Fixes #2219

… parse

When from_paligemma or from_google_gemini_2_0 find no detections (no regex
matches, JSON decode error, or empty bounding-box list), they previously
returned None for class_id. All other early-exit and filter paths already
return a zero-length ndarray of dtype int. This inconsistency causes
downstream AttributeError when callers unconditionally call .shape or
iterate over the result.

Affected paths:
- from_paligemma: matches.shape[0] == 0 branch
- from_google_gemini_2_0: JSONDecodeError branch and len(xyxy) == 0 branch

Closes roboflow#2219
@YousefZahran1 YousefZahran1 requested a review from SkalskiP as a code owner April 30, 2026 20:47
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 30, 2026

CLA assistant check
All committers have signed the CLA.

@Borda
Copy link
Copy Markdown
Member

Borda commented Apr 30, 2026

Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@YousefZahran1 could you pls sign ^^ 🦝

@Borda Borda marked this pull request as draft April 30, 2026 21:54
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78%. Comparing base (87b1b86) to head (7e57e2c).
⚠️ Report is 4 commits behind head on develop.

❌ Your project check has failed because the head coverage (78%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2239   +/-   ##
=======================================
  Coverage       78%     78%           
=======================================
  Files           66      66           
  Lines         8347    8347           
=======================================
  Hits          6475    6475           
  Misses        1872    1872           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@YousefZahran1
Copy link
Copy Markdown
Author

"CLA signed! Ready for review when you have a moment.

@YousefZahran1 YousefZahran1 marked this pull request as ready for review April 30, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Design]: Pick one convention for class_id on the error path of VLM parsers

3 participants