Görsel soru-cevaplama (VQA)

Hugging Face ile Multi-Modal Modeller

James Chapman

Curriculum Manager, DataCamp

Multimodal QA görevleri

Bir VQA modelinde görsel ve metin işlemesini gösteren diyagram

  1. Soru metni ve diğer modalitenin ayrı kodlanması
Hugging Face ile Multi-Modal Modeller

Multimodal QA görevleri

Bir VQA modelinde görsel ve metin işlemesini gösteren diyagram

  1. Soru metni ve diğer modalitenin ayrı kodlanması
  2. Kodlanmış özelliklerin birleştirilmesi
Hugging Face ile Multi-Modal Modeller

Multimodal QA görevleri

Bir VQA modelinde görsel ve metin işlemesini gösteren diyagram

  1. Soru metni ve diğer modalitenin ayrı kodlanması
  2. Kodlanmış özelliklerin birleştirilmesi
  3. Yanıt belirteçlerini tahmin eden ek katmanlar
Hugging Face ile Multi-Modal Modeller

VQA

import requests
from PIL import Image

url = "https://www.worldanimalprotection
.org/cdn-cgi/image/width=1920,format=
auto/globalassets/images/elephants/1
033551-elephant.jpg"


image = Image.open(requests.get(url, stream=True).raw)
text = "What animal is in this photo?"

Vahşi doğada bir fil resmi

Hugging Face ile Multi-Modal Modeller

VQA

 

  • Model birçok nesnenin görsel ve metin özelliklerini bilir
  • Ek ince ayar gerektirmeyen yeniden kullanılabilir modeller

Bir hayvana odaklanma ve kimlik tespitini gösteren diyagram

Hugging Face ile Multi-Modal Modeller

VQA

from transformers import ViltProcessor, ViltForQuestionAnswering


processor = ViltProcessor.from_pretrained("dandelin/vilt-b32-finetuned-vqa") model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
encoding = processor(image, text, return_tensors="pt")
outputs = model(**encoding)
idx = outputs.logits.argmax(-1).item()
print("Predicted answer:", model.config.id2label[idx])
Predicted answer: elephant
Hugging Face ile Multi-Modal Modeller

Belge VQA

  • Görsellerde grafikler, tablolar ve metni (OCR) algılayan VQA genişletmesi
from datasets import load_dataset
from transformers import pipeline

dataset = load_dataset("lmms-lab/DocVQA")


import matplotlib.pyplot as plt plt.imshow(dataset["test"][2]["image"]) plt.show()

Grafik ve çubuk grafik içeren belge görseli

Hugging Face ile Multi-Modal Modeller

Belge VQA

Google Tessearact logosu

  • OCR çalıştırmak için ek bağımlılıklar gerekir
  • pytesseract pip ile kurulur
  • Tesseract OCR, paket yükleyici ile (örn. apt-get, exe veya homebrew/macports)

OCR içeren kahve tabelası fotoğrafı

Hugging Face ile Multi-Modal Modeller

Belge VQA

from transformers import pipeline
pipe = pipeline("document-question-answering", "impira/layoutlm-document-qa")

result = pipe( dataset["test"][2]["image"], "What was the gross income in 2011-2012?" )
Hugging Face ile Multi-Modal Modeller

Belge VQA

print(result)
[{'score': 0.05149758607149124,
  'answer': '3 36073 Crores', ...}]

Grafik ve çubuk grafik içeren belge görseli

Hugging Face ile Multi-Modal Modeller

Hadi pratik yapalım!

Hugging Face ile Multi-Modal Modeller

Preparing Video For Download...