Views
No views yet
1from transformers import ViltProcessor, ViltForQuestionAnswering
2import requests
3from PIL import Image
4
5# prepare image + question
6url = "http://images.cocodataset.org/val2017/000000039769.jpg"
7image = Image.open(requests.get(url, stream=True).raw)
8text = "How many cats are there?"
9
10processor = ViltProcessor.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
11model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
12
13# prepare inputs
14encoding = processor(image, text, return_tensors="pt")
15
16# forward pass
17outputs = model(**encoding)
18logits = outputs.logits
19idx = logits.argmax(-1).item()
20print("Predicted answer:", model.config.id2label[idx])1@misc{kim2021vilt,
2 title={ViLT: Vision-and-Language Transformer Without Convolution or Region Supervision},
3 author={Wonjae Kim and Bokyung Son and Ildoo Kim},
4 year={2021},
5 eprint={2102.03334},
6 archivePrefix={arXiv},
7 primaryClass={stat.ML}
8}