模型概述
模型特點
模型能力
使用案例
🚀 BLIP:用於統一視覺語言理解與生成的語言 - 圖像預訓練引導
BLIP是一個在COCO數據集上進行預訓練的圖像描述模型(基於ViT基礎架構),可靈活應用於視覺 - 語言理解和生成任務,在多個相關任務中取得了先進成果。
🚀 快速開始
本模型可用於有條件和無條件的圖像描述任務。
✨ 主要特性
- 靈活遷移:能靈活遷移到視覺 - 語言理解和生成任務。
- 有效利用數據:通過引導式字幕有效利用嘈雜的網絡數據。
- 先進成果:在圖像文本檢索、圖像描述、視覺問答等多種視覺 - 語言任務中取得了先進成果。
- 泛化能力強:在零樣本情況下直接遷移到視頻 - 語言任務時表現出強大的泛化能力。
📦 安裝指南
文檔未提及安裝步驟,可參考Hugging Face相關庫的安裝方式來安裝transformers
庫。
💻 使用示例
基礎用法
可以使用該模型進行有條件和無條件的圖像描述。
使用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
📚 詳細文檔
作者在論文摘要中提到:
視覺 - 語言預訓練(VLP)提升了許多視覺 - 語言任務的性能。然而,大多數現有的預訓練模型僅在基於理解的任務或基於生成的任務中表現出色。此外,性能的提升主要是通過擴大從網絡收集的嘈雜圖像 - 文本對數據集來實現的,而網絡數據是一種次優的監督來源。在本文中,我們提出了BLIP,一個新的VLP框架,它可以靈活地遷移到視覺 - 語言理解和生成任務。BLIP通過引導式字幕有效利用嘈雜的網絡數據,其中一個字幕生成器生成合成字幕,一個過濾器去除嘈雜的字幕。我們在廣泛的視覺 - 語言任務中取得了先進成果,如圖像 - 文本檢索(平均召回率@1提高2.7%)、圖像描述(CIDEr指標提高2.8%)和視覺問答(VQA分數提高1.6%)。BLIP在零樣本情況下直接遷移到視頻 - 語言任務時也表現出強大的泛化能力。代碼、模型和數據集均已發佈。
🔧 技術細節
- 數據處理:通過引導式字幕有效利用嘈雜的網絡數據,一個字幕生成器生成合成字幕,一個過濾器去除嘈雜的字幕。
- 任務表現:在圖像文本檢索、圖像描述、視覺問答等多種視覺 - 語言任務中取得了先進成果,在零樣本情況下直接遷移到視頻 - 語言任務時也表現出強大的泛化能力。
📄 許可證
本模型採用BSD 3 - 條款許可證。
⚠️ 重要提示
本版本僅用於支持學術論文的研究目的。我們的模型、數據集和代碼並非專門為所有下游用途設計或評估。我們強烈建議用戶在部署此模型之前評估並解決與準確性、安全性和公平性相關的潛在問題。我們鼓勵用戶考慮人工智能的常見侷限性,遵守適用法律,並在選擇用例時採用最佳實踐,特別是在錯誤或濫用可能對人們的生活、權利或安全產生重大影響的高風險場景中。有關用例的進一步指導,請參考我們的可接受使用政策(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}
}








