🚀 CogVLM
CogVLM 是一個強大的開源視覺語言模型(VLM)。CogVLM - 17B 擁有 100 億視覺參數和 70 億語言參數,在 10 個經典跨模態基準測試上取得了最優(SOTA)性能,這些測試包括 NoCaps、Flicker30k captioning、RefCOCO、RefCOCO+、RefCOCOg、Visual7W、GQA、ScienceQA、VizWiz VQA 和 TDIUC。在 VQAv2、OKVQA、TextVQA、COCO captioning 等方面則排名第二,超越或與 PaLI - X 55B 持平。您可以通過線上 demo 體驗 CogVLM 多模態對話。
🚀 快速開始
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, LlamaTokenizer
tokenizer = LlamaTokenizer.from_pretrained('lmsys/vicuna-7b-v1.5')
model = AutoModelForCausalLM.from_pretrained(
'THUDM/cogvlm-grounding-generalist-hf',
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True
).to('cuda').eval()
query = 'Can you provide a description of the image and include the coordinates [[x0,y0,x1,y1]] for each mentioned object?'
image = Image.open(requests.get('https://github.com/THUDM/CogVLM/blob/main/examples/4.jpg?raw=true', stream=True).raw).convert('RGB')
inputs = model.build_conversation_input_ids(tokenizer, query=query, images=[image])
inputs = {
'input_ids': inputs['input_ids'].unsqueeze(0).to('cuda'),
'token_type_ids': inputs['token_type_ids'].unsqueeze(0).to('cuda'),
'attention_mask': inputs['attention_mask'].unsqueeze(0).to('cuda'),
'images': [[inputs['images'][0].to('cuda').to(torch.bfloat16)]],
}
gen_kwargs = {"max_length": 2048, "do_sample": False}
with torch.no_grad():
outputs = model.generate(**inputs, **gen_kwargs)
outputs = outputs[:, inputs['input_ids'].shape[1]:]
print(tokenizer.decode(outputs[0]))
📚 詳細文檔
CogVLM 模型包括四個基本組件:視覺變換器(ViT)編碼器、MLP 適配器、預訓練的大型語言模型(GPT)和一個視覺專家模塊。更多細節請參見Paper。
📄 許可證
此存儲庫中的代碼是根據 Apache - 2.0 許可 開放源碼,而使用 CogVLM 模型權重必須遵循 模型許可。
📖 引用
如果您覺得我們的工作有幫助,請考慮引用以下論文:
@article{wang2023cogvlm,
title={CogVLM: Visual Expert for Pretrained Language Models},
author={Weihan Wang and Qingsong Lv and Wenmeng Yu and Wenyi Hong and Ji Qi and Yan Wang and Junhui Ji and Zhuoyi Yang and Lei Zhao and Xixuan Song and Jiazheng Xu and Bin Xu and Juanzi Li and Yuxiao Dong and Ming Ding and Jie Tang},
year={2023},
eprint={2311.03079},
archivePrefix={arXiv},
primaryClass={cs.CV}
}