เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

VQA with Vision Language Transformers (ViLTs)

Time to have a go with multi-modal generation, starting with Visual Question-Answering (VQA). You will use the dandelin/vilt-b32-finetuned-vqa model to determine the color of the traffic light in the following image:

Picture of a traffic light showing red

The preprocessor (processor), model (model), and image (image) have been loaded for you.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Multi-Modal Models with Hugging Face

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Preprocess the text prompt and image.
  • Generate the answer tokens from the model and assign to outputs.
  • Find the ID of the answer with the highest confidence using the output logits.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

text = "What color is the traffic light?"

# Preprocess the text prompt and image
encoding = ____(____, ____, return_tensors="pt")

# Generate the answer tokens
outputs = ____

# Find the ID of the answer with the highest confidence
idx = outputs.logits.____
print("Predicted answer:", model.config.id2label[idx])
แก้ไขและรันโค้ด