🚀 PromptCap: 自然言語指示による画像キャプショニングモデル
自然言語指示で制御可能な画像キャプショニングモデルで、VQAや画像キャプショニングタスクで高い性能を発揮します。
🚀 クイックスタート
このリポジトリは、論文 PromptCap: Prompt-Guided Task-Aware Image Captioning の実装です。この論文は、ICCV 2023に PromptCap: Prompt-Guided Image Captioning for VQA with GPT-3 として採択されました。
私たちは、自然言語指示によって制御可能なキャプショニングモデルであるPromptCapを導入します。この指示には、ユーザーが興味を持っている質問が含まれる場合があります。例えば、「この少年は何を着ていますか?」などです。PromptCapは、「この画像は何を表していますか?」という質問を使用して、一般的なキャプションもサポートします。
PromptCapは、GPT-3、ChatGPTなどの大規模言語モデルや、Segment AnythingやDINOなどの他の基盤モデルに対する軽量な視覚プラグインとして機能します(BLIP-2よりもはるかに高速です)。COCOキャプショニングタスクでSOTAの性能を達成し(150 CIDEr)、GPT-3と組み合わせてユーザーの質問に基づく場合、知識ベースのVQAタスクでもSOTAの性能を発揮します(OK-VQAで60.4%、A-OKVQAで59.6%)。
📦 インストール
pip install promptcap
2つのパイプラインが含まれています。1つは画像キャプショニング用で、もう1つは視覚的質問応答用です。
💻 使用例
基本的な使用法
キャプショニングパイプライン
ベストな性能を得るために、プロンプト形式に従ってください。
import torch
from promptcap import PromptCap
model = PromptCap("tifa-benchmark/promptcap-coco-vqa")
if torch.cuda.is_available():
model.cuda()
prompt = "please describe this image according to the given question: what piece of clothing is this boy putting on?"
image = "glove_boy.jpeg"
print(model.caption(prompt, image))
一般的なキャプショニングを試すには、「what does the image describe?」を使用します。
prompt = "what does the image describe?"
image = "glove_boy.jpeg"
print(model.caption(prompt, image))
PromptCapは、OCR入力もサポートしています。
prompt = "please describe this image according to the given question: what year was this taken?"
image = "dvds.jpg"
ocr = "yip AE Mht juor 02/14/2012"
print(model.caption(prompt, image, ocr))
視覚的質問応答パイプライン
典型的なVQAモデルがVQAv2で分類を行うのとは異なり、PromptCapはオープンドメインであり、任意のテキストQAモデルと組み合わせることができます。ここでは、PromptCapとUnifiedQAを組み合わせるためのパイプラインを提供します。
import torch
from promptcap import PromptCap_VQA
vqa_model = PromptCap_VQA(promptcap_model="tifa-benchmark/promptcap-coco-vqa", qa_model="allenai/unifiedqa-t5-base")
if torch.cuda.is_available():
vqa_model.cuda()
question = "what piece of clothing is this boy putting on?"
image = "glove_boy.jpeg"
print(vqa_model.vqa(question, image))
同様に、PromptCapはOCR入力もサポートしています。
question = "what year was this taken?"
image = "dvds.jpg"
ocr = "yip AE Mht juor 02/14/2012"
print(vqa_model.vqa(question, image, ocr=ocr))
Unifiedqaの柔軟性により、PromptCapは選択式VQAもサポートしています。
question = "what piece of clothing is this boy putting on?"
image = "glove_boy.jpeg"
choices = ["gloves", "socks", "shoes", "coats"]
print(vqa_model.vqa_multiple_choice(question, image, choices))
引用情報
@article{hu2022promptcap,
title={PromptCap: Prompt-Guided Task-Aware Image Captioning},
author={Hu, Yushi and Hua, Hang and Yang, Zhengyuan and Shi, Weijia and Smith, Noah A and Luo, Jiebo},
journal={arXiv preprint arXiv:2211.09699},
year={2022}
}
📄 ライセンス
ライセンスはOpenRailです。
プロパティ |
詳細 |
パイプラインタグ |
画像からテキストへの変換 |
タグ |
画像からテキストへの変換、視覚的質問応答、画像キャプショニング |
データセット |
COCO、TextVQA、VQAv2、OK-VQA、A-OKVQA |
言語 |
英語 |