Skip to content

Abstract image processor arg checks.#28843

Merged
molbap merged 23 commits into
huggingface:mainfrom
molbap:refactor_image_processor_arg_check
Feb 20, 2024
Merged

Abstract image processor arg checks.#28843
molbap merged 23 commits into
huggingface:mainfrom
molbap:refactor_image_processor_arg_check

Conversation

@molbap

@molbap molbap commented Feb 2, 2024

Copy link
Copy Markdown
Collaborator

What does this PR do?

This refactors existing image processor argument checks that sprawl out on all existing models that have an ImageProcessor.
Lines such as

        if do_resize is not None and size is None:
            raise ValueError("Size and max_size must be specified if do_resize is True.")

        if do_rescale is not None and rescale_factor is None:
            raise ValueError("Rescale factor must be specified if do_rescale is True.")

        if do_normalize is not None and (image_mean is None or image_std is None):
            raise ValueError("Image mean and std must be specified if do_normalize is True.")

can be abstracted away in a validate... function residing in image_utils.
Also, fixing (when it doesn't break BC) some cases where existence of arguments is checked, but the actual preprocess method doesn't seem to call them. bridgetower doesn't pass center_crop from init, chinese_clip does not convert_to_rgb, and so on.

Who can review?

@amyeroberts

@molbap

molbap commented Feb 2, 2024

Copy link
Copy Markdown
Collaborator Author

Also linked to #28711 as I discovered logic flow issues here, seems fitting to abstract them separately and deal with the actual processing in the main PR. Here I'll try to stick to verifications and fix what's necessary to satisfy existing tests.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@amyeroberts amyeroberts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - so much tidier 🤩 Thanks for abstracting this out!

Let me know when it's ready for final review

Comment thread src/transformers/models/chinese_clip/image_processing_chinese_clip.py Outdated
@molbap molbap marked this pull request as ready for review February 9, 2024 17:02

@amyeroberts amyeroberts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for working on this and tidying all this code up 🧹 🧹 🧹

Just a few small comments

Comment thread src/transformers/image_utils.py Outdated
Comment thread src/transformers/models/bit/image_processing_bit.py Outdated
Comment thread src/transformers/models/blip/image_processing_blip.py Outdated
Comment thread src/transformers/models/bridgetower/image_processing_bridgetower.py Outdated
Comment thread src/transformers/models/bridgetower/image_processing_bridgetower.py Outdated
Comment thread src/transformers/models/bridgetower/image_processing_bridgetower.py Outdated
Comment thread src/transformers/models/bridgetower/image_processing_bridgetower.py Outdated
Comment thread src/transformers/models/bridgetower/image_processing_bridgetower.py Outdated
Comment thread src/transformers/models/bridgetower/image_processing_bridgetower.py
Comment thread src/transformers/models/chinese_clip/image_processing_chinese_clip.py Outdated
molbap and others added 12 commits February 11, 2024 14:34
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
@molbap molbap changed the title WIP: abstract image processor arg checks. Abstract image processor arg checks. Feb 12, 2024
@molbap

molbap commented Feb 15, 2024

Copy link
Copy Markdown
Collaborator Author

@amyeroberts I think it's ok to take another look at this one now! Improved a few things, didn't add much, will rebase the other refactor off of that one

@amyeroberts amyeroberts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - thanks for working on this!

Comment thread src/transformers/models/efficientformer/image_processing_efficientformer.py Outdated
Comment thread src/transformers/models/mobilevit/image_processing_mobilevit.py
Comment thread src/transformers/models/bridgetower/image_processing_bridgetower.py Outdated
Comment thread src/transformers/models/sam/image_processing_sam.py
molbap and others added 2 commits February 16, 2024 10:40
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
@molbap molbap merged commit 1c9134f into huggingface:main Feb 20, 2024
This was referenced Feb 27, 2024
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.

3 participants