模型简介
模型特点
模型能力
使用案例
🚀 mBLIP mT0-XL
mBLIP mT0-XL是一个用于多语言视觉任务的模型,它基于BLIP-2架构,能在96种语言下执行图像描述、视觉问答等任务,为多语言视觉处理提供了高效的解决方案。
🚀 快速开始
本模型可用于96种语言的图像描述、视觉问答等任务。若要使用原始模型进行零样本条件文本生成,或对其进行微调以用于下游应用,可参考我们的代码仓库。
✨ 主要特性
- 多语言支持:mBLIP可在96种语言下执行图像描述、视觉问答等任务。
- 高效架构:基于BLIP-2架构,由视觉变换器(ViT)、查询变换器(Q-Former)和大语言模型(LLM)组成。
- 灵活使用:可直接使用原始模型进行零样本推理,也可进行微调以适应特定任务。
📦 安装指南
文档未提及安装步骤,暂不展示。
💻 使用示例
基础用法
在CPU上运行模型
import requests
from PIL import Image
from transformers import BlipProcessor, Blip2ForConditionalGeneration
processor = BlipProcessor.from_pretrained("Gregor/mblip-mt0-xl")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-mt0-xl")
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 = "Describe the image in German."
inputs = processor(raw_image, question, return_tensors="pt")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
高级用法
在GPU上以全精度运行模型
# pip install accelerate
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-mt0-xl")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-mt0-xl", device_map="auto")
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 = "Describe the image in German."
inputs = processor(raw_image, question, return_tensors="pt").to("cuda")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
在GPU上以半精度(bfloat16
)运行模型
# pip install accelerate
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-mt0-xl")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-mt0-xl", torch_dtype=torch.bfloat16, device_map="auto")
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 = "Describe the image in German."
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.bfloat16)
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
在GPU上以8位精度(int8
)运行模型
⚠️ 重要提示
论文结果仅对大语言模型(LLM)的权重使用
int8
,而此代码会将所有权重加载为int8
。我们发现这样的结果稍差,目前HuggingFace不支持对部分模型使用int8
。
# pip install accelerate bitsandbytes
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-mt0-xl")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-mt0-xl", load_in_8bit=True, device_map="auto")
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 = "Describe the image in German."
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.bfloat16)
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
📚 详细文档
模型描述
mBLIP是一个基于BLIP-2的模型,由3个子模型组成:视觉变换器(ViT)、查询变换器(Q-Former)和大语言模型(LLM)。
Q-Former和ViT均由英文BLIP-2检查点(blip2-flan-t5-xl)初始化,然后使用多语言任务混合数据集与多语言大语言模型(mt0-xl)重新对齐。
这使得该模型可用于以下任务:
- 图像描述
- 视觉问答(VQA)
支持96种语言。
支持语言
mBLIP在以下96种语言上进行了训练:
af, am, ar, az, be, bg, bn, ca, ceb, cs, cy, da, de, el, en, eo, es, et, eu, fa, fi, fil, fr, ga, gd, gl, gu, ha, hi, ht, hu, hy, id, ig, is, it, iw, ja, jv, ka, kk, km, kn, ko, ku, ky, lb, lo, lt, lv, mg, mi, mk, ml, mn, mr, ms, mt, my, ne, nl, no, ny, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sm, sn, so, sq, sr, st, su, sv, sw, ta, te, tg, th, tr, uk, ur, uz, vi, xh, yi, yo, zh, zu
直接使用和下游应用
你可以在零样本设置下,使用原始模型根据图像和提示文本进行条件文本生成,或者对其进行微调以用于下游应用。我们强烈建议在微调时对大语言模型(LLM)应用低秩自适应(LoRA),并使用bf16
作为数据类型,因为标准的fp16
可能会导致损失出现NaN
。
偏差、风险、局限性和伦理考量
虽然mBLIP理论上可以处理多达100种语言,但在实践中,我们预计在英语、德语、西班牙语等高资源语言的提示下,模型会取得最佳效果。
mBLIP继承了用于初始化它的模型的风险、局限性和偏差。该模型尚未在现实世界的应用中进行测试,因此不应直接部署到任何应用程序中。研究人员应首先仔细评估模型在特定部署环境中的安全性和公平性。
🔧 技术细节
文档未提及技术实现细节,暂不展示。
📄 许可证
本项目采用MIT许可证。
📖 引用
如果您使用了我们的模型,请引用以下文献:
@article{geigle2023mblip,
author = {Gregor Geigle and
Abhay Jain and
Radu Timofte and
Goran Glava\v{s}},
title = {mBLIP: Efficient Bootstrapping of Multilingual Vision-LLMs},
journal = {arXiv},
volume = {abs/2307.06930},
year = {2023},
url = {https://arxiv.org/abs/2307.06930},
eprinttype = {arXiv},
eprint = {2307.06930},
}








