🌟 项目概述

SVGenius 是一个全面的 SVG 处理能力基准测试框架,从三个递进维度评估(多模态)大语言模型的能力:

维度 说明 子任务
理解 (Understanding) 感知与语义问答 SVG属性问答、语义理解
编辑 (Editing) 代码级修改能力 Bug修复、代码优化、风格编辑
生成 (Generation) 从描述/图像生成SVG 文本→SVG、图像→SVG、风格迁移

核心特色

  • 24 个应用领域 的真实世界数据

  • 系统化的复杂度分层(简单/中等/困难)

  • 8 类任务 + 18 种评估指标

  • 评估 22 个主流模型(涵盖不同规模、架构、训练范式)

  • 包括闭源模型(GPT-4o、Gemini-2.0-Flash、Claude 3.7-Sonnet)和开源模型(1.5B-72B 参数)

✨ 数据构建流程

我们构建了一个带有系统复杂度分层的全面数据集:

  • 左侧:从数据收集、处理、人工筛选到复杂度分层的系统化流水线

  • 中间:覆盖 24 个应用领域

  • 右侧:通过特征分布和复杂度分数验证 Easy/Medium/Hard 三层的清晰分层

📁 项目结构

SVGenius/
├── 📂 docs/                    # 项目页面源码
├── 📂 src/                     # 主要源代码
│   ├── 📂 data/                # 分层处理后的SVG文件
│   │   ├── easy/process/       # 简单难度(.svg + .png)
│   │   ├── medium/process/     # 中等难度
│   │   └── hard/process/       # 困难难度
│   ├── 📂 tasks/               # 8类任务的测试样本
│   │   ├── understanding/      # 理解任务(JSON格式)
│   │   ├── editing/            # 编辑任务
│   │   │   ├── bug_fixion/     #   Bug修复样本
│   │   │   ├── code_optimization/  # 代码优化样本
│   │   │   └── style_editing/  #   风格编辑样本
│   │   └── generation/         # 生成任务
│   │       ├── text_svg/       #   文本→SVG
│   │       ├── multimodel_svg/ #   多模态SVG生成
│   │       └── style_trans/    #   风格迁移
│   ├── 📂 understanding/       # 理解维度评估代码
│   │   └── evaluation_fix.py   # SVG问答评估(多选题准确率)
│   ├── 📂 editing/             # 编辑维度评估代码
│   │   ├── bug_fixing/         # Bug修复评估
│   │   ├── code_opti/          # 代码优化评估
│   │   └── style_editing/      # 风格编辑评估
│   ├── 📂 generation/          # 生成维度评估代码
│   │   ├── text2svg/           # 文本→SVG评估
│   │   ├── image2svg/          # 图像→SVG评估
│   │   └── style_trans/        # 风格迁移评估
│   ├── 📂 metrics/             # 共享评估指标模块
│   │   ├── compute_clip_score.py    # CLIPScore (ViT-L/14)
│   │   ├── compute_aesthetic_score.py # 美学评分
│   │   ├── compute_hpsv2.py         # HPSv2 人类偏好评分
│   │   ├── compute_dino_score.py    # DINOv2 相似度
│   │   ├── compute_fid.py           # FID 距离
│   │   ├── compute_SSIM.py          # SSIM 结构相似性
│   │   ├── compute_LPIPS.py         # LPIPS 感知距离
│   │   ├── compute_mse.py           # MSE 均方误差
│   │   ├── merge_metrics.py         # SVGMetrics 统一入口
│   │   └── pss/                     # 路径级语义相似度系统
│   │       ├── merge.py             #   SVGEvaluationSystem 核心
│   │       ├── validate.py          #   SVG有效性验证
│   │       ├── normal.py            #   SVG标准化/缩放
│   │       ├── com_iou.py           #   Alpha Mask IoU
│   │       ├── similarity.py        #   路径形状/颜色/位置相似度
│   │       ├── sequence.py          #   路径绘制顺序相似度
│   │       └── path_iou.py          #   路径级IoU
│   └── 📄 eval_util.py         # 通用评估工具函数
├── 📂 supplementary/           # 补充材料(数据构建、任务定义、指标详解)
├── 📄 requirements.txt         # Python 依赖
└── 📄 README.md                # 英文说明文档

📊 评估指标总览

理解维度(Understanding)

指标 说明
Accuracy 多选题准确率
Category Accuracy 按问题类型统计的准确率

编辑维度(Editing)

指标 说明 适用任务
Repair Accuracy 修复精度(完全匹配=1) Bug修复
Change Magnitude 修改幅度(编辑距离) Bug修复
Compression Ratio 代码压缩比 代码优化
MSE 均方误差(视觉保真度) 代码优化、风格编辑
Edit Distance 编辑距离 风格编辑
Custom Score 自定义综合评分 风格编辑

生成维度(Generation)

层级 指标 说明
路径级 (Path-level) Final Reward 综合加权得分
Global IoU Alpha Mask IoU
Shape Similarity 路径形状相似度
Color Similarity 路径颜色相似度
Position Similarity 路径位置相似度
Order Similarity 绘制顺序相似度
Path Count 路径数量评分
图像级 (Image-level) CLIPScore 图文匹配度
AestheticScore 美学质量
HPSv2 人类偏好评分
SSIM 结构相似性
LPIPS 感知距离
DinoScore DINOv2 特征相似度
FID Fréchet Inception Distance

🎯 模型评测机制详解

SVGenius 的评估体系涉及 两种类型的模型,在不同环节承担不同的角色:

类型一:被评测模型(Target Models)

即我们想要测试的(多模态)大语言模型,它们需要完成实际的 SVG 处理任务。这些模型被用于以下 8 个任务

维度 任务 评测脚本 模型的作用 支持的模型示例
理解 SVG问答 understanding/evaluation_fix.py 读取 SVG 代码,回答多选题 GPT-4o, DeepSeek-R1, Qwen2-72B 等
编辑 Bug修复 editing/bug_fixing/evaluation.py 接收有错误的 SVG,输出修复后的 SVG DeepSeek-R1, Qwen2-72B 等
编辑 代码优化 editing/code_opti/evaluation.py 接收 SVG,输出压缩优化后的 SVG DeepSeek-R1, Qwen2-72B 等
编辑 风格编辑 editing/style_editing/evaluation.py 按指令修改 SVG 的视觉风格 DeepSeek-R1, Qwen2-72B 等
生成 文本→SVG generation/text2svg/evaluation.py 根据文本描述生成 SVG 代码 DeepSeek-R1, Qwen2-72B 等
生成 图像→SVG generation/image2svg/evaluation.py 根据输入图像生成 SVG 代码 Qwen2.5-VL-72B 等多模态模型
生成 风格迁移(生成) generation/style_trans/style_trans.py 将参考 SVG 转换为目标风格 Qwen2.5-72B, DeepSeek-R1 等
生成 风格迁移(排名) generation/style_trans/rank_evaluation.py 多个模型生成结果的两两对比排名 多个模型同时对比

类型二:评判模型(Judge Models / Evaluator Models)

使用 LLM-as-Judge 方式,由一个独立的模型来评判被评测模型的输出质量。这些模型在以下 3 个场景 中使用:

场景 脚本位置 评判模型的作用 默认使用的评判模型
SVG 问答评分 understanding/evaluation_fix.py 本身既是选手又是裁判:同一个模型读取 SVG 并回答问题,然后对比正确答案计算准确率 与目标模型相同(如 GPT-4o)
风格迁移绝对评分 generation/style_trans/evaluation.py 多模态 LLM 查看生成的 SVG 图片(需先转为 PNG),按 3 个维度(风格一致性、内容保真度、视觉质量)打出 1-5 分 GPT-4o(多模态)
风格迁移相对排名 generation/style_trans/rank_evaluation.py 多模态 LLM 进行两两对比(Pairwise),判断 A 和 B 哪个风格迁移结果更好,输出 Win Rate 矩阵 DeepSeek-R1 等

类型三:自动化指标计算(无需 LLM,但部分依赖本地 CV 模型)

以下指标由传统计算机视觉模型和纯算法计算,不依赖大语言模型 API。但其中部分指标仍需加载本地预训练模型(本地 GPU/CPU 推理),部分则是纯数学算法。

🔴 需要加载本地预训练模型的指标
指标 计算脚本 加载的模型 模型详情 使用场景
CLIPScore metrics/compute_clip_score.py clip.load("ViT-L/14") OpenAI CLIP ViT-L/14(~890MB),首次运行自动下载到 ~/.cache/clip/ 文本→SVG 的图文匹配度
AestheticScore metrics/compute_aesthetic_score.py aesthetic-predictor-v2-5 (SigLIP backbone) 美学评分模型(~1.5GB),从 HuggingFace 自动下载 文本→SVG 的美学质量
HPSv2 metrics/compute_hpsv2.py hpsv2 库 v2.1 人类偏好评分模型,调用 hpsv2.score() 内置模型 文本→SVG 的人类偏好
DinoScore metrics/compute_dino_score.py AutoModel.from_pretrained("./dinov2-base") DINOv2-base(~350MB),需手动下载到 ./dinov2-base/ 目录 图像→SVG 的特征相似度
LPIPS metrics/compute_LPIPS.py lpips.LPIPS(net='vgg') LPIPS 感知距离模型(VGG backbone,~50MB) 图像→SVG 的感知距离
FID metrics/compute_fid.py InceptionV3 (2048-dim) InceptionV3(~100MB),通过 torchvision 加载 文本/图像→SVG 的分布距离

⚠️ 注意:以上 6 个指标需要本地 GPU 显存加载模型。首次运行时模型会自动下载,如果网络受限需提前手动下载。详见下方 离线部署指南

🟢 纯算法/轻量计算的指标(不加载模型)
指标 计算脚本 依赖的库/算法 使用场景
SSIM metrics/compute_SSIM.py skimage.metrics.structural_similarity(纯数学算法) 图像→SVG 的结构相似性
MSE metrics/compute_mse.py torchvision.transforms.ToTensor + 逐像素 MSE(纯数学计算) 代码优化、风格编辑、图像→SVG
PSS 路径相似度 metrics/pss/merge.py 自定义算法(匈牙利匹配 + Kendall tau),无深度学习模型 文本/图像→SVG 的路径级精细评估
Repair Accuracy editing/bug_fixing/set_metric.py difflib 字符串比较(纯算法) Bug 修复精度
Change Magnitude editing/bug_fixing/set_metric.py 编辑距离算法(纯算法) Bug 修复/风格编辑修改幅度
Compression Ratio editing/code_opti/set_metric.py 字节级大小比较(纯算法) 代码优化压缩率
Edit Distance editing/style_editing/set_metric.py 编辑距离算法(纯算法) 风格编辑的代码修改程度

评测流程图

被评测模型 (Target Model)
    │
    │  输入:SVG 代码 / 文本描述 / 图片
    ▼
┌─────────────────────────────────────┐
│  8 个任务:理解、Bug修复、代码优化、  │
│  风格编辑、文本→SVG、图像→SVG、      │
│  风格迁移(生成)、风格迁移(排名)       │
└─────────────────────────────────────┘
    │
    │  输出:SVG 代码 / 选择题答案
    ▼
┌─────────────────────────────────────┐
│         评估层(两种方式)            │
│                                     │
│  方式1: LLM-as-Judge                │
│  ├── SVG问答准确率(自身评判)        │
│  ├── 风格迁移绝对评分(GPT-4o)       │
│  └── 风格迁移相对排名(Pairwise)     │
│                                     │
│  方式2: 自动化指标计算               │
│  ├── [需本地模型] CLIPScore / Aesthetic / HPSv2 │
│  ├── [需本地模型] LPIPS / DinoScore / FID        │
│  ├── [纯算法] SSIM / MSE             │
│  ├── [纯算法] PSS 路径语义相似度      │
│  └── [纯算法] Repair / Compression / EditDistance │
└─────────────────────────────────────┘
    │
    ▼
  最终评分结果(JSON 文件)

需要配置 API Key 的位置(共 9 处)

所有涉及模型调用的脚本都需要配置 API_KEYBASE_URL

# 文件 用途 行号
1 src/understanding/evaluation_fix.py SVG问答(被评测模型) 18-19
2 src/editing/bug_fixing/evaluation.py Bug修复(被评测模型) 16-17
3 src/editing/code_opti/evaluation.py 代码优化(被评测模型) 19-20
4 src/editing/style_editing/evaluation.py 风格编辑(被评测模型) 15-16
5 src/generation/text2svg/evaluation.py 文本→SVG(被评测模型) 21-22
6 src/generation/image2svg/evaluation.py 图像→SVG(被评测模型) 20-21
7 src/generation/style_trans/style_trans.py 风格迁移生成(被评测模型) 22-23
8 src/generation/style_trans/evaluation.py 风格迁移评分(评判模型) 19-20
9 src/generation/style_trans/rank_evaluation.py 风格迁移排名(评判模型) 21-22

注意

  • 自动化指标中 红色标注 的部分(CLIPScore、AestheticScore、HPSv2、DinoScore、LPIPS、FID)需要在本地加载预训练 CV 模型(需 GPU 显存),但不需要 API Key。

  • 绿色标注 的部分(SSIM、MSE、PSS、Repair Accuracy、Change Magnitude、Compression Ratio、Edit Distance)是纯算法计算,既不需要 API Key 也不需要加载模型。

🧪 完整评估指南

一、环境配置

# 克隆仓库
git clone https://github.com/ZJU-REAL/SVGenius.git
cd SVGenius
​
# 创建虚拟环境
conda create -n svg_ben python=3.10
conda activate svg_ben
​
# 安装依赖
pip install -r requirements.txt

二、配置 API 密钥

每个评估脚本的顶部都有硬编码的 API_KEYBASE_URL,需要修改以下 9 个文件(详见 模型评测机制详解 中的表格):

将每个文件中的:

API_KEY = "your_api_key_here"
BASE_URL = "your_base_url_here"

替换为你的实际 API 凭据。

提示:也可以使用 run_all_evaluations.py 通过命令行参数 --api-key--base-url 统一注入密钥,避免逐个修改文件。


🏭 离线部署指南(离线环境如何提前下载模型)

如果你的评估机器无法联网,需要在有网络的机器上提前下载所有 CV 模型,然后复制到离线机器。

步骤 1:在有网络的机器上下载模型
# 进入项目根目录
cd SVGenius
​
# 安装依赖(联网环境下)
pip install -r requirements.txt
​
# 运行离线下载脚本(约需下载 6GB)
python download_models_offline.py --target-dir ./models

脚本会下载以下 6 个模型 到本地:

# 模型 大小 缓存/保存位置
1 CLIP ViT-L/14 ~890MB ~/.cache/clip/
2 aesthetic-predictor-v2-5 ~1.5GB ~/.cache/huggingface/hub/
3 HPSv2 v2.1 ~3GB ~/.cache/huggingface/hub/
4 DINOv2-base ~350MB ./models/dinov2-base/(项目内)
5 LPIPS (VGG backbone) ~50MB ~/.cache/torch/hub/
6 InceptionV3 (FID权重) ~100MB ./models/fid/(项目内)

如果只想下载部分模型(例如跳过较大的 HPSv2):

python download_models_offline.py --skip hpsv2
步骤 2:复制模型到离线机器

将以下目录复制到离线机器的相同路径

# 1. 复制项目内的模型目录(DINOv2 + FID 权重)
#    源: SVGenius/models/  →  目标: 离线机器 SVGenius/src/metrics/models/
cp -r ./models/dinov2-base 离线机器:SvGenius/src/metrics/models/
cp -r ./models/fid           离线机器:SvGenius/src/metrics/models/
​
# 2. 复制用户缓存目录中的模型(CLIP, aesthetic, HPSv2, LPIPS, InceptionV3)
#    源 → 目标(路径必须一致)
cp -r ~/.cache/clip/         离线机器:~/.cache/clip/
cp -r ~/.cache/huggingface/  离线机器:~/.cache/huggingface/
cp -r ~/.cache/torch/        离线机器:~/.cache/torch/

关键:用户缓存目录(~/.cache/)下的模型必须放在离线机器的完全相同路径下,因为 cliphpsv2lpipstorchvision 等库硬编码了这些缓存路径。

步骤 3:离线机器上的环境设置

在离线机器的项目根目录创建启动脚本 run_offline.sh

#!/bin/bash
# ============================================================
# SVGenius 离线评估启动脚本
# 使用前确保已完成步骤 1 和步骤 2 的模型复制
# ============================================================
​
# 激活虚拟环境
conda activate svg_ben
cd SVGenius/src
​
# 设置离线环境变量(关键!)
export HF_HUB_OFFLINE=1
export TRANSFORMERS_OFFLINE=1
export HF_DATASETS_OFFLINE=1
export CUDA_VISIBLE_DEVICES=0  # 指定使用的 GPU
​
# 验证离线模式是否就绪
python -m offline_init
​
# 开始评估(示例:文本→SVG easy 难度)
python -m generation.text2svg.evaluation \
    --input tasks/generation/text_svg/easy_svg_captions.json \
    --output results/generation/text2svg_easy.json \
    --model deepseekr1 \
    --concurrent 5 \
    --disable-fid

或者在 Python 代码中设置(在导入 metrics 模块之前):

import os
os.environ['HF_HUB_OFFLINE'] = '1'
os.environ['TRANSFORMERS_OFFLINE'] = '1'
os.environ['HF_DATASETS_OFFLINE'] = '1'
​
# 然后再导入其他模块
from src.metrics.merge_metrics import SVGMetrics
离线模式验证

运行以下命令检查离线模式是否就绪:

cd SVGenius/src
python -m offline_init

输出示例:

[SVGenius 离线模式] 环境变量已设置:
  HF_HUB_OFFLINE=1
  TRANSFORMERS_OFFLINE=1
​
[SVGenius 离线模式] 模型完整性检查:
  ✓ DINOv2-base: .../src/metrics/models/dinov2-base/config.json
  ✓ FID Inception: .../src/metrics/models/fid/pt_inception-2015-12-05-6726825d.pth
  ✓ CLIP ViT-L/14: ~/.cache/clip/ViT-L-14.pt
  ✓ 离线模式已就绪,可以开始评估!

⚠️ 常见问题

  • HFValidationErrorLocalEntryNotFoundError:说明 HuggingFace 模型缓存路径不正确,检查 ~/.cache/huggingface/hub/ 是否完整复制

  • RuntimeError: cannot download:说明环境变量未设置,确认已 export HF_HUB_OFFLINE=1

  • FileNotFoundError: dinov2-base:DINOv2 模型未复制到 src/metrics/models/dinov2-base/


三、完整评估流程(3 个维度 × 8 个任务)

准备工作:创建输出目录
# 在项目根目录执行
cd SVGenius/src
mkdir -p results/understanding
mkdir -p results/editing
mkdir -p results/generation
mkdir -p results/style_trans

维度 1:理解(Understanding)—— 1 个任务

评估脚本: src/understanding/evaluation_fix.py

参数 说明 示例
--input 输入 JSON 数据集 见下方
--model 模型名称(默认 gpt-4o gpt-4o, deepseekr1, Qwen2-72B-Instruct-AWQ
--output-dir 输出目录 ./results/understanding
--concurrency 并发数(默认 5) 5
--samples 样本数(默认全部) 100
--seed 随机种子 42
# ========== SVG 理解(3个难度级别) ==========
​
# 简单难度
python -m understanding.evaluation_fix \
  --input tasks/understanding/easy_generation_results.json \
  --model gpt-4o \
  --output-dir results/understanding \
  --concurrency 5
​
# 中等难度
python -m understanding.evaluation_fix \
  --input tasks/understanding/medium_generation_results.json \
  --model gpt-4o \
  --output-dir results/understanding \
  --concurrency 5
​
# 困难难度
python -m understanding.evaluation_fix \
  --input tasks/understanding/hard_generation_results.json \
  --model gpt-4o \
  --output-dir results/understanding \
  --concurrency 5

输出指标: 总体准确率 (Overall Accuracy)、按问题类型准确率 (Category Accuracy)


维度 2:编辑(Editing)—— 3 个任务
2.1 Bug 修复

评估脚本: src/editing/bug_fixing/evaluation.py

参数 说明
--input 输入 JSON(含 bug_svgground_truth
--output 输出结果 JSON 路径
--model 模型名称(默认 deepseekr1
--concurrent 并发数(默认 5)
# ========== Bug 修复(3个难度级别) ==========
​
python -m editing.bug_fixing.evaluation \
  --input tasks/editing/bug_fixion/easy_svg_errors_dataset.json \
  --output results/editing/bug_fix_easy.json \
  --model deepseekr1 \
  --concurrent 5
​
python -m editing.bug_fixing.evaluation \
  --input tasks/editing/bug_fixion/medium_svg_errors_dataset.json \
  --output results/editing/bug_fix_medium.json \
  --model deepseekr1 \
  --concurrent 5
​
python -m editing.bug_fixing.evaluation \
  --input tasks/editing/bug_fixion/hard_errors_dataset.json \
  --output results/editing/bug_fix_hard.json \
  --model deepseekr1 \
  --concurrent 5

输出指标: Repair Accuracy(修复精度)、Change Magnitude(修改幅度)、Processing Time


2.2 代码优化

评估脚本: src/editing/code_opti/evaluation.py

参数 说明
--input 输入 JSON(含 origin_svgopti_ratio
--output 输出结果 JSON 路径
--model 模型名称(默认 deepseekr1
--concurrent 并发数(默认 5)
# ========== 代码优化(3个难度级别) ==========
​
python -m editing.code_opti.evaluation \
  --input tasks/editing/code_optimization/easy_svg_optimization_results.json \
  --output results/editing/code_opti_easy.json \
  --model deepseekr1 \
  --concurrent 5
​
python -m editing.code_opti.evaluation \
  --input tasks/editing/code_optimization/medium_svg_optimization_results.json \
  --output results/editing/code_opti_medium.json \
  --model deepseekr1 \
  --concurrent 5
​
python -m editing.code_opti.evaluation \
  --input tasks/editing/code_optimization/hard_svg_optimization_results.json \
  --output results/editing/code_opti_hard.json \
  --model deepseekr1 \
  --concurrent 5

输出指标: Compression Ratio(压缩比)、Size Reduction %(尺寸减少)、MSE(视觉保真度)


2.3 风格编辑

评估脚本: src/editing/style_editing/evaluation.py

参数 说明
--input 输入 JSON(含 originalmodifiedcommand
--output 输出结果 JSON 路径
--model 模型名称(默认 deepseekr1
--concurrent 并发数(默认 5)
# ========== 风格编辑(3个难度级别) ==========
​
python -m editing.style_editing.evaluation \
  --input tasks/editing/style_editing/easy_results.json \
  --output results/editing/style_edit_easy.json \
  --model deepseekr1 \
  --concurrent 5
​
python -m editing.style_editing.evaluation \
  --input tasks/editing/style_editing/medium_results.json \
  --output results/editing/style_edit_medium.json \
  --model deepseekr1 \
  --concurrent 5
​
python -m editing.style_editing.evaluation \
  --input tasks/editing/style_editing/hard_results.json \
  --output results/editing/style_edit_hard.json \
  --model deepseekr1 \
  --concurrent 5

输出指标: Edit Distance(编辑距离)、MSE(视觉差异)、Custom Score(综合评分)


维度 3:生成(Generation)—— 4 个任务
3.1 文本→SVG

评估脚本: src/generation/text2svg/evaluation.py

参数 说明
--input 输入 JSON(含文本描述)
--output 输出结果 JSON 路径
--model 模型名称(默认 deepseekr1
--concurrent 并发数(默认 5)
--disable-fid 禁用 FID 计算(加速)
# ========== 文本→SVG(3个难度级别) ==========
​
# 注意:这个任务计算量大,建议先用 --disable-fid 测试
python -m generation.text2svg.evaluation \
  --input tasks/generation/text_svg/easy_svg_captions.json \
  --output results/generation/text2svg_easy.json \
  --model deepseekr1 \
  --concurrent 5
​
python -m generation.text2svg.evaluation \
  --input tasks/generation/text_svg/medium_svg_captions.json \
  --output results/generation/text2svg_medium.json \
  --model deepseekr1 \
  --concurrent 5
​
python -m generation.text2svg.evaluation \
  --input tasks/generation/text_svg/hard_svg_captions.json \
  --output results/generation/text2svg_hard.json \
  --model deepseekr1 \
  --concurrent 5

输出指标:

  • 路径级: Final Reward, Global IoU, Shape/Color/Position/Order Similarity, Path Count

  • 图像级: CLIPScore, AestheticScore, HPSv2, FID


3.2 图像→SVG(多模态)

评估脚本: src/generation/image2svg/evaluation.py

参数 说明
--input 输入 JSON(含图像路径和描述)
--output 输出结果 JSON 路径
--model 模型名称(默认 Qwen2.5-VL-72B-Instruct
--concurrent 并发数(默认 5)
--disable-fid 禁用 FID 计算
# ========== 图像→SVG(3个难度级别) ==========
# 注意:需要使用支持多模态视觉输入的模型
​
python -m generation.image2svg.evaluation \
  --input tasks/generation/multimodel_svg/easy_svg_captions.json \
  --output results/generation/image2svg_easy.json \
  --model Qwen2.5-VL-72B-Instruct \
  --concurrent 5
​
python -m generation.image2svg.evaluation \
  --input tasks/generation/multimodel_svg/medium_svg_captions.json \
  --output results/generation/image2svg_medium.json \
  --model Qwen2.5-VL-72B-Instruct \
  --concurrent 5
​
python -m generation.image2svg.evaluation \
  --input tasks/generation/multimodel_svg/hard_svg_captions.json \
  --output results/generation/image2svg_hard.json \
  --model Qwen2.5-VL-72B-Instruct \
  --concurrent 5

输出指标:

  • 路径级: 同 Text→SVG

  • 图像级: SSIM, LPIPS, MSE, DinoScore, FID


3.3 风格迁移生成

步骤 1:先生成风格迁移的 SVG 文件。

评估脚本: src/generation/style_trans/style_trans.py

参数 说明
--input 输入 JSON(含 reference_svgdescription
--output 输出结果 JSON 路径
--output-dir 生成 SVG 文件的保存目录
--model 模型名称(默认 Qwen2.5-72B-Instruct
--thread_num 并发数(默认 1)
# ========== 风格迁移:生成阶段(3个难度级别) ==========
​
python -m generation.style_trans.style_trans \
  --input tasks/generation/style_trans/easy.json \
  --output results/style_trans/easy_gen.json \
  --output-dir results/style_trans/easy_svg/ \
  --model deepseekr1 \
  --thread_num 3
​
python -m generation.style_trans.style_trans \
  --input tasks/generation/style_trans/medium.json \
  --output results/style_trans/medium_gen.json \
  --output-dir results/style_trans/medium_svg/ \
  --model deepseekr1 \
  --thread_num 3
​
python -m generation.style_trans.style_trans \
  --input tasks/generation/style_trans/hard.json \
  --output results/style_trans/hard_gen.json \
  --output-dir results/style_trans/hard_svg/ \
  --model deepseekr1 \
  --thread_num 3

步骤 2:对生成的风格迁移结果进行 LLM 评分。

评估脚本: src/generation/style_trans/evaluation.py

参数 说明
--input 生成阶段的输出 JSON
--output-dir 评估结果输出目录
--model 评分模型(默认 gpt-4o
--thread_num 并发数(默认 1)
# ========== 风格迁移:LLM评分阶段(3个难度级别) ==========
​
python -m generation.style_trans.evaluation \
  --input results/style_trans/easy_gen.json \
  --output-dir results/style_trans/easy_eval/ \
  --model gpt-4o \
  --thread_num 3
​
python -m generation.style_trans.evaluation \
  --input results/style_trans/medium_gen.json \
  --output-dir results/style_trans/medium_eval/ \
  --model gpt-4o \
  --thread_num 3
​
python -m generation.style_trans.evaluation \
  --input results/style_trans/hard_gen.json \
  --output-dir results/style_trans/hard_eval/ \
  --model gpt-4o \
  --thread_num 3

输出指标: LLM 绝对评分(1-5 分)

⚠️ 已知问题与修复evaluation.py 需要 score_rubrics.json 文件,原始仓库未提供。我们已补充在 src/generation/style_trans/score_rubrics.json,包含 3 个评分维度:

  • Style Consistency(风格一致性)

  • Content Preservation(内容保真度)

  • Visual Quality(视觉质量)

此外,evaluation.py 读取 transferred_image_path 时要求是 PNG 图片路径(用于 base64 编码发送给多模态 LLM),而 style_trans.py 输出的是 SVG 文件路径。因此需要在评估前将 SVG 光栅化为 PNG。可使用以下辅助脚本:

# svg_to_png.py —— 放在 src/generation/style_trans/ 下运行
import cairosvg, json, os, sys
​
gen_json = sys.argv[1]  # style_trans.py 的输出 JSON
with open(gen_json, 'r') as f:
    data = json.load(f)
​
for item in data.get('results', []):
    paths = item.get('output_paths', {})
    for key in ['gt_svg', 'gen_svg']:
        svg_path = paths.get(key, '')
        if svg_path and os.path.exists(svg_path):
            png_path = svg_path.replace('.svg', '.png')
            cairosvg.svg2png(url=svg_path, write_to=png_path)
            item[f'{key}_png'] = png_path
    # 更新 transferred_image_path 为 PNG 路径
    if 'output_paths' in item:
        item['transferred_image_path'] = item['output_paths'].get('gen_svg', '').replace('.svg', '.png')
​
with open(gen_json.replace('.json', '_png.json'), 'w') as f:
    json.dump(data, f, ensure_ascii=False, indent=2)
print("Done. Use the _png.json file as --input for evaluation.py")

3.4 风格迁移相对排名

评估脚本: src/generation/style_trans/rank_evaluation.py

参数 说明
--svg-dir 生成的 SVG 文件目录
--model 排名模型(默认 deepseekr1
# ========== 风格迁移:两两对比排名 ==========
​
python -m generation.style_trans.rank_evaluation \
  --svg-dir results/style_trans/easy_svg/ \
  --model deepseekr1
​
python -m generation.style_trans.rank_evaluation \
  --svg-dir results/style_trans/medium_svg/ \
  --model deepseekr1
​
python -m generation.style_trans.rank_evaluation \
  --svg-dir results/style_trans/hard_svg/ \
  --model deepseekr1

输出指标: Win Rate(胜率)两两比较矩阵


四、一键运行脚本(全部评估)

将以下内容保存为 run_all_eval.sh,执行前请先配置好所有 API 密钥:

#!/bin/bash
# ============================================================
# SVGenius 全维度评估一键运行脚本
# 使用前请确保:
#   1. 已安装所有依赖:pip install -r requirements.txt
#   2. 已在各评估脚本中配置 API_KEY 和 BASE_URL
#   3. 在 SVGenius/src 目录下执行此脚本
# ============================================================
​
set -e
MODEL="gpt-4o"            # 主评估模型(可改为 deepseekr1 等)
EDIT_MODEL="deepseekr1"   # 编辑类任务模型
CONCURRENT=5               # 并发数
​
mkdir -p results/understanding results/editing results/generation results/style_trans
​
echo "========================================="
echo " 维度 1/3: 理解 (Understanding)"
echo "========================================="
​
for level in easy medium hard; do
    echo "--- 理解 - ${level} ---"
    python -m understanding.evaluation_fix \
        --input tasks/understanding/${level}_generation_results.json \
        --model ${MODEL} \
        --output-dir results/understanding \
        --concurrency ${CONCURRENT}
done
​
echo "========================================="
echo " 维度 2/3: 编辑 (Editing)"
echo "========================================="
​
echo "--- Bug 修复 ---"
for level in easy medium hard; do
    suffix="svg_errors_dataset"
    [ "$level" = "hard" ] && suffix="errors_dataset"
    python -m editing.bug_fixing.evaluation \
        --input tasks/editing/bug_fixion/${level}_${suffix}.json \
        --output results/editing/bug_fix_${level}.json \
        --model ${EDIT_MODEL} \
        --concurrent ${CONCURRENT}
done
​
echo "--- 代码优化 ---"
for level in easy medium hard; do
    python -m editing.code_opti.evaluation \
        --input tasks/editing/code_optimization/${level}_svg_optimization_results.json \
        --output results/editing/code_opti_${level}.json \
        --model ${EDIT_MODEL} \
        --concurrent ${CONCURRENT}
done
​
echo "--- 风格编辑 ---"
for level in easy medium hard; do
    python -m editing.style_editing.evaluation \
        --input tasks/editing/style_editing/${level}_results.json \
        --output results/editing/style_edit_${level}.json \
        --model ${EDIT_MODEL} \
        --concurrent ${CONCURRENT}
done
​
echo "========================================="
echo " 维度 3/3: 生成 (Generation)"
echo "========================================="
​
echo "--- 文本→SVG ---"
for level in easy medium hard; do
    python -m generation.text2svg.evaluation \
        --input tasks/generation/text_svg/${level}_svg_captions.json \
        --output results/generation/text2svg_${level}.json \
        --model ${EDIT_MODEL} \
        --concurrent ${CONCURRENT}
done
​
echo "--- 图像→SVG (多模态) ---"
for level in easy medium hard; do
    python -m generation.image2svg.evaluation \
        --input tasks/generation/multimodel_svg/${level}_svg_captions.json \
        --output results/generation/image2svg_${level}.json \
        --model Qwen2.5-VL-72B-Instruct \
        --concurrent ${CONCURRENT}
done
​
echo "--- 风格迁移 (生成) ---"
for level in easy medium hard; do
    python -m generation.style_trans.style_trans \
        --input tasks/generation/style_trans/${level}.json \
        --output results/style_trans/${level}_gen.json \
        --output-dir results/style_trans/${level}_svg/ \
        --model ${EDIT_MODEL} \
        --thread_num 3
done
​
echo "--- 风格迁移 (LLM评分) ---"
for level in easy medium hard; do
    python -m generation.style_trans.evaluation \
        --input results/style_trans/${level}_gen.json \
        --output-dir results/style_trans/${level}_eval/ \
        --model gpt-4o \
        --thread_num 3
done
​
echo "--- 风格迁移 (相对排名) ---"
for level in easy medium hard; do
    python -m generation.style_trans.rank_evaluation \
        --svg-dir results/style_trans/${level}_svg/ \
        --model ${EDIT_MODEL}
done
​
echo "========================================="
echo " 全部评估完成!结果保存在 results/ 目录"
echo "========================================="

运行方式:

cd SVGenius/src
chmod +x run_all_eval.sh
./run_all_eval.sh

五、各任务参数速查表

维度 任务 脚本 (src/) 输入文件 (tasks/) 输出 默认模型 特殊参数
理解 SVG问答 understanding/evaluation_fix.py understanding/{level}_generation_results.json 输出目录 gpt-4o --samples, --seed
编辑 Bug修复 editing/bug_fixing/evaluation.py editing/bug_fixion/{level}_*.json JSON文件 deepseekr1 -
编辑 代码优化 editing/code_opti/evaluation.py editing/code_optimization/{level}_*.json JSON文件 deepseekr1 -
编辑 风格编辑 editing/style_editing/evaluation.py editing/style_editing/{level}_results.json JSON文件 deepseekr1 -
生成 文本→SVG generation/text2svg/evaluation.py generation/text_svg/{level}_svg_captions.json JSON文件 deepseekr1 --disable-fid
生成 图像→SVG generation/image2svg/evaluation.py generation/multimodel_svg/{level}_svg_captions.json JSON文件 Qwen2.5-VL-72B-Instruct --disable-fid
生成 风格迁移(生成) generation/style_trans/style_trans.py generation/style_trans/{level}.json JSON + SVG目录 Qwen2.5-72B-Instruct --thread_num, --output-dir
生成 风格迁移(评分) generation/style_trans/evaluation.py 上一步的输出JSON 输出目录 gpt-4o --thread_num
生成 风格迁移(排名) generation/style_trans/rank_evaluation.py 生成的SVG目录 --svg-dir deepseekr1 -

注意: {level} 替换为 easymediumhard;Bug修复的 hard 文件名为 hard_errors_dataset.json(与 easy/medium 略有不同)。

🔑 核心工具函数(src/eval_util.py

函数 功能
remove_whitespace(svg) 移除SVG中所有空白字符
compare_svg(svg1, svg2) 使用 difflib 比较两个SVG的相似度
calculate_change_magnitude(src, tgt) 计算SVG之间的编辑距离
setup_logger() 统一日志配置(文件+控制台)
extract_svg_from_response(text) 从模型响应中提取SVG代码
load_svg_metrics() 动态导入 SVGMetrics 类
encode_image_to_base64(path) 图片转 Base64 编码

🏗️ PSS 路径语义相似度系统

SVGEvaluationSystem(位于 src/metrics/pss/merge.py)执行 7 步评估流程

  1. SVG 有效性检查

  2. 空 fill 属性处理

  3. SVG 标准化/缩放

  4. 全局 Alpha Mask IoU 计算

  5. 路径数量评估

  6. 路径级比较(形状、颜色、位置)

  7. 路径顺序相似度计算

  8. 加权总分计算(权重:global_iou=0.5, shape=0.25, color=0.15, position=0.15, order=0.15)

📦 主要依赖

依赖 用途
PyTorch 2.7.0 深度学习框架
torchvision 图像处理
OpenAI SDK API 调用
cairosvg SVG 光栅化
CLIP CLIPScore 计算
transformers 预训练模型加载
opencv-python 图像处理
Pillow 图像操作
lpips 感知距离计算
hpsv2 人类偏好评分
aesthetic-predictor-v2-5 美学评分
svgpathtools / svgelements SVG 路径解析

 

Logo

这里是“一人公司”的成长家园。我们提供从产品曝光、技术变现到法律财税的全栈内容,并连接云服务、办公空间等稀缺资源,助你专注创造,无忧运营。

更多推荐