Skip to content
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

Make image processors more general #27690

Merged

Conversation

NielsRogge
Copy link
Contributor

@NielsRogge NielsRogge commented Nov 24, 2023

What does this PR do?

This PR undoes #26965 and instead makes image processors more general, by removing the hardcoded "shortest_side" arguments, allowing to pass the following to image processors:

size = {"height": ..., "width": ...}
size = {"shortest_edge": ...}

Ideally it should also allow for the following (cc @amyeroberts)

size = {"longest_edge": ...}
size = {"shortest_edge": ..., "longest_edge": ...}

Image processors should not be limited to only {"shortest_edge": ...} for instance, as CLIPImageProcessor is at the moment. The size argument is now always a dictionary containing one of these 4 possibilities; hence it would be great to support them all.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@amyeroberts
Copy link
Collaborator

Thanks for opening this PR!

Ideally it should also allow for the following (cc @amyeroberts)

size = {"longest_edge": ...}
size = {"shortest_edge": ..., "longest_edge": ...}

As discussed on slack, enabling all image processors to accept {"height": h, "width": w} is a change I'm very much pro. Enabling all to accept {"shortest_edge": x, "longest_edge": y} isn't something I think we should as this behaviour isn't well-defined and varies between models.

@NielsRogge
Copy link
Contributor Author

NielsRogge commented Nov 26, 2023

cc @ydshieh this is failing for KOSMOS-2 - it would be great to revert that change for KOSMOS-2 (i.e. remove the "use_square_size" attribute) since this is introduced for legacy behaviour of size (which used to be an integer and is now a dictionary).

@ArthurZucker
Copy link
Collaborator

It did but it's also very convenient not to have to use copied from when the only difference was this, so reverting IMO is not the best solution. Let's rather adapt / make it compatible

@NielsRogge NielsRogge mentioned this pull request Nov 27, 2023
3 tasks
@ydshieh
Copy link
Collaborator

ydshieh commented Nov 27, 2023

Reverting #26965 means we well have to add Kosmos2ImageProcessor (while currently it is CLIPImageProcessor with use_square_size=True). Probably it will go without problem, but still kind of breaking changes.

@NielsRogge
Copy link
Contributor Author

@ydshieh would it also be possible to just set size to {"height": ..., "width" ...}? With this PR, image processors are made more general, making sure square sizes are supported

@ydshieh
Copy link
Collaborator

ydshieh commented Nov 27, 2023

Hi, could you give more details on

set size to {"height": ..., "width" ...}

(where should I set this, for example.)

Do you mean on the config file?

@NielsRogge NielsRogge force-pushed the make_image_processors_more_general branch from f9a2b1f to 135bc9d Compare November 27, 2023 14:17
@NielsRogge
Copy link
Contributor Author

Yes I meant in the preprocessor_config.json. Given that the model is only one month old, we could still update them. Alternatively, I've added a backwards compatibility in this PR, only for CLIPImageProcessor. Let me know what you think works best.

@ydshieh
Copy link
Collaborator

ydshieh commented Nov 27, 2023

We can keep your backwards compatibility code, and I could try to open Hub PRs to update them.
Let's also hear what the core maintainers say of course.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Looks like a better and more general solution so in favor, I'll let @amyeroberts review when she comes back unless it's urgent! 😉

@NielsRogge
Copy link
Contributor Author

It's required to merge #27718

Copy link
Collaborator

@amyeroberts amyeroberts 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 adding!

The test file will need to be removed before merging - otherwise looks good!

src/transformers/models/test.py Outdated Show resolved Hide resolved
@NielsRogge NielsRogge force-pushed the make_image_processors_more_general branch from 1dfef5c to bd71da3 Compare December 4, 2023 17:36
@ydshieh
Copy link
Collaborator

ydshieh commented Dec 5, 2023

Merge now as full (slow) CI on 4 models touched by this PR pass

@ydshieh ydshieh merged commit df40edf into huggingface:main Dec 5, 2023
4 checks passed
@ArthurZucker
Copy link
Collaborator

cc @younesbelkada we have a regression on this

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.

5 participants