模型:
ybelkada/blip-image-captioning-base-football-finetuned
在COCO数据集上预先训练的图像字幕模型卡片 - 基础架构(具有ViT基础骨干) - 并在 football dataset 上进行微调。
用于微调的Google Colab笔记本: https://colab.research.google.com/drive/1lbqiSiA0sDF7JDWPeS0tccrM85LloVha?usp=sharing
Pull figure from BLIP official repo |
paper 的作者在摘要中写道:
视觉-语言预训练(VLP)已经提高了许多视觉-语言任务的性能。然而,大多数现有的预训练模型仅在理解型任务或生成型任务中表现突出。此外,通过扩大从网络收集到的带有噪声的图像-文本对数据集来实现性能改进,这是一种次优的监督来源。在本文中,我们提出了BLIP,这是一种新的VLP框架,可以灵活地转移到视觉-语言理解和生成任务。BLIP通过引导生成人工字幕的方式有效地利用了网络数据,其中字幕生成器生成合成字幕,并使用过滤器去除噪声字幕。我们在广泛的视觉-语言任务上取得了最先进的结果,如图像-文本检索(平均召回率@1增加了2.7%),图像字幕(CIDEr增加了2.8%)和VQA(VQA得分增加了1.6%)等。BLIP还展示了直接在零-shot方式下转移到视频-语言任务时的强大的泛化能力。代码、模型和数据集已发布。
您可以在条件和非条件图像字幕中使用此模型。
import requests from PIL import Image from transformers import BlipProcessor, BlipForConditionalGeneration processor = BlipProcessor.from_pretrained("ybelkada/blip-image-captioning-base") model = BlipForConditionalGeneration.from_pretrained("ybelkada/blip-image-captioning-base") img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg' raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB') # conditional image captioning text = "a photography of" inputs = processor(raw_image, text, return_tensors="pt") out = model.generate(**inputs) print(processor.decode(out[0], skip_special_tokens=True)) # >>> a photography of a woman and her dog # unconditional image captioning inputs = processor(raw_image, return_tensors="pt") out = model.generate(**inputs) print(processor.decode(out[0], skip_special_tokens=True)) >>> a woman sitting on the beach with her dog在GPU上运行模型 在全精度下 点击展开
import requests from PIL import Image from transformers import BlipProcessor, BlipForConditionalGeneration processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") model = BlipForConditionalGeneration.from_pretrained("Salesfoce/blip-image-captioning-base").to("cuda") img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg' raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB') # conditional image captioning text = "a photography of" inputs = processor(raw_image, text, return_tensors="pt").to("cuda") out = model.generate(**inputs) print(processor.decode(out[0], skip_special_tokens=True)) # >>> a photography of a woman and her dog # unconditional image captioning inputs = processor(raw_image, return_tensors="pt").to("cuda") out = model.generate(**inputs) print(processor.decode(out[0], skip_special_tokens=True)) >>> a woman sitting on the beach with her dog在半精度(float16)下 点击展开
import torch import requests from PIL import Image from transformers import BlipProcessor, BlipForConditionalGeneration processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", torch_dtype=torch.float16).to("cuda") img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg' raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB') # conditional image captioning text = "a photography of" inputs = processor(raw_image, text, return_tensors="pt").to("cuda", torch.float16) out = model.generate(**inputs) print(processor.decode(out[0], skip_special_tokens=True)) # >>> a photography of a woman and her dog # unconditional image captioning inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16) out = model.generate(**inputs) print(processor.decode(out[0], skip_special_tokens=True)) >>> a woman sitting on the beach with her dog
@misc{https://doi.org/10.48550/arxiv.2201.12086, doi = {10.48550/ARXIV.2201.12086}, url = {https://arxiv.org/abs/2201.12086}, author = {Li, Junnan and Li, Dongxu and Xiong, Caiming and Hoi, Steven}, keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences}, title = {BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation}, publisher = {arXiv}, year = {2022}, copyright = {Creative Commons Attribution 4.0 International} }