🚀 BLIP - Math
本模型在數學多模態數據集上進行了微調,它包含兩個輸出頭:文本生成和評分。我們提供了模型文本生成部分的權重文件 pytorch_model.bin
。
你需要 4 個輸入源,包括兩個文本輸入和兩個圖像輸入:problem_body
、student_response
、question_image
和 student_image
。
要進行條件文本生成:
對於所有其他使用情況,請遵循與 BLIP 模型相同的步驟。
如果你有任何進一步的問題或需要特定代碼或實現細節方面的幫助,請隨時提問。
🚀 快速開始
BLIP:用於統一視覺 - 語言理解和生成的引導式語言 - 圖像預訓練
這是一個在 COCO 數據集上進行圖像字幕預訓練的模型卡片 - 基礎架構(使用 ViT 基礎骨幹網絡)。
 |
圖片來源於 BLIP 官方倉庫 |
簡要概述
來自論文的作者在摘要中寫道:
視覺 - 語言預訓練(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-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')
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))
>>> 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')
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))
>>> 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')
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))
>>> a woman sitting on the beach with her dog
📚 詳細文檔
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}
}
📄 許可證
本模型使用的許可證為 bsd - 3 - clause。