Skip to content

Fix image resize minimum-size handling#358

Open
Travor278 wants to merge 1 commit into
om-ai-lab:mainfrom
Travor278:fix/image-resize-min-size
Open

Fix image resize minimum-size handling#358
Travor278 wants to merge 1 commit into
om-ai-lab:mainfrom
Travor278:fix/image-resize-min-size

Conversation

@Travor278
Copy link
Copy Markdown

@Travor278 Travor278 commented May 6, 2026

Description

Fixes the image minimum-size resize path used during GRPO generation scoring. Normal-size images are now returned unchanged, while images with either side below 28 pixels are resized once with aspect ratio preserved.

The trainer behavior for valid images is unchanged except that it no longer relies on an UnboundLocalError/broad exception path for normal images. A small image utility and focused tests cover the resize cases.

Related Issue

Resolves #355.

Motivation and Context

The previous code defined new_w and new_h only inside the small-image branch but called img.resize((new_w, new_h), ...) outside that branch. For normal images, this triggered exception handling as part of normal control flow. Moving the behavior into a tested helper makes the intended resize contract explicit and avoids that overhead.

How Has This Been / Can This Be Tested?

Tested locally on Windows with Anaconda py311 / Python 3.11.15.

D:\Dev\conda-envs\py311\python.exe -m py_compile src/open-r1-multimodal/src/open_r1/utils/image.py src/open-r1-multimodal/tests/test_image.py
$env:PYTHONPATH='src/open-r1-multimodal/src'; D:\Dev\conda-envs\py311\python.exe -m pytest src/open-r1-multimodal/tests/test_image.py

The focused image tests passed: 5 passed.

Checklist

  • Normal-size and boundary-size images remain unchanged.
  • Images below the minimum size are expanded while preserving aspect ratio.
  • Existing trainer fallback behavior is preserved for unexpected image errors.
  • Added focused tests for the resize helper.

@Travor278 Travor278 marked this pull request as ready for review May 6, 2026 18:26
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.

Fix performance overhead caused by incorrect indentation in image resizing logic

1 participant