模型:

Salesforce/blip-itm-base-flickr

英文

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

BLIP 在图像-文本匹配上训练,基于 ViT 基础骨干架构训练于 Flickr30k 数据集。

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

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-flickr")
model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-base-flickr").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-flickr")
model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-base-flickr", 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}
}