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

Pipeline VQA: Add support for list of images and questions as pipeline input #31217

Merged

Conversation

BlacCod
Copy link
Contributor

@BlacCod BlacCod commented Jun 3, 2024

What does this PR do?

Fixes #31216

This PR will allow passing list of either PIL.Image or str as pipeline argument (and list[str] for questions). Passing dataset (in form of .pt_utils.KeyDataset) is also allowed.
So this code will now work (passing the dataset as list)

from transformers import pipeline
dataset = datasets.load_dataset("frgfm/imagenette", "full_size", "validation[:10]")
oracle = pipeline(task="vqa", model="dandelin/vilt-b32-finetuned-vqa")
oracle(question="What's in this image?", image=dataset['image'], top_k=1)

This also works:

from transformers.pipelines.pt_utls import KeyDataset

oracle(question="What's in this image?", image=KeyDataset(dataset, "image"), top_k=1)

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?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

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 this capability!

Seems like something which would be useful to have. Alongside the logic, there's a few things we should add alongside:

  • Update docstrings to reflect the new input types
  • Add tests for the new input types

@BlacCod
Copy link
Contributor Author

BlacCod commented Jun 4, 2024

Hi @amyeroberts, thank you for reviewing :) I added the tests and docstrings
As for the docstring, I assume you mean the comments inside the function? There isn't much to update there (the original author wrote the "correct" documentation, but did not implement everything for some reason).

@BlacCod
Copy link
Contributor Author

BlacCod commented Jun 4, 2024

Found and fixed the problem with the dataset :) Now dataset (in form of KeyDataset, to stay consistent with this tutorial) as input for image is accepted

@BlacCod BlacCod requested a review from amyeroberts June 5, 2024 10:25
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.

Great - thanks for adding this!

@amyeroberts
Copy link
Collaborator

Thanks again for this contribution!

@amyeroberts amyeroberts merged commit f929624 into huggingface:main Jun 6, 2024
18 checks passed
@BlacCod BlacCod deleted the vqa-pipeline-accept-list-as-input branch June 6, 2024 17:14
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.

[pipeline] VQA pipeline does not accept list as input
2 participants