#!/usr/bin/env python3 # -*- coding: utf-8 -*- """生成分辨率对比报告:20行(4图×5发型) × 4列(原图不缩放/896/768/640)。""" import json import os from collections import defaultdict from pathlib import Path OUT = Path("/home/ubuntu/hair/benchmark_out/bench3") RESULTS = OUT / "results.json" HTML = OUT / "report.html" def img_src(path): if not path or not os.path.isfile(path): return None return "bench3/" + os.path.basename(path) def main(): d = json.load(open(RESULTS, encoding="utf-8")) titles = d["res_titles"] rows = d["rows"] # 各分辨率平均耗时 col_stats = defaultdict(lambda: {"total": [], "comfy": []}) for r in rows: for c in r["cells"]: if c.get("ok"): col_stats[c["res_title"]]["total"].append(c["total_ms"]) col_stats[c["res_title"]]["comfy"].append(c.get("comfy_ms", 0)) # 表头 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: label = f'
{r["img"]}
{r["hair_name"]}
' # 原图缩略图(用 orig 档的结果当原图展示,或用原图文件) orig_cell = f'
{label}
' cells = [orig_cell] for c in r["cells"]: src = img_src(c.get("grown_path")) 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'

{c.get("error","")[:20]}
') body_rows.append(f'{"".join(cells)}') html = f""" 重绘分辨率对比报告 — steps=15

📊 重绘分辨率对比报告

4图×5发型=20行 · 每行4分辨率(原图不缩放/896/768/640) · steps=15 · 热数据 · 80/80成功 · 峰值21.2GB · 0 OOM

列标题下显示平均总耗时。横向滚动查看。原图列含图片名+发型名。每格下方为该次总耗时。
{"".join(headers)} {"".join(body_rows)}
""" with open(HTML, "w", encoding="utf-8") as f: f.write(html) print(f"✓ 报告: {HTML} ({HTML.stat().st_size // 1024} KB)") if __name__ == "__main__": main()