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 Image To Text Generation pipeline #18821

Merged

Conversation

OlivierDehaene
Copy link
Member

@OlivierDehaene OlivierDehaene commented Aug 30, 2022

What does this PR do?

Add Image To Text Generation pipeline. The pipeline currently defaults to nlpconnect/vit-gpt2-image-captioning.

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?

This features was asked for by @Narsil.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Aug 30, 2022

The documentation is not available anymore as the PR was closed or merged.

@OlivierDehaene OlivierDehaene force-pushed the image-2-text-generation-pipeline branch 2 times, most recently from 7eaba04 to c687369 Compare August 31, 2022 13:28
@OlivierDehaene OlivierDehaene marked this pull request as ready for review August 31, 2022 13:31
Copy link
Contributor

@Narsil Narsil left a comment

Choose a reason for hiding this comment

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

Very nice first PR.

It looks very nice already.

@mishig25 I don't think we have a widget for text-to-image, do we ? Do you think we could add one ?

@sgugger for a second opinion on this pipeline.

src/transformers/pipelines/image2text_generation.py Outdated Show resolved Hide resolved
src/transformers/pipelines/image2text_generation.py Outdated Show resolved Hide resolved
src/transformers/pipelines/image2text_generation.py Outdated Show resolved Hide resolved
tests/pipelines/test_pipelines_image2text_generation.py Outdated Show resolved Hide resolved
tests/pipelines/test_pipelines_image2text_generation.py Outdated Show resolved Hide resolved
src/transformers/pipelines/__init__.py Show resolved Hide resolved
@OlivierDehaene OlivierDehaene force-pushed the image-2-text-generation-pipeline branch from 8bdb156 to ac3dabc Compare August 31, 2022 17:28
# parse inputs. In the Tensorflow version, `generate` raises an error if we don't use `input_ids` whereas
# the PyTorch version matches it with `self.model.main_input_name` or `self.model.encoder.main_input_name`
# in the `_prepare_model_inputs` method.
inputs = model_inputs.pop(self.model.main_input_name)
Copy link
Member Author

Choose a reason for hiding this comment

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

@Narsil,
What do you think of this? The issue is that model_inputs is a dict with only a pixel_values entry. While PyTorch generate utils is able to understand that pixel_values must be matched with the encoder input, Tensorflow's isn't.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a nice workaround.

It would be better if it wasn't there, I would ask @gante about this (Worked on TF generate quite extensively).
I expect it's a TF limit that it needs to be consistent in the naming hence the issue about input_ids.

But maybe there's cleaner code overall to be done in the lib.

Copy link
Member

Choose a reason for hiding this comment

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

Hi @OlivierDehaene @Narsil 👋 This seems to be a limitation on the TF generation side. I've taken note of the issue, including the removal of this line :D

Copy link
Collaborator

@sgugger sgugger 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 this new pipeline!

Copy link
Contributor

@Narsil Narsil left a comment

Choose a reason for hiding this comment

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

LGTM

@sgugger sgugger merged commit ddb69e5 into huggingface:main Sep 1, 2022
@NielsRogge
Copy link
Contributor

NielsRogge commented Sep 1, 2022

cc @mishig25, the inference widgets for models like TrOCR, Donut, image captioning can now be created! 🥳

oneraghavan pushed a commit to oneraghavan/transformers that referenced this pull request Sep 26, 2022
* Add Image2TextGenerationPipeline to supported pipelines

* Add Flax and Tensorflow support

* Add Flax and Tensorflow small tests

* Add default model for Tensorflow

* Add docstring

* Fix doc style

* Add tiny models for pytorch and flax

* Remove flax from pipeline.
Fix tests

* Use ydshieh/vit-gpt2-coco-en as a default for both PyTorch and Tensorflow

* Fix Tensorflow support

Co-authored-by: Olivier Dehaene <olivier@huggingface.co>
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.

None yet

7 participants