🚀 Pix2Struct - AI2Dでファインチューニングされたモデルカード (科学図表の視覚的質問応答)
Pix2Structは、画像キャプショニングや視覚的質問応答などの様々なタスクに対応した画像エンコーダ - テキストデコーダモデルです。このモデルはAI2Dデータセットでファインチューニングされ、科学図表の視覚的質問応答に特化しています。

📚 目次
- 要約
- モデルの使用方法
- 貢献者
- 引用
📖 要約
Pix2Structは、画像 - テキストのペアで訓練された画像エンコーダ - テキストデコーダモデルで、画像キャプショニングや視覚的質問応答などの様々なタスクに使用できます。利用可能なモデルの完全なリストは、論文の表1に記載されています。

このモデルの概要は以下の通りです。
視覚的な言語はあらゆる場所に存在します。教科書の図、ウェブページの画像や表、モバイルアプリのボタンやフォームなど、様々なソースがあります。この多様性のため、以前の研究では、基礎となるデータ、モデルアーキテクチャ、目的の共有が限られたドメイン固有の手法に依存することが多かった。我々は、視覚的な言語理解のための事前学習済み画像 - テキストモデルであるPix2Structを提案する。このモデルは、視覚的な言語を含むタスクに対してファインチューニングすることができる。Pix2Structは、ウェブページのマスクされたスクリーンショットを簡略化されたHTMLにパースすることを学習することで事前学習される。ウェブは、その豊富な視覚要素がHTML構造にきれいに反映されており、下流のタスクの多様性に適した大規模な事前学習データ源を提供する。直感的には、この目的は、OCR、言語モデリング、画像キャプショニングなどの一般的な事前学習信号を包含する。新しい事前学習戦略に加えて、我々は可変解像度の入力表現と、質問などの言語プロンプトを入力画像の上に直接レンダリングする、より柔軟な言語とビジョン入力の統合を導入する。初めて、単一の事前学習モデルが、文書、イラスト、ユーザーインターフェース、自然画像の4つのドメインにまたがる9つのタスクのうち6つで最先端の結果を達成できることを示す。
💻 モデルの使用方法
このモデルは視覚的質問応答(VQA)にファインチューニングされているため、特定の形式で質問を提供する必要があります。理想的には、選択肢付きの質問形式です。
🖥️ モデルの実行
完全精度、CPUでの実行
import requests
from PIL import Image
from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
image = Image.open(requests.get(image_url, stream=True).raw)
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-ai2d-base")
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-ai2d-base")
question = "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"
inputs = processor(images=image, text=question, return_tensors="pt")
predictions = model.generate(**inputs)
print(processor.decode(predictions[0], skip_special_tokens=True))
>>> ash cloud
完全精度、GPUでの実行
import requests
from PIL import Image
from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
image = Image.open(requests.get(image_url, stream=True).raw)
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-ai2d-base").to("cuda")
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-ai2d-base")
question = "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"
inputs = processor(images=image, text=question, return_tensors="pt").to("cuda")
predictions = model.generate(**inputs)
print(processor.decode(predictions[0], skip_special_tokens=True))
>>> ash cloud
半精度、GPUでの実行
import requests
from PIL import Image
import torch
from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
image = Image.open(requests.get(image_url, stream=True).raw)
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-ai2d-base", torch_dtype=torch.bfloat16).to("cuda")
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-ai2d-base")
question = "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"
inputs = processor(images=image, text=question, return_tensors="pt").to("cuda", torch.bfloat16)
predictions = model.generate(**inputs)
print(processor.decode(predictions[0], skip_special_tokens=True))
>>> ash cloud
⚙️ T5xからHugging Faceへの変換
convert_pix2struct_checkpoint_to_pytorch.py
スクリプトを使用して、以下のように変換できます。
python convert_pix2struct_checkpoint_to_pytorch.py --t5x_checkpoint_path PATH_TO_T5X_CHECKPOINTS --pytorch_dump_path PATH_TO_SAVE --is_vqa
大規模モデルを変換する場合は、以下のコマンドを実行します。
python convert_pix2struct_checkpoint_to_pytorch.py --t5x_checkpoint_path PATH_TO_T5X_CHECKPOINTS --pytorch_dump_path PATH_TO_SAVE --use-large --is_vqa
保存後、以下のコードで変換したモデルをHugging Face Hubにプッシュできます。
from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
model = Pix2StructForConditionalGeneration.from_pretrained(PATH_TO_SAVE)
processor = Pix2StructProcessor.from_pretrained(PATH_TO_SAVE)
model.push_to_hub("USERNAME/MODEL_NAME")
processor.push_to_hub("USERNAME/MODEL_NAME")
👥 貢献者
このモデルは、Kenton Lee、Mandar Joshiらによって最初に貢献され、Younes BelkadaによってHugging Faceエコシステムに追加されました。
📜 引用
この研究を引用する場合は、元の論文を引用してください。
@misc{https://doi.org/10.48550/arxiv.2210.03347,
doi = {10.48550/ARXIV.2210.03347},
url = {https://arxiv.org/abs/2210.03347},
author = {Lee, Kenton and Joshi, Mandar and Turc, Iulia and Hu, Hexiang and Liu, Fangyu and Eisenschlos, Julian and Khandelwal, Urvashi and Shaw, Peter and Chang, Ming-Wei and Toutanova, Kristina},
keywords = {Computation and Language (cs.CL), Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {Pix2Struct: Screenshot Parsing as Pretraining for Visual Language Understanding},
publisher = {arXiv},
year = {2022},
copyright = {Creative Commons Attribution 4.0 International}
}
属性 |
详情 |
モデルタイプ |
画像エンコーダ - テキストデコーダモデル |
訓練データ |
AI2Dデータセット |
ライセンス |
Apache-2.0 |