模型简介
模型特点
模型能力
使用案例
🚀 BLIP: 用于统一视觉语言理解与生成的语言 - 图像预训练引导
BLIP是一个在COCO数据集上预训练的图像描述模型(基于ViT大骨干网络的基础架构),能够灵活迁移到视觉 - 语言理解和生成任务,在多种视觉语言任务中取得了先进的成果。
🚀 快速开始
模型用途
你可以使用此模型进行条件和无条件的图像描述。
✨ 主要特性
- 灵活迁移:能够灵活迁移到视觉 - 语言理解和生成任务。
- 有效利用数据:通过引导字幕有效利用嘈杂的网络数据,其中字幕生成器生成合成字幕,过滤器去除嘈杂的字幕。
- 先进性能:在广泛的视觉 - 语言任务中取得了最先进的结果,如图文检索(平均召回率@1提高2.7%)、图像描述(CIDEr提高2.8%)和视觉问答(VQA分数提高1.6%)。
- 强泛化能力:在零样本方式下直接迁移到视频 - 语言任务时表现出强大的泛化能力。
📦 安装指南
文档未提及安装步骤,暂不展示。
💻 使用示例
基础用法
使用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))
# >>> a photography of a woman and her dog
# 无条件图像描述
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
📚 详细文档
论文概述
论文作者在摘要中写道:
视觉 - 语言预训练(VLP)提升了许多视觉 - 语言任务的性能。然而,大多数现有的预训练模型仅在基于理解的任务或基于生成的任务中表现出色。此外,性能的提升很大程度上是通过扩大从网络收集的嘈杂图像 - 文本对数据集来实现的,而网络数据是一种次优的监督来源。在本文中,我们提出了BLIP,一个新的VLP框架,它可以灵活地迁移到视觉 - 语言理解和生成任务。BLIP通过引导字幕有效利用嘈杂的网络数据,其中字幕生成器生成合成字幕,过滤器去除嘈杂的字幕。我们在广泛的视觉 - 语言任务中取得了最先进的结果,如图文检索(平均召回率@1提高2.7%)、图像描述(CIDEr提高2.8%)和视觉问答(VQA分数提高1.6%)。BLIP在零样本方式下直接迁移到视频 - 语言任务时也表现出强大的泛化能力。代码、模型和数据集已发布。
伦理考量
本版本仅用于支持学术论文的研究目的。我们的模型、数据集和代码并非专门为所有下游用途而设计或评估。我们强烈建议用户在部署此模型之前评估并解决与准确性、安全性和公平性相关的潜在问题。我们鼓励用户考虑人工智能的常见局限性,遵守适用法律,并在选择用例时采用最佳实践,特别是在错误或滥用可能对人们的生活、权利或安全产生重大影响的高风险场景中。有关用例的进一步指导,请参考我们的AUP和AI AUP。
🔧 技术细节
文档未提及技术实现细节,暂不展示。
📄 许可证
本模型使用的许可证为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数据集 |
⚠️ 重要提示
本版本仅用于支持学术论文的研究目的。我们的模型、数据集和代码并非专门为所有下游用途而设计或评估。建议用户在部署此模型之前评估并解决与准确性、安全性和公平性相关的潜在问题。
💡 使用建议
考虑人工智能的常见局限性,遵守适用法律,并在选择用例时采用最佳实践,特别是在错误或滥用可能对人们的生活、权利或安全产生重大影响的高风险场景中。有关用例的进一步指导,请参考AUP和AI AUP。
![]() |
---|
图片来自BLIP官方仓库 |








