-
Notifications
You must be signed in to change notification settings - Fork 31.4k
Use canonical get_size_with_aspect_ratio (with max_size) from transformers.image_transforms to fix #37939 #41284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use canonical get_size_with_aspect_ratio (with max_size) from transformers.image_transforms to fix #37939 #41284
Conversation
902ad41 to
d6ad5b4
Compare
molbap
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! I'm all for simplifying the image processing logic wherever we can, however this will break Backwards Compatibility on a few models (from what I checked, not many). cc @yonigozlan wdyt?
@sonianuj287 , Can you please edit the PR's name to add "🚨🚨🚨" in front so we know it's breaking? Thank you!
|
Hi @molbap , Thanks for replying. Okay will change the PR's name. |
yonigozlan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sonianuj287 ! Thanks for working on this. However I'm not sure this fixes #37939 as max_size is still accepted as an arg?
To deprecate it fully we need to modify the resize function of conditional detr. However I agree with removing get_size_with_aspect_ratio from the image processor and importing it from image_transforms as they seem to be equivalent.
We can first start with merging this PR to deprecate max_size and import get_size_with_aspect_ratio from image_transforms, and I think we can then extend this to other models which have an equivalent get_size_with_aspect_ratio to the image_transforms one plainly written in their image processing file, along with support for max_size :)
|
However as @qubvel noted in #37939, we still have a lot of popular models using |
|
HI @yonigozlan, Thanks for confirming to merge this PR. Let me get the task to change in other models which have an equivalent get_size_with_aspect_ratio to the image_transforms one plainly written in their image processing file, along with support for max_size. Delighted to help you. :) |
|
I can see some conflict arouse due to some new changes, I'll fix them in couple of minutes. |
…rmers.image_transforms to fix huggingface#37939
7430aa6 to
d6ad5b4
Compare
e05375e to
c186903
Compare
c186903 to
b66368b
Compare
|
Hi @yonigozlan , I resolved the conflict, and the workflows also passed. Let me know for any other changes, and we good to close. :) |
|
I can see files like - having this function - def get_size_with_aspect_ratio with max_size attribute, I can change it to avoid errors These files also have this function but max_size is an optional attribute there, so we can skip them. right? should I go further and make changes? |
|
Hey @sonianuj287 , if the |
yonigozlan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sonianuj287, be careful not to remove get_size_with_aspect_ratio if it's not the same as in image_transforms, for the yolos image processors, they are not the same! Also it looks like you haven't
| return (max_height, max_width) | ||
|
|
||
|
|
||
| def get_size_with_aspect_ratio( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the same as in image_transforms! (mode_size)
| logger = logging.get_logger(__name__) | ||
|
|
||
|
|
||
| def get_size_with_aspect_ratio( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
…ssors (except YOLOS) This commit updates image processing utilities in multiple model processors to use the shared transformers.image_transforms.get_size_with_aspect_ratio for consistent resizing logic and aspect ratio handling. YOLOS processors are intentionally left unchanged in this commit to preserve their current behavior and avoid breaking model-specific padding/resizing assumptions. YOLOS will be updated in a dedicated follow-up PR once compatibility is fully verified.
4b94897 to
8bfd765
Compare
|
This PR updates all relevant image processors to use the canonical get_size_with_aspect_ratio function from transformers.image_transforms. |
91ae426 to
76ef2e8
Compare
…canonical transformers.image_transforms version
3a213f2 to
cc941b8
Compare
|
Hi @yonigozlan , just a follow up. Am I going correct? |
yonigozlan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @sonianuj287 ! Looks good to me, let's wait for the CI to pass then I'll merge :)
|
[For maintainers] Suggested jobs to run (before merge) run-slow: conditional_detr, deformable_detr, detr, eomt, grounding_dino, mask2former, maskformer, rt_detr |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
…rmers.image_transforms to fix huggingface#37939 (huggingface#41284) * Use canonical get_size_with_aspect_ratio (with max_size) from transformers.image_transforms to fix huggingface#37939 * Fix import sorting/style * Fix import order * Refactor: use canonical get_size_with_aspect_ratio across image processors (except YOLOS) This commit updates image processing utilities in multiple model processors to use the shared transformers.image_transforms.get_size_with_aspect_ratio for consistent resizing logic and aspect ratio handling. YOLOS processors are intentionally left unchanged in this commit to preserve their current behavior and avoid breaking model-specific padding/resizing assumptions. YOLOS will be updated in a dedicated follow-up PR once compatibility is fully verified. * ruff fixes * Fix check_copies.py references for get_size_with_aspect_ratio to use canonical transformers.image_transforms version --------- Co-authored-by: Yoni Gozlan <74535834+yonigozlan@users.noreply.github.com>
Removed max_size parameter from ConditionalDetrImageProcessor
to simplify image resizing logic and fix #37939.
Used canonical get_size_with_aspect_ratio (with max_size) from transformers.image_transforms
Tested with pytest suite and all tests are passed.
Happy to be guided further for improvement.
Thanks