Skip to content

fix(workflows): preserve image metadata on empty Template Matching results - #3038

Merged
PawelPeczek-Roboflow merged 4 commits into
roboflow:mainfrom
davidnichols-ops:fix/template-empty-image-metadata
Sep 25, 2026
Merged

PawelPeczek-Roboflow merged 4 commits into
roboflow:mainfrom
davidnichols-ops:fix/template-empty-image-metadata

Conversation

@davidnichols-ops

Copy link
Copy Markdown
Contributor

Summary

When template_matching@v1 finds no matches, its numpy path returns a bare sv.Detections.empty(). The serializer then emits image.width and image.height as null, and the empty result has no parent/root lineage. Use the existing empty_detections_with_image_metadata(image) helper for this branch so zero-match results keep the input image's dimensions and lineage. The matched-result path is unchanged; the tensor-native sibling already carries image metadata on empty results.

Root cause and before/after

  • Before: a 160×120 input with zero matches serialized as {"image": {"width": null, "height": null}, "predictions": []}.
  • After: the same path serializes as {"image": {"width": 160, "height": 120}, "predictions": []} and retains parent/root metadata on the empty detections object.

What changed

  • Return the existing metadata-aware empty detections helper from Template Matching's zero-match branch.
  • Add a block-level regression test for zero predictions, serialized dimensions, and parent/root lineage.
  • Add the required Workflows Unreleased changelog entry.

Verification

  • Before the fix, the new focused test failed on the null dimensions (1 failed, 4 passed).
  • After merging current upstream main, uv run --project . --extra test --locked pytest tests/unit_tests/core_steps/classical_cv/test_template_matching.py -q from workflows/: 5 passed, 8 Pydantic deprecation warnings.
  • Related serializer, utility, and formatter tests: 368 passed, 84 deprecation warnings.
  • Black, isort, and git diff --check: passed.

Scope

This addresses the numpy Template Matching zero-match path. It does not change tensor-native behavior or claim that every downstream Workflows consumer has been exercised. Release timing is up to maintainers.

…sults

When template_matching@v1 finds no matches, its numpy path returns a bare sv.Detections.empty(). The serializer then emits image.width and image.height as null, and the empty result has no parent/root lineage. Use the existing empty_detections_with_image_metadata(image) helper for this branch so zero-match results keep the input image's dimensions and lineage.

Adds a block-level regression test and updates workflows CHANGELOG.
@davidnichols-ops
davidnichols-ops force-pushed the fix/template-empty-image-metadata branch from 1e0f5f4 to 83ed04e Compare September 24, 2026 12:46
@PawelPeczek-Roboflow
PawelPeczek-Roboflow merged commit f7f7345 into roboflow:main Sep 25, 2026
5 checks passed
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.

2 participants