fix(metrics): retain detection tensor columns for empty pages
AF
11h ago+87+87+01234567890123456789-1-1-0123456789
Summary
The JSON detection loader converts an empty page to a tensor with shape (0,). Matching expects a prediction matrix with six columns and a target matrix with five columns, so blank pages or pages without annotations raise an IndexError during document evaluation.
Reshape each loaded page to its declared matrix format. Nonempty page values and layout are unchanged; empty predictions and empty targets can now participate in the existing matching and metric calculations.
Validation
- Added 10 native JSON-to-metrics tests: 7 fail and 3 pass on the unchanged base; all 10 pass after the fix.
- Covers all empty/nonempty prediction and target combinations, blank pages at different document positions, false-positive and false-negative pages with hand-calculated precision/recall/F1/AP, and the existing empty-document sentinel.
- Preserves the existing undefined (
NaN) metrics when no class has any ground-truth targets. - Ruff 0.15.10 check/format and
git diff --checkpass. The full optional-dependency suite was not run.
Checklist
- Added regression tests for the behavior change.
- Preserved nonempty tensor layout and metric conventions.
- Apply the
buglabel.