许可证:apache-2.0
语言:
- 英文
基础模型:
- Qwen/Qwen2-VL-7B-Instruct
任务标签:视觉问答
数据集:
- DiagramAgent/DiagramGenBenchmark
📑论文链接
模型卡片:DiagramAgent/Diagram_to_Code_Agent
1. 模型概述
- 名称:DiagramAgent/Diagram_to_Code_Agent
- 描述:
该代理的任务是将给定的图表(视觉表示)转换为对应的结构化代码。
2. 预期用途
- 主要任务:
- 将现有图表转换为结构化代码表示。
- 通过提供可靠的代码基础支持图表编辑工作流。
- 捕获并保留图表的隐式逻辑结构和视觉细节。
- 应用场景:
- 自动化图表编辑:将图表转换为代码以便后续修改。
- 逆向工程视觉图表以进行分析和复用。
- 通过集成基于代码的图表表示增强数据可视化工具。
3. 架构与训练细节
- 基础模型:使用Qwen2-VL-7B模型,这是一种视觉语言融合模型。
- 训练过程:
- 在DiagramGenBenchmark数据集中的多样化图表样本上进行训练。
- 旨在生成与参考代码高度一致的代码,确保所有图表元素被准确捕获。
- 使用专门的损失函数以减少生成代码与参考代码之间的编辑距离。
- 模块交互:
与检查代理(Check Agent)紧密协作,验证生成的代码并提供进一步优化的反馈。
4. 使用示例
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
model = Qwen2VLForConditionalGeneration.from_pretrained(
"DiagramAgent/Diagram_to_Code_Agent", torch_dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained("DiagramAgent/Diagram_to_Code_Agent")
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "your input",
},
{"type": "text", "text": "image path"},
],
}
]
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
generated_ids = model.generate(**inputs, max_new_tokens=8192)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
5. 引用
如果您觉得我们的工作有帮助,欢迎引用。
@inproceedings{wei2024wordsstructuredvisualsbenchmark,
title={From Words to Structured Visuals: A Benchmark and Framework for Text-to-Diagram Generation and Editing},
author={Jingxuan Wei and Cheng Tan and Qi Chen and Gaowei Wu and Siyuan Li and Zhangyang Gao and Linzhuang Sun and Bihui Yu and Ruifeng Guo},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
year={2025}
}