🚀 BLIP:用於統一視覺語言理解和生成的語言 - 圖像預訓練引導
BLIP是一個新的視覺 - 語言預訓練(VLP)框架,它可以靈活地遷移到視覺 - 語言理解和生成任務中。該模型在多種視覺 - 語言任務上取得了最先進的成果,還能以零樣本的方式直接遷移到視頻 - 語言任務中。
 |
圖片來源於BLIP官方倉庫 |
🚀 快速開始
模型概述
本模型卡片介紹了在視覺問答任務上訓練的BLIP模型 - 基礎架構(使用ViT基礎骨幹網絡)。
模型用途
你可以使用此模型進行條件和無條件的圖像字幕生成。
✨ 主要特性
作者在論文的摘要中提到:
視覺 - 語言預訓練(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, BlipForQuestionAnswering
processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-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')
question = "how many dogs are in the picture?"
inputs = processor(raw_image, question, return_tensors="pt")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
>>> 1
在GPU上運行模型
全精度運行
點擊展開
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForQuestionAnswering
processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-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')
question = "how many dogs are in the picture?"
inputs = processor(raw_image, question, return_tensors="pt").to("cuda")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
>>> 1
半精度(float16
)運行
點擊展開
import torch
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForQuestionAnswering
processor = BlipProcessor.from_pretrained("ybelkada/blip-vqa-base")
model = BlipForQuestionAnswering.from_pretrained("ybelkada/blip-vqa-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')
question = "how many dogs are in the picture?"
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16)
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
>>> 1
📚 詳細文檔
倫理考量
本版本僅用於支持學術論文的研究目的。我們的模型、數據集和代碼並非專門為所有下游用途而設計或評估。我們強烈建議用戶在部署此模型之前評估並解決與準確性、安全性和公平性相關的潛在問題。我們鼓勵用戶考慮人工智能的常見侷限性,遵守適用法律,並在選擇用例時採用最佳實踐,特別是在錯誤或濫用可能對人們的生活、權利或安全產生重大影響的高風險場景中。有關用例的進一步指導,請參考我們的AUP和AI AUP。
📄 許可證
本模型使用的許可證為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}
}