模型库 / Salesforce/blip-image-captioning-base

blip-image-captioning-base

Salesforce image-to-text transformers
Salesforce/blip-image-captioning-base
2,399,250
下载量
852
收藏数
11
浏览量
bsd-3-clause
许可

简介

BLIP:面向统一视觉-语言理解与生成的语言-图像预训练引导方法

模型卡片

许可协议 bsd-3-clause
任务 image-to-text
image-captioning

模型配置

模型类型 blip
架构 BlipForConditionalGeneration

模型详情

已翻译

BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation

在 COCO 数据集上预训练的图像描述模型卡片 - 基础架构(使用 ViT base backbone)。

BLIP.gif
图片来自 BLIP 官方仓库

摘要

论文 的作者在摘要中写道:

视觉-语言预训练(VLP)已提升了众多视觉-语言任务的性能。然而,大多数现有的预训练模型仅在基于理解的任务或基于生成的任务中表现出色。此外,性能提升主要通过扩大数据集规模实现,这些数据来自网络收集的带噪声图像-文本对,这是一种次优的监督来源。在本文中,我们提出 BLIP,一种新的 VLP 框架,能够灵活迁移到视觉-语言理解和生成任务。BLIP 通过 bootstrapping 描述有效利用噪声网络数据,其中 captioner 生成合成描述,filter 移除噪声描述。我们在广泛的视觉-语言任务上取得了最先进的结果,例如图像-文本检索(平均 recall@1 提升 +2.7%)、图像描述(CIDEr 提升 +2.8%)和 VQA(VQA 分数提升 +1.6%)。BLIP 在零样本方式下直接迁移到视频-语言任务时也展现出强大的泛化能力。代码、模型和数据集已发布。

使用方法

你可以使用此模型进行条件性和无条件性图像描述

使用 Pytorch 模型

在 CPU 上运行模型

点击展开

import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration

processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")

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

# conditional image captioning
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))
# >>> a photography of a woman and her dog

# unconditional image captioning
inputs = processor(raw_image, return_tensors="pt")

out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
>>> a woman sitting on the beach with her dog

在 GPU 上运行模型

全精度

点击展开

import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration

processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base").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')

# conditional image captioning
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))
# >>> a photography of a woman and her dog

# unconditional image captioning
inputs = processor(raw_image, return_tensors="pt").to("cuda")

out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
>>> a woman sitting on the beach with her dog
半精度(float16

点击展开

import torch
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration

processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", 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')

# conditional image captioning
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

# unconditional image captioning
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

伦理考量

此版本仅用于研究目的,以支持学术论文。我们的模型、数据集和代码并未针对所有下游用途进行专门设计或评估。我们强烈建议用户在部署此模型前评估并解决与准确性、安全性和公平性相关的潜在问题。我们鼓励用户考虑 AI 的常见局限性,遵守适用法律,并在选择用例时采用最佳实践,特别是在错误或滥用可能严重影响人们生活、权利或安全的高风险场景中。有关用例的进一步指导,请参考我们的 AUP 和 AI AUP。

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

标签

tf blip image-text-to-text image-captioning arxiv:2201.12086 license:bsd-3-clause endpoints_compatible region:us

操作


详细信息

厂商
Salesforce
任务
image-to-text
框架
transformers
模型类型
blip
许可(HF)
bsd-3-clause