🚀 MMICL模型卡片
MMICL(Multi-Modal In-Context Learning)是一個融合了blip2/instrcutblip的多模態視覺語言模型。它能夠分析和理解多圖像,還能遵循指令,在複雜視覺推理數據集上表現出色。
🚀 快速開始
最新消息
- [09-19] 我們已將MMICL演示轉換為永久鏈接:MMICL演示。MMICL的Vicuna版本和聊天模式目前正在開發中,可能需要仔細調整生成參數,且可能無法正常工作。
- [09-15] 我們的論文已上傳至arXiv。
- [09-01] MIC數據已在huggingface hub上發佈。
- [08-23] 在MME上排名第1,在MMBench上排名第1。
- [08-21] MMICL-FLANT5XXL和MMICL-Tiny模型已在huggingface hub上發佈。
MMICL臨時演示
MMICL-FLANT5XXL在線演示,支持多圖像輸入和視頻輸入。
✨ 主要特性
- 多圖像引用和推理能力:能夠分析和理解多個圖像,並進行推理。
- 手動構建的上下文指令調優數據集:有助於模型更好地遵循指令。
- 優異的性能表現:截至2023年8月21日,在多模態任務排行榜和廣泛的視覺語言任務中達到了最先進的性能,在MME和MMBench上均排名第1。
- 豐富的模型配置:
- 視覺編碼器:CLIP的VIT - L / EVA - CLIP的ViT - G/14
- 預訓練大語言模型:FlanT5 - XL/FlanT5 - XXL/Vicuna - 7B/Vicuna - 13B
📦 安裝指南
文檔中未提及具體安裝步驟,暫無法提供。
💻 使用示例
基礎用法
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'Use the image 0: <image0>{replace_token},image 1: <image1>{replace_token} and image 2: <image2>{replace_token} as a visual aid to help you calculate the equation accurately. image 0 is 2+1=3.\nimage 1 is 5+6=11.\nimage 2 is"']
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)
📚 詳細文檔
模型詳情
MMICL(Multi-Modal In-Context Learning)是一個多模態視覺語言模型,它融合了blip2/instrcutblip。該模型能夠分析和理解多個圖像,還能遵循指令。MMICL優於相同大小的視覺語言模型,在複雜視覺推理數據集上表現出色。截至2023年8月21日,它在多模態任務排行榜和廣泛的視覺語言任務中達到了最先進的性能。此外,它在視頻理解和多模態上下文學習(M - ICL)方面展現了新的能力。
模型基本信息
訓練超參數
- 訓練機制:[fp32, bf16混合精度, bf16非混合精度]
📄 許可證
本項目採用MIT許可證。