模型:

Salesforce/blip-itm-large-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还展示了强大的泛化能力,可以直接以零样本的方式转移到视频-语言任务上。发布了代码、模型和数据集。

使用

您可以将此模型用于有条件和无条件的图像描述。

使用Pytorch模型

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

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