Views
No views yet
pip install promptcap1import torch
2from promptcap import PromptCap
3
4model = PromptCap("tifa-benchmark/promptcap-coco-vqa") # also support OFA checkpoints. e.g. "OFA-Sys/ofa-large"
5
6if torch.cuda.is_available():
7 model.cuda()
8
9prompt = "please describe this image according to the given question: what piece of clothing is this boy putting on?"
10image = "glove_boy.jpeg"
11
12print(model.caption(prompt, image))1prompt = "what does the image describe?"
2image = "glove_boy.jpeg"
3
4print(model.caption(prompt, image))1prompt = "please describe this image according to the given question: what year was this taken?"
2image = "dvds.jpg"
3ocr = "yip AE Mht juor 02/14/2012"
4
5print(model.caption(prompt, image, ocr))1import torch
2from promptcap import PromptCap_VQA
3
4# QA model support all UnifiedQA variants. e.g. "allenai/unifiedqa-v2-t5-large-1251000"
5vqa_model = PromptCap_VQA(promptcap_model="tifa-benchmark/promptcap-coco-vqa", qa_model="allenai/unifiedqa-t5-base")
6
7if torch.cuda.is_available():
8 vqa_model.cuda()
9
10question = "what piece of clothing is this boy putting on?"
11image = "glove_boy.jpeg"
12
13print(vqa_model.vqa(question, image))1question = "what year was this taken?"
2image = "dvds.jpg"
3ocr = "yip AE Mht juor 02/14/2012"
4
5print(vqa_model.vqa(question, image, ocr=ocr))1question = "what piece of clothing is this boy putting on?"
2image = "glove_boy.jpeg"
3choices = ["gloves", "socks", "shoes", "coats"]
4print(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}
}