Evaluation Parameters
To compute the spatial_match metric, the following parameters must be provided:-
actual_output: A list of predicted bounding boxes. Each box must be in[x1, y1, x2, y2]format (coordinates of top-left and bottom-right corners). Accepts two formats:- JSON array:
"[[10, 10, 50, 50], [100, 100, 120, 120]]" - JSON object with “bboxes” key:
'{"bboxes": [[10, 10, 50, 50], [100, 100, 120, 120]]}'
- JSON array:
-
expected_output: A single ground truth bounding box in[x1, y1, x2, y2]format. Accepts two formats:- JSON array:
"[10, 10, 50, 50]" - JSON object with “bbox” key (singular):
'{"bbox": [10, 10, 50, 50]}'
- JSON array:
actual_output and expected_output must be valid JSON. Truncated or malformed JSON will cause evaluation failures.
How Is It Calculated?
- The predicted box is compared against each reference box.
- The IoU is calculated for each pair:
- The highest IoU score among all comparisons is selected as the final score.
- If this score is greater than or equal to a predefined threshold (0.5), the metric returns 100% (pass). Otherwise, it returns 0% (fail).
Interpretation of Scores
- 1.0 – Strong spatial match; high alignment.
- 0.0 – Low spatial match; poor alignment.
Suggested Test Case Types
Use Spatial Match when evaluating:- Document layout tasks requiring accurate box alignment.
- OCR or form field extraction where exact box positioning matters.
- Visual QA and multi-box alignment tasks that benefit from flexible but spatially aware comparisons.