license: apache-2.0
language:
CogAgent
🔥 最新动态:新版 CogAgent-9B-20241220
已发布!欢迎访问 CogAgent GitHub 和 技术报告 探索并使用我们的最新模型。
📖 论文:https://arxiv.org/abs/2312.08914
📄 技术报告:https://cogagent.aminer.cn/blog#/articles/cogagent-9b-20241220-technical-report-en
🚀 GitHub:https://github.com/THUDM/CogAgent
🤗 模型主页:https://huggingface.co/THUDM/cogagent-9b-20241220
CogAgent 是基于 CogVLM 改进的开源视觉语言模型。关于演示、THUDM/cogagent-chat-hf
微调及查询提示等更多信息,请参阅 此GitHub。
重要提示
📍 此为 CogAgent 的 cogagent-chat
版本检查点。
我们开源了 2 个 CogAgent 检查点版本,您可根据需求选择:
-
cogagent-chat
:此模型 在 GUI 智能体、视觉多轮对话、视觉定位 等方面能力突出。
如需 GUI 智能体和视觉定位功能,或需基于给定图像进行多轮对话,推荐使用此版本模型。
-
cogagent-vqa
:此模型 在 单轮视觉对话 方面表现更优。
如需在 VQA 基准测试(如 MMVET、VQAv2)上工作,推荐使用此模型。
模型介绍
CogAgent-18B 包含 110 亿视觉参数和 70 亿语言参数。
CogAgent 在图像理解和 GUI 智能体方面展现出 卓越性能:
-
CogAgent-18B 在 9 个跨模态基准测试中达到顶尖水平,包括:VQAv2、MM-Vet、POPE、ST-VQA、OK-VQA、TextVQA、ChartQA、InfoVQA、DocVQA。
-
CogAgent-18B 在 GUI 操作数据集上显著超越现有模型,包括 AITW 和 Mind2Web。
除 CogVLM 已有功能(视觉多轮对话、视觉定位)外,CogAgent 还具备:
-
支持更高分辨率视觉输入与对话问答,可处理 1120x1120 超高清图像输入。
-
拥有视觉智能体能力,可针对任意 GUI 截图任务返回执行计划、下一步动作及带坐标的具体操作。
-
增强的 GUI 相关问答能力,可处理网页、PC 应用、移动端应用等任意界面截图的问题。
-
通过改进预训练与微调,强化了 OCR 相关任务能力。
本仓库模型权重仅供学术研究 免费使用。
商业用途需注册 此处。
注册用户可免费用于商业活动,但须遵守许可协议所有条款。
软件的所有副本或实质性部分均须包含许可声明。
快速开始
通过 cli_demo.py
快速体验:
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, LlamaTokenizer
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--quant", choices=[4], type=int, default=None, help='量化位数')
parser.add_argument("--from_pretrained", type=str, default="THUDM/cogagent-chat-hf", help='预训练权重路径')
parser.add_argument("--local_tokenizer", type=str, default="lmsys/vicuna-7b-v1.5", help='分词器路径')
parser.add_argument("--fp16", action="store_true")
parser.add_argument("--bf16", action="store_true")
args = parser.parse_args()
MODEL_PATH = args.from_pretrained
TOKENIZER_PATH = args.local_tokenizer
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
tokenizer = LlamaTokenizer.from_pretrained(TOKENIZER_PATH)
if args.bf16:
torch_type = torch.bfloat16
else:
torch_type = torch.float16
print("========使用设备:{} 数据类型:{}========\n\n".format(DEVICE, torch_type))
if args.quant:
model = AutoModelForCausalLM.from_pretrained(
MODEL_PATH,
torch_dtype=torch_type,
low_cpu_mem_usage=True,
load_in_4bit=True,
trust_remote_code=True
).eval()
else:
model = AutoModelForCausalLM.from_pretrained(
MODEL_PATH,
torch_dtype=torch_type,
low_cpu_mem_usage=True,
load_in_4bit=args.quant is not None,
trust_remote_code=True
).to(DEVICE).eval()
while True:
image_path = input("图片路径 >>>>> ")
if image_path == "stop":
break
image = Image.open(image_path).convert('RGB')
history = []
while True:
query = input("用户提问:")
if query == "clear":
break
input_by_model = model.build_conversation_input_ids(tokenizer, query=query, history=history, images=[image])
inputs = {
'input_ids': input_by_model['input_ids'].unsqueeze(0).to(DEVICE),
'token_type_ids': input_by_model['token_type_ids'].unsqueeze(0).to(DEVICE),
'attention_mask': input_by_model['attention_mask'].unsqueeze(0).to(DEVICE),
'images': [[input_by_model['images'][0].to(DEVICE).to(torch_type)]],
}
if 'cross_images' in input_by_model and input_by_model['cross_images']:
inputs['cross_images'] = [[input_by_model['cross_images'][0].to(DEVICE).to(torch_type)]]
gen_kwargs = {"max_length": 2048,
"temperature": 0.9,
"do_sample": False}
with torch.no_grad():
outputs = model.generate(**inputs, **gen_kwargs)
outputs = outputs[:, inputs['input_ids'].shape[1]:]
response = tokenizer.decode(outputs[0])
response = response.split("</s>")[0]
print("\nCogAgent:", response)
history.append((query, response))
运行命令:
python cli_demo_hf.py --bf16
许可协议
代码遵循 Apache-2.0 许可,模型权重使用需遵守 模型许可。
引用与致谢
如果我们的工作对您有帮助,请考虑引用以下论文:
@misc{hong2023cogagent,
title={CogAgent: A Visual Language Model for GUI Agents},
author={Wenyi Hong and Weihan Wang and Qingsong Lv and Jiazheng Xu and Wenmeng Yu and Junhui Ji and Yan Wang and Zihan Wang and Yuxiao Dong and Ming Ding and Jie Tang},
year={2023},
eprint={2312.08914},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@misc{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}
}
在 CogVLM 的指令微调阶段,我们使用了来自 MiniGPT-4、LLAVA、LRV-Instruction、LLaVAR 和 Shikra 项目的英文图文数据,以及众多经典跨模态工作数据集,在此衷心感谢这些项目的贡献。