Skip to content

Validate parent_id alignment between images and predictions in Dynamic Crop - #2746

Open
rs-03 wants to merge 1 commit into
roboflow:mainfrom
rs-03:fix-dynamic-crop-parent-id-validation
Open

Validate parent_id alignment between images and predictions in Dynamic Crop#2746
rs-03 wants to merge 1 commit into
roboflow:mainfrom
rs-03:fix-dynamic-crop-parent-id-validation

Conversation

@rs-03

@rs-03 rs-03 commented Aug 2, 2026

Copy link
Copy Markdown

What changed

DynamicCropBlockV1.run pairs images with predictions positionally via zip(images, predictions). When those two inputs are produced by independent workflow branches they can be misaligned, so a crop gets taken from one image using another image's detections, producing silently incorrect results (the "nonsense results" described in the issue).

This adds a contract check in crop_image: when the predictions carry a parent_id (as model-produced sv.Detections do), it must match the image's parent_metadata.parent_id. On a mismatch the block now raises a clear ValueError explaining the misalignment instead of returning wrong crops. The check mirrors the block's existing detection_id contract validation and is skipped when predictions carry no parent_id, so behavior is unchanged for correctly aligned inputs.

Closes #390

Design note

I implemented this as validation with an explicit error, consistent with the block's existing detection_id contract check, because a silent realignment would hide a genuinely misconfigured workflow rather than surface it. If you would instead prefer the block to match predictions to images by parent_id, I am happy to switch to that approach.

Tests

Added two unit tests in tests/workflows/unit_tests/core_steps/transformations/test_crop.py:

  • test_crop_image_raises_when_predictions_parent_id_does_not_match_image (fails on the pre-fix code, confirming the guard is effective)
  • test_crop_image_accepts_predictions_whose_parent_id_matches_image

Command run:

pytest tests/workflows/unit_tests/core_steps/transformations/test_crop.py

Result: 47 passed. Files were formatted with black (26.3.1) and isort (5.13.2); both leave the changes unchanged.

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.

CropBlock - ensure parent_id of detection and cropped image match

1 participant