模型:

Salesforce/blip-itm-base-coco

英文

BLIP: 用于统一的视觉-语言理解和生成的引导式语言-图像预训练

用于在图像-文本匹配上训练的BLIP模型卡 - 基于COCO数据集训练的基本架构(具有ViT基础骨干网络)。

1234321
Pull figure from BLIP official repo

TL;DR

作者们在摘要中写道: paper

视觉-语言预训练(VLP)已经提升了许多视觉-语言任务的性能。然而,大多数现有的预训练模型在理解型任务或生成型任务中表现突出。此外,通过扩大使用从网络收集的带有噪声的图像-文本对数据集来提高性能,这是一种次优的监督来源。在本文中,我们提出了BLIP,这是一种新的VLP框架,可以灵活地转向视觉-语言理解和生成任务。BLIP通过引导生成字幕的方式有效地利用噪声网络数据,其中字幕生成器生成合成字幕,然后过滤器删除噪声字幕。我们在广泛的视觉-语言任务上取得了最先进的结果,例如图像-文本检索(平均召回率@1提升2.7%)、图像字幕生成(CIDEr提升2.8%)和VQA(VQA分数提升1.6%)。BLIP还展示了强大的泛化能力,能够直接以零-shot方式转移到视频-语言任务。代码、模型和数据集已发布。

用法

您可以将此模型用于有条件和无条件的图像字幕生成

使用Pytorch模型

在CPU上运行模型 点击展开
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForImageTextRetrieval

processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-base-coco")
model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-base-coco")

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')

question = "A woman and a dog sitting together in a beach."
inputs = processor(raw_image, question, return_tensors="pt")

itm_scores = model(**inputs)[0]
cosine_score = model(**inputs, use_itm_head=False)[0]
在GPU上运行模型 使用全精度 点击展开
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForImageTextRetrieval

processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-base-coco")
model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-base-coco").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')

question = "A woman and a dog sitting together in a beach."
inputs = processor(raw_image, question, return_tensors="pt").to("cuda")

itm_scores = model(**inputs)[0]
cosine_score = model(**inputs, use_itm_head=False)[0]
使用半精度(float16) 点击展开
import torch
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForImageTextRetrieval

processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-base-coco")
model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-base-coco", 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')

question = "A woman and a dog sitting together in a beach."
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16)

itm_scores = model(**inputs)[0]
cosine_score = model(**inputs, use_itm_head=False)[0]

BibTex和引用信息

@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}
}