Skip to content

Fix deprecated max_size parameter handling in DETR image processors#39046

Open
nck90 wants to merge 6 commits intohuggingface:mainfrom
nck90:fix-max-size-parameter-handling
Open

Fix deprecated max_size parameter handling in DETR image processors#39046
nck90 wants to merge 6 commits intohuggingface:mainfrom
nck90:fix-max-size-parameter-handling

Conversation

@nck90
Copy link
Copy Markdown

@nck90 nck90 commented Jun 26, 2025

Fixes #37939

The deprecated max_size parameter was incorrectly overriding the size parameter completely instead of being properly handled. This affected both ConditionalDetrImageProcessor and DetrImageProcessor.

Changes:

  • Fixed init method to properly handle max_size parameter by setting longest_edge when size dict doesn't have it, instead of replacing size
  • Fixed preprocess method to handle max_size parameter correctly
  • Added max_size as explicit parameter to init for proper from_dict support
  • Added comprehensive tests for max_size parameter handling

The fix ensures backward compatibility while properly deprecating the max_size parameter in favor of size['longest_edge'].

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

nck90 added 6 commits June 26, 2025 09:04
Fixes huggingface#37939

The deprecated max_size parameter was incorrectly overriding the size
parameter completely instead of being properly handled. This affected
both ConditionalDetrImageProcessor and DetrImageProcessor.

Changes:
- Fixed __init__ method to properly handle max_size parameter by setting
  longest_edge when size dict doesn't have it, instead of replacing size
- Fixed preprocess method to handle max_size parameter correctly
- Added max_size as explicit parameter to __init__ for proper from_dict support
- Added comprehensive tests for max_size parameter handling

The fix ensures backward compatibility while properly deprecating the
max_size parameter in favor of size['longest_edge'].
- Fix whitespace and trailing spaces detected by ruff
- Apply black code formatting
- Ensure all code quality checks pass
- Fix runtime error: ensure longest_edge is always present in size dict
- Fix ruff formatting issues
- Fix check_copies.py consistency by updating DeformableDetr as well
- Properly handle max_size parameter in all DETR image processors
- Fix max_size parameter handling in preprocess method to match DETR ImageProcessor
- Ensure consistency across all DETR image processors
- This should resolve the check_copies.py validation error
- Fix __init__ method: Remove hardcoded max_size=1333 in get_size_dict call
- Fix resize method: Handle max_size with existing size dict properly
- Fix test: Use proper test dict without conflicting longest_edge
- Ensure max_size works correctly with from_dict and preprocess methods
- All DETR variants (Conditional, Deformable, standard) now consistent
- Fix ConditionalDetrImageProcessor.from_dict to handle max_size correctly
- Fix DetrImageProcessor.from_dict to handle max_size correctly
- Fix DeformableDetrImageProcessor.from_dict to handle max_size correctly
- Fix preprocess methods in all DETR variants to handle max_size properly
- Add comprehensive test verification script
- Ensure max_size is properly converted to longest_edge in size dict
- Handle both integer size and dict size with max_size parameter
- All fixes maintain backward compatibility with deprecation warnings

Fixes issue where max_size parameter would incorrectly overwrite
existing size settings instead of being properly integrated.
@Rocketknight1
Copy link
Copy Markdown
Member

cc @qubvel @yonigozlan

@qubvel
Copy link
Copy Markdown
Contributor

qubvel commented Jun 27, 2025

Hello @nck90, thanks for opening a PR, but unfortunately, we can't remove support for max_size for DETR because some models on the hub have not yet updated their configs.

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

3 participants