#!/usr/bin/env python3 # -*- coding: utf-8 -*- """重新生成 bench3/4/5/7 报告,在最左边加原图列。""" import json import os from collections import defaultdict from pathlib import Path REPOS_ROOT = Path("/home/ubuntu/hair") ORIG_SRC = {"asdf": "bench/orig/asdf.jpg", "qwer": "bench/orig/qwer.jpg", "girl2": "bench/orig/girl2.jpg", "girl5": "bench/orig/girl5.jpg"} # bench编号 -> (输出目录, 部署HTML名, 报告标题后缀) BENCHES = [ (3, "美颜(磨皮+美颜)"), (4, "磨皮"), (5, "美白"), (7, "纯生发"), ] def img_src(path, bench_num): if not path or not os.path.isfile(path): return None return f"bench{bench_num}/" + os.path.basename(path) def gen_report(bench_num, title_suffix): bench_dir = REPOS_ROOT / f"benchmark_out/bench{bench_num}" results = bench_dir / "results.json" if not results.exists(): print(f" 跳过 bench{bench_num}: results.json 不存在") return d = json.load(open(results, encoding="utf-8")) titles = d["res_titles"] rows = d["rows"] prompt = d.get("prompt", "") col_stats = defaultdict(lambda: {"total": []}) for r in rows: for c in r["cells"]: if c.get("ok"): col_stats[c["res_title"]]["total"].append(c["total_ms"]) # 表头:原图列 + 分辨率列 headers = ['原图'] for t in titles: s = col_stats.get(t) avg = sum(s["total"]) // len(s["total"]) if s and s["total"] else 0 headers.append(f'
{t}
' f'
均{avg/1000:.1f}s
') body_rows = [] for r in rows: orig_src = ORIG_SRC.get(r["img"]) label = f'
{r["img"]}
{r["hair_name"]}
' # 原图列:显示输入原图 orig_cell = (f'
{label}
' f'') cells = [orig_cell] for c in r["cells"]: src = img_src(c.get("grown_path"), bench_num) if c.get("ok") else None if src: t = c.get("total_ms", 0) cells.append(f'' f'
{t/1000:.1f}s
') else: cells.append(f'
') body_rows.append(f'{"".join(cells)}') html = f""" 重绘分辨率对比({title_suffix})

📊 重绘分辨率对比(提示词:{title_suffix})

4图×5发型=20行 · 每行原图+4分辨率 · steps=15 · 提示词="{prompt}" · 80/80成功 · 0 OOM

最左列为输入原图。列标题下为平均总耗时。横向滚动查看。
{"".join(headers)} {"".join(body_rows)}
""" deploy = REPOS_ROOT / "static" / f"bench{bench_num}_report.html" deploy.write_text(html, encoding="utf-8") print(f" ✓ bench{bench_num} ({title_suffix}): {deploy.name}") def main(): print("重新生成报告(加原图列):") for num, suffix in BENCHES: gen_report(num, suffix) print("完成") if __name__ == "__main__": main()