🚀 BLIP:用於統一視覺語言理解和生成的語言圖像預訓練引導
BLIP是一個新的視覺語言預訓練(VLP)框架,它能夠靈活地遷移到視覺語言理解和生成任務中。本模型是經過微調的Salesforce BLIP大型圖像字幕模型,尤其增加了回覆長度,可用於圖像字幕生成任務。
 |
圖片來源於BLIP官方倉庫 |
📚 詳細文檔
論文 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在以零樣本方式直接遷移到視頻語言任務時也表現出了很強的泛化能力。代碼、模型和數據集已發佈。
💻 使用示例
你可以使用此模型進行條件和無條件的圖像字幕生成。
基礎用法
使用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))
📄 許可證
本模型使用的許可證為BSD 3條款許可證(BSD-3-Clause)。
📖 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}
}