编辑与 layout

图像编辑评测用的 SemSR、IRS、CAS、编辑方向与 object-wise consistency 指标。

面向图像编辑的语义保持、指令跟随与 layout 一致性指标。

跳转到指标7 个 id · 点击展开

semsr (↑)

用法: trigger/origin/target 三图组的 Semantic Shift Rate。

参考: 语义偏移率 SemSR:CLIP 语义偏移归一化(触发 vs 原始图像)。 论文: arXiv:2402.07562 仓库: WorldFoundry(按论文复现)

资产: 从图像计算时使用 CLIP backbone 权重(scorer / HF cache)。

from worldfoundry.evaluation.tasks.metrics import compute_semsr_from_images

result = compute_semsr_from_images(
    image_ust="trigger.png",
    image_ori="origin.png",
    image_tar="target.png",
    semantic_text="a photo of a cat",
)
print(result["semsr"])

返回: 含 semsrsem_shift 与 CLIP 相似度的 dict。

irs (↑)

用法: 相对真实图统计校准的 Image Realism Score。

参考: 图像真实感分 IRS:五种统计量构成 pentagon 面积。 论文: arXiv:2309.14756 仓库: WorldFoundry(按论文复现)

资产: 无需模型 checkpoint — 由输入图像直接计算统计量。

from PIL import Image
from worldfoundry.evaluation.tasks.metrics import compute_irs_with_reference

real_paths = ["real/1.jpg", "real/2.jpg"]
test_paths = ["gen/1.jpg", "gen/2.jpg"]
real_images = [Image.open(p) for p in real_paths]
test_images = [Image.open(p) for p in test_paths]

out = compute_irs_with_reference(test_images, real_images)
print(out["irs_mean"], out["irs_scores"])

返回: 含逐图 IRS 与拟合 reference means 的 dict。

cas (↑)

用法: 合成图训练分类器,在真实标签上算 Top-k accuracy。

参考: 分类准确率分 CAS:仅用合成图训练分类器,在真实标签上测 Top-k。 论文: arXiv:1905.10887 仓库: WorldFoundry(按论文复现)

资产: 无固定 checkpoint — 在 API 提供的 synthetic feature 上训练轻量分类器。

import numpy as np
from worldfoundry.evaluation.tasks.metrics import (
    train_classifier_and_compute_cas,
    compute_cas_from_predictions,
)

out = train_classifier_and_compute_cas(
    synthetic_images=syn_x,
    synthetic_labels=syn_y,
    real_images=real_x,
    real_labels=real_y,
    num_classes=10,
    device="cuda",
)
print(out["cas_top1"], out.get("cas_top5"))

# or with existing predictions
print(compute_cas_from_predictions(real_y, pred_topk, topk=(1, 5)))

返回: 含 cascas_top1、可选 cas_top5 的 dict。

manipulation_direction (↑)

用法: 图像编辑评估的 CLIP 变化向量对齐。

参考: 操控方向 MD:CLIP 图像/文本变化向量余弦相似度。 论文: Sensors 2023 仓库: WorldFoundry(按论文复现)

资产: CLIP 图像/文本 encoder,经 HF 或 scorer cache 加载。

from worldfoundry.evaluation.tasks.metrics import compute_manipulation_direction_from_pairs

md = compute_manipulation_direction_from_pairs(
    image_input="before.png",
    image_manipulated="after.png",
    text_original="a red car",
    text_replaced="a blue car",
)
print(md)

返回: [-1, 1] 余弦相似度;越高说明编辑越沿文本方向。

vs_similarity (↑)

用法: 成对 embedding 的 HDGAN 视觉–语义相似度。

参考: HDGAN 视觉-语义相似度(配对 embedding 余弦)。 论文: HDGAN 仓库: WorldFoundry(按论文复现)

资产: 由 API 提供 HDGAN embedding 输入;无 bundled standalone checkpoint。

import numpy as np
from worldfoundry.evaluation.tasks.metrics import compute_vs_similarity

image_embeds = np.load("img_emb.npy")  # (N, D)
text_embeds = np.load("txt_emb.npy")   # (N, D)
print(compute_vs_similarity(image_embeds, text_embeds, paired=True))

返回: 成对 batch 的 VS 相似度 float。

quality_loss (↓)

用法: CLIPScore × 文字出现概率(prompt 优化指标)。

参考: 质量损失:CLIPScore × 生成图含文字/字符概率 PC。 论文: IEEE Access 2023.3348778 仓库: WorldFoundry(按论文复现)

资产: CLIPScore 风格 CLIP 权重,经 WORLDFOUNDRY_T2V_METRICS_CACHE_DIR / HF cache 加载。

from worldfoundry.evaluation.tasks.metrics import compute_quality_loss_for_pair

out = compute_quality_loss_for_pair(
    image="sample.png",
    prompt="HELLO WORLD",
    has_text=True,
)
print(out)  # clip_score, text_presence_probability, quality_loss

返回: dict;无文字时 quality_loss 降低是预期行为。

object_wise_consistency (↑)

用法: 位置感知 T2I:guidance box 与检测框匹配。

参考: 对象级一致性:检测框与引导框 max IoU 及 R_suc(IoU>0.5)。 论文: arXiv:2304.13427 仓库: WorldFoundry(按论文复现)

资产: 无需模型 checkpoint — 只需要 guidance box 与 detector 输出。

from worldfoundry.evaluation.tasks.metrics import compute_object_wise_consistency

guidance = [([10, 20, 100, 200], "cat"), ([120, 30, 220, 180], "dog")]
detections = [([12, 22, 98, 198], "cat"), ([125, 35, 215, 175], "dog")]

print(compute_object_wise_consistency(guidance, detections, iou_threshold=0.5))

返回: 含 mean IoU 与 object_wise_success_rate 的 dict。