Skip to content

[Python] Tolerate Pillow 13 resize rounding in PyTorch MaskRCNN COCO ITs - #41646

Merged
damccorm merged 1 commit into
users/damccorm/py313-inference-2-huggingfacefrom
users/damccorm/py313-inference-3-pytorch
Nov 25, 2026
Merged

damccorm merged 1 commit into
users/damccorm/py313-inference-2-huggingfacefrom
users/damccorm/py313-inference-3-pytorch

Conversation

@damccorm

@damccorm damccorm commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #41652 (stack: https://github.com/apache/beam/stack/41650).

Stack 3/6 — Makes the two COCO MaskRCNN integration tests in pytorch_inference_it_test.py resilient to minor image-resizing rounding differences across Pillow/PyTorch versions:

  • MaskRCNN returns all detections above box_score_thresh=0.05 sorted by score. Pillow 13.0.0 (used by Beam's Python 3.11–3.14 environments) produces a ±1/255 bilinear resize difference on two COCO val2017 images (000000006818.jpg and 000000331352.jpg), which reorders nearly-tied detections and toggles borderline detections near 0.05.
  • Adds _assert_labels_match to compare parsed detection label lists using an exact top-5 match plus >= 0.8 multiset IoU, keeping the assertion meaningful across Pillow 10–13 without mutating the shared GCS golden files used by older release branches.

(Note: the 15 missing COCO val2017 JPEG inputs referenced by gs://apache-beam-ml/testing/inputs/it_coco_validation_inputs.txt have also been restored to gs://apache-beam-ml/datasets/coco/raw-data/val2017/.)

Verification

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (users/damccorm/py313-inference-2-huggingface@c92f42e). Learn more about missing BASE report.

Additional details and impacted files
@@                               Coverage Diff                               @@
##             users/damccorm/py313-inference-2-huggingface   #41646   +/-   ##
===============================================================================
  Coverage                                                ?   58.04%           
  Complexity                                              ?     2844           
===============================================================================
  Files                                                   ?     1210           
  Lines                                                   ?   173284           
  Branches                                                ?     2329           
===============================================================================
  Hits                                                    ?   100586           
  Misses                                                  ?    69988           
  Partials                                                ?     2710           
Flag Coverage Δ
python 80.67% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@damccorm
damccorm marked this pull request as ready for review November 24, 2026 19:58
@damccorm

Copy link
Copy Markdown
Contributor Author

stop reviewer notifications

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR updates the PyTorch MaskRCNN COCO integration tests in pytorch_inference_it_test.py to tolerate minor bilinear resize rounding differences introduced in Pillow 13.0.0. Instead of enforcing strict string equality across the entire detection list, it checks for an exact match on the top 5 predictions and at least 0.8 multiset IoU across all detected labels.

🔍 General Feedback

  • The approach is clean, well-scoped, and preserves compatibility with shared GCS golden files across different Python and Pillow versions.
  • Consider guarding against a potential ZeroDivisionError in _assert_labels_match if both expected and predicted label lists are ever empty (i.e., union == 0), though self.assertEqual(expected[:top_k], predicted[:top_k]) would already hold in that case.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

MaskRCNN returns all detections above score 0.05 sorted by confidence, so +/-1
pixel bilinear resize rounding differences introduced in Pillow 13.0.0 reorder
nearly-tied detections and toggle borderline detections near 0.05. Compare
parsed label lists using exact top-5 match plus >= 0.8 multiset IoU so tests
remain resilient across Pillow/PyTorch versions without mutating shared GCS
golden files.
@damccorm
damccorm force-pushed the users/damccorm/py313-inference-3-pytorch branch from e90083d to ac0682c Compare November 24, 2026 20:08
@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: requested by reviewer. If you'd like to restart, comment assign set of reviewers

@damccorm
damccorm merged commit 29ebd13 into master Nov 25, 2026
89 of 91 checks passed
@damccorm
damccorm deleted the users/damccorm/py313-inference-3-pytorch branch November 25, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python size/s S: 10-49 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants