HuggingFace镜像/cogagent-vqa-hf
模型介绍文件和版本分析
下载使用量0

CogAgent

CogAgent 是在 CogVLM 基础上改进的开源视觉语言模型。

📖 论文:https://arxiv.org/abs/2312.08914

🚀 GitHub:有关演示、微调、查询提示等更多信息,请参考 我们的 GitHub

提醒

📍 这是 CogAgent 检查点的 cogagent-vqa 版本。

我们已开源两个版本的 CogAgent 检查点,您可以根据需求选择:

  1. cogagent-chat:此模型 在 GUI 智能体、视觉多轮对话、视觉定位 等方面具备强大能力。

    如果您需要 GUI 智能体和视觉定位功能,或需要针对给定图像进行多轮对话,建议使用此版本模型。

  2. cogagent-vqa:此模型 在 单轮视觉对话 方面能力更强。

    如果您需要 处理 VQA 基准测试(如 MMVET、VQAv2),建议使用此模型。

介绍

CogAgent-18B 拥有 110 亿视觉参数和 70 亿语言参数。

CogAgent 在图像理解和 GUI 智能体方面展现出 卓越性能:

  1. CogAgent-18B 在 9 个跨模态基准测试中取得了最先进的通用性能,包括:VQAv2、MM-Vet、POPE、ST-VQA、OK-VQA、TextVQA、ChartQA、InfoVQA、DocVQA。

  2. CogAgent-18B 在 GUI 操作数据集(包括 AITW 和 Mind2Web)上显著超越现有模型。

除了 CogVLM 已有的所有功能(视觉多轮对话、视觉定位)外,CogAgent 还具备:

  1. 支持更高分辨率的视觉输入和对话问答。它支持 1120x1120 的超高分辨率图像输入。

  2. 具备视觉智能体能力,能够针对任何 GUI 截图上的给定任务返回计划、下一步操作以及带坐标的具体操作。

  3. 增强了与 GUI 相关的问答能力,能够处理关于任何 GUI 截图的问题,例如网页、电脑应用程序、移动应用程序等。

  4. 通过改进的预训练和微调,增强了 OCR 相关任务的能力。

img

本仓库中的模型权重用于学术研究是免费的。 希望将模型用于商业目的的用户必须在 此处 注册。 已注册用户可免费将模型用于商业活动,但必须遵守本许可的所有条款和条件。 许可通知应包含在软件的所有副本或实质部分中。

快速开始

使用以下 Python 代码在 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='quantization bits')
parser.add_argument("--from_pretrained", type=str, default="THUDM/cogagent-chat-hf", help='pretrained ckpt')
parser.add_argument("--local_tokenizer", type=str, default="lmsys/vicuna-7b-v1.5", help='tokenizer path')
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("========Use torch type as:{} with device:{}========\n\n".format(torch_type, DEVICE))

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("image path >>>>> ")
    if image_path == "stop":
        break

    image = Image.open(image_path).convert('RGB')
    history = []
    while True:
        query = input("Human:")
        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)]]

        # add any transformers params here.
        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("\nCog:", response)
        history.append((query, response))

然后运行:

python cli_demo_hf.py --bf16

许可协议

本仓库中的代码根据 Apache-2.0 许可协议 开源,而 CogAgent 和 CogVLM 模型权重的使用必须遵守 模型许可协议。

引用与致谢

如果您发现我们的工作对您有所帮助,请考虑引用以下论文

@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项目的英文图文数据,以及众多经典的跨模态研究数据集。我们由衷感谢他们的贡献。