许可证: mit
语言:
MMICL模型卡
新闻 🚀
- [09-19] 我们将MMICL演示转换为永久链接: MMICL演示。MMICL的Vicuna版本和聊天模式目前正在开发中,可能需要仔细调整生成参数,可能无法正常工作。
- [09-15] 我们的论文已上传至arXiv。
- [09-01] MIC数据已在huggingface hub上发布。
- [08-23] 在MME上排名第一,在MMBench上排名第一。
- [08-21] MMICL-FLANT5XXL和MMICL-Tiny模型已在huggingface hub上发布。
MMICL临时演示
MMICL-FLANT5XXL游乐场
支持多图像输入以及视频输入。
模型详情
MMICL(多模态上下文学习) 是一个结合了blip2/instrcutblip的多模态视觉语言模型。
它能够分析和理解多张图像,并遵循指令。
模型描述
MMICL在相同规模的VL模型中表现优异,尤其在复杂的视觉推理数据集上表现突出。
截至2023年8月21日,它在多模态任务排行榜和广泛的视觉语言任务中均实现了最先进的性能。
此外,它还展示了在视频理解和多模态上下文学习(M-ICL)方面的新能力。
-
多图像引用和推理能力
-
手动构建的上下文指令调优数据集
-
截至2023年8月21日,在MME上排名第一,在MMBench上排名第一。
-
视觉编码器: 来自CLIP的VIT-L/来自EVA-CLIP的ViT-G/14
-
预训练LLM: FlanT5-XL/FlanT5-XXL/Vicuna-7B/Vicuna-13B
如何开始使用该模型
图像显示在我们的GitHub代码库MMICL中。
from model.instructblip import InstructBlipConfig, InstructBlipModel, InstructBlipPreTrainedModel,InstructBlipForConditionalGeneration,InstructBlipProcessor
import datasets
import json
import transformers
from PIL import Image
import torch
model_type="instructblip"
model_ckpt="BleachNick/MMICL-Instructblip-T5-xxl"
processor_ckpt = "Salesforce/instructblip-flan-t5-xxl"
config = InstructBlipConfig.from_pretrained(model_ckpt)
if 'instructblip' in model_type:
model = InstructBlipForConditionalGeneration.from_pretrained(
model_ckpt,
config=config).to('cuda:0',dtype=torch.bfloat16)
image_palceholder="图"
sp = [image_palceholder]+[f"<image{i}>" for i in range(20)]
processor = InstructBlipProcessor.from_pretrained(
processor_ckpt
)
sp = sp+processor.tokenizer.additional_special_tokens[len(sp):]
processor.tokenizer.add_special_tokens({'additional_special_tokens':sp})
if model.qformer.embeddings.word_embeddings.weight.shape[0] != len(processor.qformer_tokenizer):
model.qformer.resize_token_embeddings(len(processor.qformer_tokenizer))
replace_token="".join(32*[image_palceholder])
image = Image.open("images/cal_num1.png")
image1 = Image.open("images/cal_num2.png")
image2 = Image.open("images/cal_num3.png")
images = [image,image1,image2]
prompt = [f'使用图像0: <image0>{replace_token},图像1: <image1>{replace_token}和图像2: <image2>{replace_token}作为视觉辅助,帮助你准确计算方程。图像0是2+1=3。\n图像1是5+6=11。\n图像2是"']
prompt = " ".join(prompt)
inputs = processor(images=images, text=prompt, return_tensors="pt")
inputs['pixel_values'] = inputs['pixel_values'].to(torch.bfloat16)
inputs['img_mask'] = torch.tensor([[1 for i in range(len(images))]])
inputs['pixel_values'] = inputs['pixel_values'].unsqueeze(0)
inputs = inputs.to('cuda:0')
outputs = model.generate(
pixel_values = inputs['pixel_values'],
input_ids = inputs['input_ids'],
attention_mask = inputs['attention_mask'],
img_mask = inputs['img_mask'],
do_sample=False,
max_length=50,
min_length=1,
set_min_padding_size=False,
)
generated_text = processor.batch_decode(outputs, skip_special_tokens=True)[0].strip()
print(generated_text)
训练超参数
- 训练机制: [fp32, bf16混合精度, bf16非混合精度]