File size: 2,077 Bytes
2c76448 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | """Combine per-task score files into the VisSlideBench summary (Table 1 layout).
python eval/aggregate.py --pred_dir outputs/my_model
Each metric is averaged over the cases with a valid score for that metric.
Overall is the mean of the eleven metrics (CF/IF/AQ for three generation
tasks, SC/PQ for editing) and is reported only when all four tasks exist.
"""
import argparse
import json
import os
from common import load_jsonl, mean
GEN_TASKS = ("t2i", "template", "multi_image")
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--pred_dir", required=True)
ap.add_argument("--by", choices=["none", "source", "prompt_type"], default="none",
help="Optionally split generation scores by real/synthetic source or prompt type.")
args = ap.parse_args()
score_dir = os.path.join(args.pred_dir, "scores")
table, metrics = {}, []
for task in GEN_TASKS:
path = os.path.join(score_dir, f"{task}.jsonl")
if not os.path.exists(path):
continue
rows = load_jsonl(path)
groups = {"all": rows} if args.by == "none" else {}
if args.by != "none":
for r in rows:
groups.setdefault(r.get(args.by), []).append(r)
for g, rs in groups.items():
entry = {m: mean(r[m] for r in rs if r.get(m) is not None) for m in ("cf", "if", "aq")}
entry["n"] = len(rs)
table[task if g == "all" else f"{task}/{g}"] = entry
if args.by == "none":
metrics += [table[task][m] for m in ("cf", "if", "aq")]
edit_path = os.path.join(score_dir, "edit.jsonl")
if os.path.exists(edit_path):
ok = [r for r in load_jsonl(edit_path) if "sc" in r]
sc, pq = mean(r["sc"] for r in ok), mean(r["pq"] for r in ok)
table["edit"] = {"sc": sc, "pq": pq, "n": len(ok)}
metrics += [sc, pq]
if args.by == "none" and len(metrics) == 11 and None not in metrics:
table["overall"] = mean(metrics)
print(json.dumps(table, indent=1))
if __name__ == "__main__":
main()
|