[Clean-up] Planned removal of the `max_size` argument
Author: HichTala
Pull request: yes

# What does this PR do?

This PR aims to serve as a progress tracker for updating the size configurations of detection models on the Hugging Face Hub. The updates focus on aligning the configs with the deprecation of the `max_size` argument while ensuring backward compatibility where needed. Each update will be submitted as an individual PR directly to the model repositories on the Hub, following the script and guidance provided by @qubvel.

All individual pull requests made directly to the model repositories on the Hub will be tracked here via links, providing a clear overview of progress and ensuring comprehensive updates across relevant models.

Here's a brief summary of what's been done so far regarding the planned deletion of the `max_size` argument:

This pull request includes multiple changes across several image processing files in the transformers library. The primary focus is on deprecating the `max_size` parameter and replacing it with `size['longest_edge']`. Additionally, backwards compatibility adjustments have been made to handle the `size` parameter more flexibly.

Deprecation of `max_size` parameter:

* [`src/transformers/models/conditional_detr/image_processing_conditional_detr.py`](diffhunk://#diff-c521b281a0d72092aec2dcad7ad516928e7462b4f4bcdcea5d007b7fe28bc43bL880-R888): Replaced `logger.warning_once` with `logger.error` for the `max_size` parameter deprecation and removed handling of `max_size` in `__init__`, `resize`, and `preprocess` methods. [[1]](diffhunk://#diff-c521b281a0d72092aec2dcad7ad516928e7462b4f4bcdcea5d007b7fe28bc43bL880-R888) [[2]](diffhunk://#diff-c521b281a0d72092aec2dcad7ad516928e7462b4f4bcdcea5d007b7fe28bc43bL1014-R1018) [[3]](diffhunk://#diff-c521b281a0d72092aec2dcad7ad516928e7462b4f4bcdcea5d007b7fe28bc43bL1367-R1372) [[4]](diffhunk://#diff-c521b281a0d72092aec2dcad7ad516928e7462b4f4bcdcea5d007b7fe28bc43bL1473-R1468)
* [`src/transformers/models/deformable_detr/image_processing_deformable_detr.py`](diffhunk://#diff-9d778d1efecc45f9608e6df1b9160fa5b84d9f3e90ecf2f55c4ac0e9cdb4ab01L878-R886): Similar changes to deprecate `max_size` and update methods accordingly. [[1]](diffhunk://#diff-9d778d1efecc45f9608e6df1b9160fa5b84d9f3e90ecf2f55c4ac0e9cdb4ab01L878-R886) [[2]](diffhunk://#diff-9d778d1efecc45f9608e6df1b9160fa5b84d9f3e90ecf2f55c4ac0e9cdb4ab01L1012-R1016) [[3]](diffhunk://#diff-9d778d1efecc45f9608e6df1b9160fa5b84d9f3e90ecf2f55c4ac0e9cdb4ab01L1365-R1371) [[4]](diffhunk://#diff-9d778d1efecc45f9608e6df1b9160fa5b84d9f3e90ecf2f55c4ac0e9cdb4ab01L1471-R1467)
* [`src/transformers/models/detr/image_processing_detr.py`](diffhunk://#diff-74625eb393c7631e74bd81b176d57cfb08a80929942837a54c861741f3a5e934L862-R870): Updated to use `logger.error` for deprecation and removed `max_size` handling. [[1]](diffhunk://#diff-74625eb393c7631e74bd81b176d57cfb08a80929942837a54c861741f3a5e934L862-R870) [[2]](diffhunk://#diff-74625eb393c7631e74bd81b176d57cfb08a80929942837a54c861741f3a5e934L993-R997) [[3]](diffhunk://#diff-74625eb393c7631e74bd81b176d57cfb08a80929942837a54c861741f3a5e934L1340-R1345) [[4]](diffhunk://#diff-74625eb393c7631e74bd81b176d57cfb08a80929942837a54c861741f3a5e934L1446-R1441)
* [`src/transformers/models/grounding_dino/image_processing_grounding_dino.py`](diffhunk://#diff-6d900076812c7c1a5596a3dfa1143580dd0fe4f9b827458ef7d832a318a713f0L886-R894): Changed `logger.warning_once` to `raise ValueError` for `max_size` deprecation and removed related code. [[1]](diffhunk://#diff-6d900076812c7c1a5596a3dfa1143580dd0fe4f9b827458ef7d832a318a713f0L886-R894) [[2]](diffhunk://#diff-6d900076812c7c1a5596a3dfa1143580dd0fe4f9b827458ef7d832a318a713f0L1020-R1024) [[3]](diffhunk://#diff-6d900076812c7c1a5596a3dfa1143580dd0fe4f9b827458ef7d832a318a713f0L1373-R1378) [[4]](diffhunk://#diff-6d900076812c7c1a5596a3dfa1143580dd0fe4f9b827458ef7d832a318a713f0L1479-R1474)
* [`src/transformers/models/rt_detr/image_processing_rt_detr.py`](diffhunk://#diff-e0274b01a4b788c6e03df73adb099f681f83b5fc59015bdeefee312fe0b23ca5L534-R541): Updated to handle `max_size` deprecation similarly.

Backwards compatibility adjustments:

* [`src/transformers/models/conditional_detr/image_processing_conditional_detr.py`](diffhunk://#diff-c521b281a0d72092aec2dcad7ad516928e7462b4f4bcdcea5d007b7fe28bc43bL880-R888): Added handling for `size` when it is an integer.
* [`src/transformers/models/deformable_detr/image_processing_deformable_detr.py`](diffhunk://#diff-9d778d1efecc45f9608e6df1b9160fa5b84d9f3e90ecf2f55c4ac0e9cdb4ab01L878-R886): Included similar handling for integer `size`.
* [`src/transformers/models/detr/image_processing_detr.py`](diffhunk://#diff-74625eb393c7631e74bd81b176d57cfb08a80929942837a54c861741f3a5e934L862-R870): Adjusted `size` handling for backwards compatibility.
* [`src/transformers/models/grounding_dino/image_processing_grounding_dino.py`](diffhunk://#diff-6d900076812c7c1a5596a3dfa1143580dd0fe4f9b827458ef7d832a318a713f0L886-R894): Added compatibility handling for `size`.
* [`src/transformers/models/rt_detr/image_processing_rt_detr.py`](diffhunk://#diff-e0274b01a4b788c6e03df73adb099f681f83b5fc59015bdeefee312fe0b23ca5R456-R457): Included backwards compatibility for `size`.


<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

It follows an issue and a pull request linked bellow:
- #34977
- #34998 



## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? 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](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

@qubvel 

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker
- vision models: @amyeroberts, @qubvel
- speech models: @ylacombe, @eustlb
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
I started by testing on my own repository to make sure everything works good and avoid spamming all models.

Here is the link to commit that is returned by `push_to_hub` method: https://huggingface.co/HichTala/test_pull_requests/commit/bb6b52f2f2039b5f4b1a27c33ebc42af072a9206

The pushed config file adds optional arguments and rearranges the arguments in an order sometimes different from that of the original file. If this is ok, we can start pushing the first 5 models.

Hi @HichTala! Thanks for continuing with this issue 🤗 

It's great that you tried using your own model! I suggest:
1. Replacing `"feature_extractor_type": "DetrFeatureExtractor"` with `"image_processor_type": "DetrImageProcessor"` because the feature extractor is deprecated.
2. Removing `max_size` and replacing `size` with a dictionary.

This way, it will be easier to merge those pull requests, and the difference will be smaller! I suppose it will require modifying the raw JSON file, instead of saving with ImageProcessor.

Hi @qubvel, 
I followed your suggestion, [here](https://huggingface.co/HichTala/test_pull_requests/commit/effec0af1b6622d90230a05a14db5f6a2c8de24b) is the PR in my own model, I think we're ready to start PRing the first 5 models!
I'll probably launch it in the next few days.

Hi @HichTala! Looks good to me, let's proceed with the first five 👍 

Hi @qubvel, here are the 5 firsts!

- [ ] 0 Model: microsoft/table-transformer-detection
Created: 2022-10-14 09:14:13+00:00
Downloads: `3207449`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/microsoft/table-transformer-detection/commit/bdf4f9300c6cce21d24c41447ee94c2aa8ba6b04)

- [ ] 1 Model: microsoft/table-transformer-structure-recognition
Created: 2022-10-14 09:19:57+00:00
Downloads: `1029420`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/microsoft/table-transformer-structure-recognition/commit/03798d2b0d540e3ff20202105ee9fb8f0eecdc48)

- [x] 2 Model: TahaDouaji/detr-doc-table-detection
Created: 2022-03-11 15:55:14+00:00
Downloads: `238448`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/TahaDouaji/detr-doc-table-detection/commit/20e6b05348a1e272922e502642ba23564f0a1160)

- [x] 3 Model: Aryn/deformable-detr-DocLayNet
Created: 2024-03-19 00:46:32+00:00
Downloads: `25095`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/Aryn/deformable-detr-DocLayNet/commit/8a0fa1d6966707102ee7d626fc4c0ac7493f0a1d)

- [ ] 4 Model: valentinafeve/yolos-fashionpedia
Created: 2022-11-17 16:04:03+00:00
Downloads: `16479`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/valentinafeve/yolos-fashionpedia/commit/b48f3285834dd567278e3a11c86537b772d67586)


Hi @HichTala! Thanks for creating the PRs and providing links. I just verified them, and everything looks perfect. Special thanks for providing a message with the PR. 🤗 I will ask to merge them and then we can proceed with the next batch.

Hi @HichTala, hope you are doing great! 2 PRs were merged by owners, however we can't merge another PRs on our side, so we have to wait to see if they will be accepted for a while. Let's open more PRs 🤗  I would say the next 20-30 would be enough. And if you can, please provide links to the PRs directly instead of commits, thank you!

Hi @qubvel,
Hope you are doing great aswell, here is the next batch ! I opened 10 PRs, the next ones have less than 100 downloads, should I include them ?

- [x] 0 Model: isalia99/detr-resnet-50-sku110k
Created: 2024-03-14 15:12:44+00:00
Downloads: `5155`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/isalia99/detr-resnet-50-sku110k/discussions/2)

- [ ] 1 Model: aParadigmP/table-transformer-detection-custom-ale
Created: 2023-11-03 12:38:33+00:00
Downloads: `3906`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/aParadigmP/table-transformer-detection-custom-ale/discussions/1)

- [ ] 2 Model: nickmuchi/yolos-small-finetuned-license-plate-detection
Created: 2022-08-18 13:21:39+00:00
Downloads: `3790`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/nickmuchi/yolos-small-finetuned-license-plate-detection/discussions/6)

- [ ] 3 Model: facebook/detr-resnet-101-dc5
Created: 2022-03-02 23:29:05+00:00
Downloads: `3472`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/facebook/detr-resnet-101-dc5/discussions/4)

- [ ] 4 Model: facebook/detr-resnet-50-dc5
Created: 2022-03-02 23:29:05+00:00
Downloads: `3191`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/facebook/detr-resnet-50-dc5/discussions/3)

- [ ] 5 Model: nickmuchi/yolos-small-rego-plates-detection
Created: 2022-07-07 21:31:21+00:00
Downloads: `2568`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/nickmuchi/yolos-small-rego-plates-detection/discussions/3)

- [ ] 6 Model: hilmantm/detr-traffic-accident-detection
Created: 2024-01-22 14:35:40+00:00
Downloads: `669`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/hilmantm/detr-traffic-accident-detection/discussions/1)

- [ ] 7 Model: Omnifact/conditional-detr-resnet-101-dc5
Created: 2024-03-26 22:35:56+00:00
Downloads: `263`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/Omnifact/conditional-detr-resnet-101-dc5/discussions/2)

- [ ] 8 Model: nickmuchi/yolos-small-plant-disease-detection
Created: 2022-11-04 12:18:11+00:00
Downloads: `182`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/nickmuchi/yolos-small-plant-disease-detection/discussions/11)

- [ ] 9 Model: nickmuchi/detr-resnet50-license-plate-detection
Created: 2022-08-23 17:44:21+00:00
Downloads: `129`
PR: [[Clean-up] Planned removal of the `max_size` argument](https://huggingface.co/nickmuchi/detr-resnet50-license-plate-detection/discussions/4)


Thank you, 10 is enough! We also need to check the other tags, e.g. `zero-shot-object-detection`, there might be a max_size too

Hi @qubvel,
That's a good point! I looked at other tags and found that the following tags can have the `max_size` parameter in the `preprocess_config` file:

- [x] object-detection
- [ ] image segmentation
- [ ] text-image

I'll try to look in the code to see exactly where it's used and whether I may need to remove some parts as we did for object detection. 

However, I can confirm that none of the `zero-shot-object-detection` models or other tags have the `max_size` parameter in the configurations, but some of them have `size` as a number and not as a dict. I don't know what we want, do we want to normalize the code or not? I may have to investigate the code a little further to see what's in there and see if it might be good or not.

Hi @HichTala! Thanks a lot for investigating it. Let's limit the scope for `max_size` now, integer `size` is fine 👍