Skip to content

Conversation

@sonianuj287
Copy link
Contributor

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

@Rocketknight1
Copy link
Member

cc @molbap @yonigozlan

@sonianuj287 sonianuj287 force-pushed the fix-conditionaldetr-remove-maxsize branch from 902ad41 to d6ad5b4 Compare October 2, 2025 12:37
Copy link
Contributor

@molbap molbap left a 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!

@sonianuj287
Copy link
Contributor Author

Hi @molbap , Thanks for replying. Okay will change the PR's name.
For the issue, the other way to resolve is to fix all function calls for this function - "get_size_with_aspect_ratio" by removing max_size parameter.

Copy link
Member

@yonigozlan yonigozlan left a 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 :)

@yonigozlan
Copy link
Member

However as @qubvel noted in #37939, we still have a lot of popular models using max_size on the hub, so we must be careful how we approach this. We can first remove all get_size_with_aspect_ratio in imaging files if they are equivalent to the image_transforms one, as this shouldn't cause any issues with BC

@sonianuj287
Copy link
Contributor Author

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. :)

@sonianuj287
Copy link
Contributor Author

I can see some conflict arouse due to some new changes, I'll fix them in couple of minutes.

@sonianuj287 sonianuj287 force-pushed the fix-conditionaldetr-remove-maxsize branch from 7430aa6 to d6ad5b4 Compare October 3, 2025 15:05
@sonianuj287 sonianuj287 force-pushed the fix-conditionaldetr-remove-maxsize branch 2 times, most recently from e05375e to c186903 Compare October 3, 2025 15:19
@sonianuj287 sonianuj287 force-pushed the fix-conditionaldetr-remove-maxsize branch from c186903 to b66368b Compare October 3, 2025 15:20
@sonianuj287
Copy link
Contributor Author

Hi @yonigozlan , I resolved the conflict, and the workflows also passed. Let me know for any other changes, and we good to close. :)

@sonianuj287 sonianuj287 requested a review from yonigozlan October 3, 2025 15:37
@sonianuj287
Copy link
Contributor Author

@yonigozlan @molbap

I can see files like -
image_transformers.py
image_processing_deformable_detr.py
image_processing_data.py
image_processing_detr.py
image_processing_eomt.py
image_processing_grounding_dino.py
image_processing_masking2former.py
image_processing_maskformer.py
image_processing_rt_detr.py

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?
image_processing_yolos_past.py
image_processing_yolos.py
modular_yolos.py

should I go further and make changes?

@yonigozlan
Copy link
Member

Hey @sonianuj287 , if the get_size_with_aspect_ratio defined is these files are the exact same than in image_transforms, let's remove them form these files and import them from image_transforms, even for image_processing_yolos etc.

Copy link
Member

@yonigozlan yonigozlan left a 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(
Copy link
Member

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(
Copy link
Member

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.
@sonianuj287 sonianuj287 force-pushed the fix-conditionaldetr-remove-maxsize branch 2 times, most recently from 4b94897 to 8bfd765 Compare October 4, 2025 14:14
@sonianuj287
Copy link
Contributor Author

Hi @yonigozlan @molbap

This PR updates all relevant image processors to use the canonical get_size_with_aspect_ratio function from transformers.image_transforms.
The YOLOS model is temporarily excluded to avoid altering its output dimensions — it will be handled in a dedicated follow-up PR once backward compatibility is ensured.

@sonianuj287 sonianuj287 force-pushed the fix-conditionaldetr-remove-maxsize branch from 91ae426 to 76ef2e8 Compare October 4, 2025 14:24
…canonical transformers.image_transforms version
@sonianuj287 sonianuj287 force-pushed the fix-conditionaldetr-remove-maxsize branch from 3a213f2 to cc941b8 Compare October 4, 2025 14:37
@sonianuj287
Copy link
Contributor Author

Hi @yonigozlan , just a follow up. Am I going correct?
shall we go and merge and proceed with yolo changes next..

Copy link
Member

@yonigozlan yonigozlan left a 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 :)

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2025

[For maintainers] Suggested jobs to run (before merge)

run-slow: conditional_detr, deformable_detr, detr, eomt, grounding_dino, mask2former, maskformer, rt_detr

@HuggingFaceDocBuilderDev

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.

@yonigozlan yonigozlan merged commit 297a41a into huggingface:main Oct 6, 2025
20 checks passed
AhnJoonSung pushed a commit to AhnJoonSung/transformers that referenced this pull request Oct 12, 2025
…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>
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.

ConditionalDetrImageProcessor still accepts the deprecated parameter max_size

5 participants