Views
No views yet
from transformers import ViltProcessor, ViltForImagesAndTextClassification
import requests
from PIL import Image
image = Image.open(requests.get("https://camo.githubusercontent.com/ffcbeada14077b8e6d4b16817c91f78ba50aace210a1e4754418f1413d99797f/687474703a2f2f696d616765732e636f636f646174617365742e6f72672f747261696e323031372f3030303030303038303333362e6a7067", stream=True).raw)
text = "The person is ahead of the cow."
processor = ViltProcessor.from_pretrained("juletxara/vilt-vsr-random")
model = ViltForImagesAndTextClassification.from_pretrained("juletxara/vilt-vsr-random")
# prepare inputs
encoding = processor(image, text, return_tensors="pt")
# forward pass
outputs = model(input_ids=encoding.input_ids, pixel_values=encoding.pixel_values.unsqueeze(0))
logits = outputs.logits
idx = logits.argmax(-1).item()
print("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}
9
10@article{liu2022visual,
11 title={Visual Spatial Reasoning},
12 author={Liu, Fangyu and Emerson, Guy and Collier, Nigel},
13 journal={arXiv preprint arXiv:2205.00363},
14 year={2022}
15}