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

Add LlavaImageProcessor #33191

Merged
merged 22 commits into from
Jan 21, 2025

Conversation

NielsRogge
Copy link
Contributor

@NielsRogge NielsRogge commented Aug 29, 2024

What does this PR do?

Fixes #33175. It adds the option to pad an image before applying the same preprocessing as CLIPImageProcessor based on the original implementation. This allows people to match the logits with the original implementation.

For now I decided to set do_pad to False by default as otherwise it would be a breaking change.

To do:

  • update padding method to take numpy as input and produce numpy as output
  • add equivalence test
  • add tests

@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.

Copy link
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me! Wondering if we need to add a small tip section in the docs, to make users aware of padding (in case they want to enable 100% match with original impl)?

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!

Main comment is about proper testing

self.assertEqual(image_processor.crop_size, {"height": 84, "width": 84})

# Ignore copy
def test_padding(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be more thoroughly tested namely - it needs to test:

  • background colour is properly set when background_color is a non-default int, or a non-default tuple
  • the method works as expected for both channels first and channels last inputs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @zucchini-nlp could you take this up?

Copy link
Member

Choose a reason for hiding this comment

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

oke, no prob, I will come back on this tomorrow

@hljjjmssyh
Copy link

Is there any update for this feature? It seems very important for aligning implementations between Hugging Face and the official ones.

@zucchini-nlp zucchini-nlp requested a review from qubvel January 21, 2025 10:00
Copy link
Member

@qubvel qubvel left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me, just a few comments

zucchini-nlp and others added 2 commits January 21, 2025 11:38
Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
@zucchini-nlp zucchini-nlp merged commit 78f5ee0 into huggingface:main Jan 21, 2025
25 checks passed
bursteratom pushed a commit to bursteratom/transformers that referenced this pull request Jan 31, 2025
* First draft

* Add equivalence test

* Update docstrings

* Add tests

* Use numpy

* Fix tests

* Improve variable names

* Improve docstring

* Add link

* Remove script

* Add copied from

* Address comment

* Add note in docs

* Add docstring, data format

* Improve test

* Add test

* update

* Update src/transformers/models/llava/image_processing_llava.py

Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>

* Update src/transformers/models/llava/image_processing_llava.py

Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>

* loop once only

---------

Co-authored-by: raushan <raushan@huggingface.co>
Co-authored-by: Raushan Turganbay <raushan.turganbay@alumni.nu.edu.kz>
Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
elvircrn pushed a commit to elvircrn/transformers that referenced this pull request Feb 13, 2025
* First draft

* Add equivalence test

* Update docstrings

* Add tests

* Use numpy

* Fix tests

* Improve variable names

* Improve docstring

* Add link

* Remove script

* Add copied from

* Address comment

* Add note in docs

* Add docstring, data format

* Improve test

* Add test

* update

* Update src/transformers/models/llava/image_processing_llava.py

Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>

* Update src/transformers/models/llava/image_processing_llava.py

Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>

* loop once only

---------

Co-authored-by: raushan <raushan@huggingface.co>
Co-authored-by: Raushan Turganbay <raushan.turganbay@alumni.nu.edu.kz>
Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supporting Padding in llava processor
6 participants