🚀 BLIP:用于统一视觉语言理解和生成的语言 - 图像预训练引导
BLIP是一个新的视觉语言预训练(VLP)框架,能够灵活地迁移到视觉语言理解和生成任务中。它通过引导字幕有效地利用了嘈杂的网络数据,在一系列视觉语言任务上取得了最先进的成果,还在零样本迁移到视频语言任务时表现出强大的泛化能力。
🚀 快速开始
本模型可用于有条件和无条件的图像字幕生成。
使用PyTorch模型
在CPU上运行模型
点击展开
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
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')
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))
inputs = processor(raw_image, return_tensors="pt")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
在GPU上运行模型
全精度
点击展开
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large").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')
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))
inputs = processor(raw_image, return_tensors="pt").to("cuda")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
半精度 (float16
)
点击展开
import torch
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large", 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')
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))
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
✨ 主要特性
- 灵活迁移:能够灵活地迁移到视觉语言理解和生成任务。
- 有效利用数据:通过引导字幕有效地利用嘈杂的网络数据。
- 先进成果:在一系列视觉语言任务上取得了最先进的成果。
- 强大泛化:在零样本迁移到视频语言任务时表现出强大的泛化能力。
📚 详细文档
模型概述
该模型是在COCO数据集上预训练的图像字幕生成模型,采用了基础架构(带有ViT大骨干网络)。
关键论文解读
来自论文《BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation》的作者在摘要中指出:
视觉语言预训练(VLP)提升了许多视觉语言任务的性能。然而,大多数现有的预训练模型仅在基于理解的任务或基于生成的任务中表现出色。此外,性能的提升主要是通过扩大从网络收集的嘈杂图像 - 文本对数据集来实现的,而网络数据是次优的监督来源。在本文中,作者提出了BLIP,一个新的VLP框架,它可以灵活地迁移到视觉语言理解和生成任务中。BLIP通过引导字幕有效地利用了嘈杂的网络数据,其中一个字幕生成器生成合成字幕,一个过滤器去除嘈杂的字幕。作者在广泛的视觉语言任务上取得了最先进的结果,如图像 - 文本检索(平均召回率@1提高2.7%)、图像字幕生成(CIDEr提高2.8%)和视觉问答(VQA分数提高1.6%)。BLIP在以零样本方式直接迁移到视频语言任务时也表现出强大的泛化能力。代码、模型和数据集均已发布。
📄 许可证
本项目采用BSD 3 - 条款许可证。
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}
}
属性 |
详情 |
模型类型 |
图像字幕生成模型 |
训练数据 |
COCO数据集 |