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

VQA ด้วย Vision Language Transformers (ViLTs)

มาลองใช้งาน multi-modal generation กัน โดยเริ่มต้นด้วย Visual Question-Answering (VQA) จะใช้โมเดล dandelin/vilt-b32-finetuned-vqa เพื่อระบุสีของสัญญาณไฟจราจรในภาพต่อไปนี้:

Picture of a traffic light showing red

ตัวประมวลผลล่วงหน้า (processor), โมเดล (model) และภาพ (image) ถูกโหลดให้แล้ว

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

โมเดล Multi-Modal ด้วย Hugging Face

ดูคอร์ส

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

  • ประมวลผลล่วงหน้า (preprocess) text prompt และ image
  • สร้าง answer tokens จากโมเดล แล้วกำหนดค่าให้กับ outputs
  • หา ID ของคำตอบที่มีความมั่นใจสูงสุดโดยใช้ 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])
แก้ไขและรันโค้ด