🚀 PromptCap:基于提示引导的图像描述模型
PromptCap是一个可由自然语言指令控制的图像描述模型,能够处理图像描述、视觉问答等任务。它可以作为轻量级视觉插件与大语言模型结合使用,在COCO图像描述和基于知识的视觉问答任务中取得了优异的成绩。
🚀 快速开始
✨ 主要特性
- 自然语言指令控制:支持通过自然语言指令控制模型,指令中可包含用户感兴趣的问题,例如“这个男孩正在穿什么衣服?”。
- 通用描述支持:支持通用的图像描述,使用问题“图像描述了什么?”即可。
- 轻量级视觉插件:可作为轻量级视觉插件与GPT - 3、ChatGPT等大语言模型以及Segment Anything、DINO等基础模型配合使用,速度比BLIP - 2快很多。
- 优异性能:在COCO图像描述任务中达到了SOTA性能(150 CIDEr),与GPT - 3结合并基于用户问题时,在基于知识的视觉问答任务中取得了SOTA性能(OK - VQA上60.4%,A - OKVQA上59.6%)。
📦 安装指南
pip install promptcap
💻 使用示例
基础用法
本项目包含两个管道,一个用于图像描述,另一个用于视觉问答。
图像描述管道
请遵循提示格式,以获得最佳性能。按照以下步骤生成提示引导的图像描述:
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))
视觉问答管道
与典型的在VQAv2上进行分类的视觉问答模型不同,PromptCap是开放域的,可以与任意文本问答模型配合使用。这里提供了一个将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还支持多项选择视觉问答:
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))
📚 详细文档
这是论文 PromptCap: Prompt-Guided Task-Aware Image Captioning 的代码仓库。该论文以 PromptCap: Prompt-Guided Image Captioning for VQA with GPT-3 为题被ICCV 2023收录。
📄 许可证
本项目采用OpenRail许可证。
🔍 信息表格
属性 |
详情 |
模型类型 |
图像到文本 |
训练数据 |
COCO、TextVQA、VQAv2、OK - VQA、A - OKVQA |
📖 BibTeX引用
@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}
}