11 Commits
Author SHA1 Message Date
xsl 5bcaeb2594 chore: 所有提示词统一为"填充遮罩区域的头发"
测试结论: 纯生发提示词(不做皮肤处理)效果最佳。
- 替换所有位置的提示词默认值(原"填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"等)
- 涉及25个文件: app.py/hairline/service.py/hairline/redraw.py/工作流json/测试页/benchmark脚本/local_test
- _REDRAW_PROMPT / _DEFAULT_PROMPT / 各接口Form默认值 / 测试页输入框默认值 全部统一
2026-07-26 21:53:39 +08:00
xsl 8a82d00056 docs: 所有报告最左边新增原图(输入图)列
- bench3/4/5/7 报告重新生成,首列显示输入原图
- 补充 girl2 原图到 static/bench/orig/
- regen_reports.py: 通用报告重生成脚本
2026-07-26 21:44:31 +08:00
xsl e2bbcca7ad docs: 重绘分辨率对比(纯生发提示词) bench7报告
提示词="填充遮罩区域的头发"(纯生发,无皮肤处理)
80/80成功,0 OOM,峰值21.2GB
对照 bench3(美颜)/bench4(磨皮)/bench5(美白)/bench7(纯生发)
2026-07-26 21:41:43 +08:00
xsl f8ed477696 docs: 重绘分辨率对比(美白提示词) bench5报告
提示词="填充遮罩区域的头发,皮肤加一点美白"
80/80成功,0 OOM,峰值21.2GB
可对照 bench3(美颜)/bench4(磨皮)/bench5(美白) 三种提示词
2026-07-26 21:00:49 +08:00
xsl 2877d07a69 docs: 重绘分辨率对比(无美颜提示词) + 调试接口支持自定义提示词
- app.py/hairline/service.py: 调试接口新增 redraw_prompt 参数,_call_local_redraw 支持自定义提示词
- benchmark_res_prompt.py: 提示词改为"填充遮罩区域的头发,皮肤加一点磨皮"(去掉美颜)
- static/bench4_report.html: 20行×4分辨率对比报告,80/80成功,0 OOM

可对照 bench3(含美颜) vs bench4(无美颜) 看画质差异
2026-07-26 19:57:36 +08:00
xsl bee7a487ac docs: 重绘分辨率对比报告(原图/896/768/640)
4图×5发型=20行,每行4分辨率对比,steps=15,热数据。
80/80成功,0 OOM,峰值21.2GB(原图不缩放也未OOM)。
报告: static/bench3_report.html
2026-07-26 19:10:33 +08:00
xsl 531dcb8279 docs: swap步数+重绘分辨率对比报告(热数据)
4图×2发型×(3步数档+3分辨率档) 热数据对比,48/48成功,0 OOM,峰值20.6GB。
- benchmark_steps_res.py: 测试脚本(预热+正式取热数据)
- benchmark_steps_res_report.py: 报告生成
- static/bench2_report.html: 对比报告
- static/bench2/: 48张结果图

结论: B维度 steps10→20 swap 3.0s→3.9s; C维度 res640比896省3s(comfy 4.3s vs 7.3s)
2026-07-26 17:44:59 +08:00
xsl 62d2660e41 feat(调试): 测试页新增重绘分辨率选项
- app.py 调试接口新增 redraw_max_side 参数,控制整条管线的降分辨率
- debug_grow_timing.html 新增"重绘分辨率"下拉(640/768/896/1024/原图)
- 实测: 640比896省1.5s(5.2s vs 6.7s), 1024比896慢0.6s
2026-07-26 17:01:27 +08:00
xsl e4d03a782d feat(调试): swapHair webui步数暴露到测试页可调
参数透传链路: 测试页→debug接口→generate_hairline_redraw→_grow_core
  →_call_swap→change_hair swapHair→webui_img2img→build_body_v2

- app.py: 调试接口新增 webui_steps Form 参数
- hairline_grow.py: _call_swap/_grow_core/generate_hairline_grow/generate_hairline_redraw 透传 webui_steps
- debug_grow_timing.html: 新增 swap步数 下拉(默认/10/15/20/25/30)

实测 steps 10→25 swap 耗时 4.1s→4.4s,参数确实生效
2026-07-26 16:49:21 +08:00
xsl ae5a3b8f1d refactor(comfyui): 模型切换时同步VAE + 完善编码器映射
- 新增 _vae_for_unet() 按模型自动切换 VAE(Z-Image用ae, Flux.2用flux2-vae)
- _clip_for_unet 增加 z-image 识别
- 为将来多模型切换做准备(当前 Q4 不受影响)
2026-07-26 16:12:43 +08:00
xsl d318efcff0 feat(调试): 接口2女性生发分步耗时分析页面
新增 /api/v1/debug/grow-timing 调试接口 + debug_grow_timing.html 测试页:
- 拆分接口2女性生发的每一步并独立计时(extract_context/mask/swap/blend/comfyui)
- 测试页用条形图展示各步耗时占比,附步骤说明
- 用于定位性能瓶颈,优化方向判断

实测花瓣发型: 总11.9s = 预处理0.44s + 换发型4.4s + ComfyUI重绘6.8s
2026-07-26 16:12:32 +08:00
409 changed files with 1569 additions and 44 deletions
+1 -1
View File
@@ -29,7 +29,7 @@
"60": {
"class_type": "JjkText",
"inputs": {
"text": "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"
"text": "填充遮罩区域的头发"
}
},
"22": {
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -410,7 +410,7 @@
},
"60": {
"inputs": {
"text": "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"
"text": "填充遮罩区域的头发"
},
"class_type": "JjkText",
"_meta": {
+148 -5
View File
@@ -757,7 +757,7 @@ async def hair_grow(
hair_style: Optional[str] = Form(default=None, description="发型序号逗号分隔(必填),如 1,2,3。female:1-5 male:1-4"),
beauty_enabled: bool = Form(default=False, description="是否开启美颜(本期不生效)"),
use_mask: bool = Form(default=True, description="是否启用 inpaint 遮罩(测试对比用)。false 时用干净原图生成(空遮罩,不烧模板线)"),
prompt: str = Form(default="填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜", description="ComfyUI 提示词,会替换工作流节点60的文本"),
prompt: str = Form(default="填充遮罩区域的头发", description="ComfyUI 提示词,会替换工作流节点60的文本"),
flux_model: Optional[str] = Form(default=None, description="Flux 模型文件名(切换模型用)。None=工作流默认;如 flux-2-klein-9b-Q5_K_M.gguf / flux-2-klein-9b-Q4_K_M.gguf / flux2.0/flux-2-klein-9b-fp8.safetensors"),
redraw_max_side: Optional[int] = Form(default=None, description="重绘压图长边像素。None=默认896;0=不缩图(原图直送);其他如 768/640/1024"),
):
@@ -813,6 +813,149 @@ async def hair_grow(
return err(1007, f"处理失败:{ex}")
# ---------------------------------------------------------------------------
# 调试接口:接口2 女性生发 分步计时
# ---------------------------------------------------------------------------
@app.post(
"/api/v1/debug/grow-timing",
summary="调试-接口2女性生发分步计时",
tags=["调试"],
include_in_schema=False,
)
async def debug_grow_timing(
image_file: Optional[UploadFile] = File(default=None),
image_url: Optional[str] = Form(default=None),
image_base64: Optional[str] = Form(default=None),
hair_style: str = Form(default="2", description="发型序号(花瓣=2),逗号分隔多选"),
webui_steps: Optional[int] = Form(default=None, description="swapHair webui img2img 采样步数,None=服务端默认(15),可填10/15/20/25对比"),
redraw_max_side: Optional[int] = Form(default=None, description="ComfyUI重绘分辨率(长边像素)。None=默认8960=原图不缩;其他如640/768/1024"),
redraw_prompt: Optional[str] = Form(default=None, description="ComfyUI重绘提示词,None=默认'填充遮罩区域的头发'"),
):
"""单图跑接口2女性生发,返回每个步骤的耗时 + 结果图,用于定位性能瓶颈。
步骤拆分:
1. extract_context:人脸关键点检测 + 头发分割 + 发际线几何
2. [每个发型] generate_hairline_redraw
2a. compute_mask:发际线遮罩计算
2b. _call_swap:调 change_hair 换发型(内含 webui SD1.5 推理,远程或本机)
2c. _composite:接缝融合(多频段/羽化)
3. [每个发型] _call_local_redraw:调本机 ComfyUI 用 Flux.2 重绘
"""
import time as _time
from fastapi.concurrency import run_in_threadpool
raw, e = await resolve_image_bytes(image_file, image_url, image_base64)
if e is not None:
return e
image = cv2.imdecode(np.frombuffer(raw, np.uint8), cv2.IMREAD_COLOR)
if image is None:
return err(1008, "图片格式不支持(仅 JPG / PNG)")
try:
max_styles = 5
hair_styles = _parse_hair_styles(hair_style, max_styles)
if hair_styles is None:
return err(1007, f"hair_style 必须为 1..{max_styles}")
t_total0 = _time.perf_counter()
timings = {"total_ms": 0, "extract_context_ms": 0, "per_hairstyle": []}
# 步骤1: extract_context
t0 = _time.perf_counter()
from hairline.service import extract_context as _ec, _call_local_redraw, _REDRAW_MAX_SIDE # noqa
from face_analysis.hairline_grow import generate_hairline_redraw, NoFaceError # noqa
from face_analysis.head_mask import SEGFORMER_HAIR # noqa
ctx = await run_in_threadpool(_ec, image)
timings["extract_context_ms"] = int((_time.perf_counter() - t0) * 1000)
if ctx is None:
return err(1001, "无法识别人像")
hair_mask_reuse = (ctx["parse_map"] == SEGFORMER_HAIR)
h, w = image.shape[:2]
eff_side = _REDRAW_MAX_SIDE if redraw_max_side is None else redraw_max_side
redraw_img, hair_mask_redraw = image, hair_mask_reuse
downscale_info = None
if eff_side > 0 and max(h, w) > eff_side:
from hairline.service import _downscale_max_side
redraw_img, _rs = _downscale_max_side(image, eff_side)
_nh, _nw = redraw_img.shape[:2]
if hair_mask_redraw is not None:
hair_mask_redraw = cv2.resize(hair_mask_reuse.astype(np.uint8), (_nw, _nh),
interpolation=cv2.INTER_NEAREST).astype(bool)
downscale_info = {"from": f"{w}x{h}", "to": f"{_nw}x{_nh}", "max_side": eff_side}
textures_map = None
from hairline.service import get_texture_map, _FEMALE_KEY_TO_CHANG, load_texture_rgba, build_overlay_layer, load_ext_mesh
textures = get_texture_map()["female"]
items = [(s, textures[s - 1]) for s in hair_styles]
for order, (key, white_path) in items:
hs_t0 = _time.perf_counter()
entry = {"hairline_type": key, "order": order}
chang_id = _FEMALE_KEY_TO_CHANG.get(key)
entry["chang_id"] = chang_id
entry["ok"] = False
entry["error"] = None
entry["grown_b64"] = None
if chang_id is None:
entry["error"] = f"无对应 chang_id"
timings["per_hairstyle"].append(entry)
continue
try:
# 2a/2b/2c: generate_hairline_redraw (内部含 mask+swap+blend)
t0 = _time.perf_counter()
data = await run_in_threadpool(
generate_hairline_redraw, redraw_img, chang_id,
hair_mask=hair_mask_redraw, webui_steps=webui_steps, **_V2_FINAL_DEFAULTS)
t_redraw_pipeline = _time.perf_counter() - t0
_tm = data.get("timings_ms") or {}
entry["mask_ms"] = _tm.get("mask", 0)
entry["swap_ms"] = _tm.get("swap", 0)
entry["blend_ms"] = _tm.get("blend", 0)
entry["redraw_pipeline_ms"] = int(t_redraw_pipeline * 1000)
steps = data.get("steps") or {}
final_b64 = steps.get("final_base64") or ""
mask_b64 = steps.get("redraw_band_mask_base64") or ""
if not final_b64 or not mask_b64:
entry["error"] = f"final/遮罩缺失(final={len(final_b64)} mask={len(mask_b64)})"
timings["per_hairstyle"].append(entry)
continue
if final_b64.startswith("data:"):
final_b64 = final_b64.split(",", 1)[1]
if mask_b64.startswith("data:"):
mask_b64 = mask_b64.split(",", 1)[1]
# 3: ComfyUI 重绘
t0 = _time.perf_counter()
# max_side: 0 或 None 都让 _call_local_redraw 用默认逻辑(外层已控制分辨率)
_ms = redraw_max_side if redraw_max_side is not None and redraw_max_side > 0 else None
grown_png = await run_in_threadpool(
_call_local_redraw,
base64.b64decode(final_b64), base64.b64decode(mask_b64),
max_side=_ms, prompt=redraw_prompt)
entry["comfyui_redraw_ms"] = int((_time.perf_counter() - t0) * 1000)
if grown_png:
entry["grown_b64"] = "data:image/jpeg;base64," + _png_to_jpg_b64(grown_png)
entry["ok"] = True
else:
entry["error"] = "ComfyUI 重绘返回空"
except NoFaceError:
entry["error"] = "未检出人脸"
except Exception as ex: # noqa: BLE001
entry["error"] = str(ex)[:150]
entry["hairstyle_total_ms"] = int((_time.perf_counter() - hs_t0) * 1000)
timings["per_hairstyle"].append(entry)
timings["total_ms"] = int((_time.perf_counter() - t_total0) * 1000)
timings["downscale"] = downscale_info
timings["image_size"] = f"{w}x{h}"
return ok(timings)
except Exception as ex: # noqa: BLE001
logger.exception("debug/grow-timing 异常")
return err(1007, f"处理失败:{ex}")
# ---------------------------------------------------------------------------
# 接口 7:C 端生发 v2 —— 已弃用(add_hair2.json 用 Klein-9b 大模型,会把常驻的
# Klein-4b/Flux 挤出显存,导致接口2/3/5 耗时抖动;且业务已不再调用)。
@@ -872,7 +1015,7 @@ async def hair_grow_b(
marked_image_url: Optional[str] = Form(default=None, description="划线图片 URL"),
marked_image_base64: Optional[str] = Form(default=None, description="划线图片 base64"),
use_mask: bool = Form(default=True, description="是否画发际线(测试对比用)。false 时跳过划线检测、直接送划线图"),
prompt: str = Form(default="填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜", description="ComfyUI 提示词,会替换工作流节点60的文本"),
prompt: str = Form(default="填充遮罩区域的头发", description="ComfyUI 提示词,会替换工作流节点60的文本"),
):
# 划线图三选一取图(只需这一张)
marked_raw, e = await resolve_image_bytes(marked_image_file, marked_image_url, marked_image_base64)
@@ -1082,7 +1225,7 @@ async def hairline_generate(
gender: Optional[str] = Form(default=None, description="性别 male/female(必填)"),
hair_style: Optional[str] = Form(default=None, description="发型序号逗号分隔(必填,如 1,2,3)。female:1-5 male:1-4"),
use_mask: bool = Form(default=True, description="生发是否启用 inpaint 遮罩(同接口2,测试对比用)"),
prompt: str = Form(default="填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜", description="ComfyUI 提示词(同接口2),会替换工作流节点60的文本"),
prompt: str = Form(default="填充遮罩区域的头发", description="ComfyUI 提示词(同接口2),会替换工作流节点60的文本"),
generate_grow_image: bool = Form(default=True, description="是否生成生发效果图(ComfyUI 生发,最耗时)。默认 true 出图;false 时跳过生发,各发型 grown_image 恒为 null,仅返回三档发际线叠图与中心点"),
):
if gender not in ("male", "female"):
@@ -1476,7 +1619,7 @@ async def hairline_grow_v2(
inpainting_fill: int = Form(default=1, description="change_hair服务端重绘填充:0=保留原图 | 1=噪声 | 2=纯色 | 3=潜变量。默认 1"),
mask_blur: int = Form(default=11, description="change_hair服务端遮罩边缘模糊像素,默认 11"),
mask_dilate_scale: float = Form(default=1.0, description="change_hair服务端遮罩膨胀缩放,默认 1.0"),
comfyui_prompt: Optional[str] = Form(default=None, description="Flux-2 重绘提示词,None 用默认「填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"),
comfyui_prompt: Optional[str] = Form(default=None, description="Flux-2 重绘提示词,None 用默认「填充遮罩区域的头发」"),
beauty_alpha: float = Form(default=0.6, description="redraw_band 版 band 外的全脸美颜融入强度(0=band外无美颜纯用final,1≈整帧版),默认 0.6"),
band_lo_mult: float = Form(default=0.5, description="重绘带外推倍率下限(相对 hairline_push_cm,内轮廓=0×、原外推线=1.0×),默认 0.5"),
band_hi_mult: float = Form(default=1.5, description="重绘带外推倍率上限(相对 hairline_push_cm),默认 1.5"),
@@ -1642,7 +1785,7 @@ async def hairline_grow_v2_final_v2(
async def api_redraw(
image_file: UploadFile = File(..., description="人物图片(JPG/PNG"),
mask_file: UploadFile = File(..., description="遮罩图片(PNG,支持红/白/alpha 格式)"),
prompt: str = Form(default="填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜",
prompt: str = Form(default="填充遮罩区域的头发",
description="ComfyUI 提示词"),
):
image_bytes = await image_file.read()
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""快速测试:3张图×花瓣发型×896分辨率,新提示词"填充遮罩区域的头发"
预热1次+正式1次。
"""
import base64, json, os, time
from pathlib import Path
import requests
API = "http://127.0.0.1:8187/api/v1/debug/grow-timing"
TOKEN = "dev-shared-secret-2026"
PROMPT = "填充遮罩区域的头发"
OUT = Path("/home/ubuntu/hair/benchmark_out/bench6")
OUT.mkdir(parents=True, exist_ok=True)
IMGS = [
("asdf", "/home/ubuntu/hair/image/asdf.jpg"),
("qwer", "/home/ubuntu/hair/image/qwer.jpg"),
("girl5", "/home/ubuntu/hair/image/girl_img/girl5.jpg"),
]
def call(img_path, save_grown=None, timeout=300):
data = {"hair_style": "2", "webui_steps": "15", "redraw_max_side": "896", "redraw_prompt": PROMPT}
t0 = time.perf_counter()
with open(img_path, "rb") as f:
r = requests.post(API, headers={"X-Internal-Token": TOKEN},
files={"image_file": (os.path.basename(img_path), f, "image/jpeg")},
data=data, timeout=timeout)
wall = time.perf_counter() - t0
j = r.json()
d = j["data"]; hs = d["per_hairstyle"][0]
if save_grown and hs.get("grown_b64"):
b = hs["grown_b64"].split(",")[1] if "," in hs["grown_b64"] else hs["grown_b64"]
open(save_grown, "wb").write(base64.b64decode(b))
return {"ok": hs.get("ok"), "total_ms": d["total_ms"], "comfy_ms": hs.get("comfyui_redraw_ms"),
"grown_path": str(save_grown) if save_grown and hs.get("ok") else None}
results = []
for ilabel, ipath in IMGS:
print(f"预热 {ilabel}...", flush=True)
call(ipath)
save = OUT / f"{ilabel}_flower_896.jpg"
print(f"正式 {ilabel}...", flush=True)
r = call(ipath, save_grown=save)
r["img"] = ilabel
print(f" -> total={r['total_ms']}ms ok={r['ok']}", flush=True)
results.append(r)
json.dump({"prompt": PROMPT, "results": results}, open(OUT/"results.json","w"), ensure_ascii=False, indent=2)
print(f"\n✓ 完成 {sum(1 for r in results if r['ok'])}/3", flush=True)
+1 -1
View File
@@ -55,7 +55,7 @@ def gpu_used():
def call(img_path, hair_num, model_file, res_val):
fd = {"gender": "female", "hair_style": str(hair_num), "use_mask": "true",
"prompt": "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"}
"prompt": "填充遮罩区域的头发"}
if model_file:
fd["flux_model"] = model_file
if res_val != "":
+1 -1
View File
@@ -54,7 +54,7 @@ def call(img_path, model_file, res_val):
"gender": "female",
"hair_style": "2", # 花瓣形
"use_mask": "true",
"prompt": "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜",
"prompt": "填充遮罩区域的头发",
}
if model_file:
fd["flux_model"] = model_file
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""分辨率对比测试:4图×5发型=20行,每行4种分辨率(不缩放/896/768/640)steps=15。
热数据:每个组合预热1次(丢弃)+正式1次。OOM的跳过记录为失败。
"""
import base64
import json
import os
import time
from pathlib import Path
import requests
API = "http://127.0.0.1:8187/api/v1/debug/grow-timing"
TOKEN = "dev-shared-secret-2026"
OUT = Path("/home/ubuntu/hair/benchmark_out/bench3")
OUT.mkdir(parents=True, exist_ok=True)
IMGS = [
("asdf", "/home/ubuntu/hair/image/asdf.jpg"),
("qwer", "/home/ubuntu/hair/image/qwer.jpg"),
("girl2", "/home/ubuntu/hair/image/girl_img/girl2.jpg"),
("girl5", "/home/ubuntu/hair/image/girl_img/girl5.jpg"),
]
HAIRSTYLES = [
(1, "ellipse", "椭圆"), (2, "flower", "花瓣"), (3, "heart", "心形"),
(4, "straight", "直线"), (5, "wave", "波浪"),
]
# 分辨率档:0=不缩放(原图)
RES_LIST = [("orig", "0"), ("896", "896"), ("768", "768"), ("640", "640")]
RES_TITLES = ["原图(不缩放)", "896", "768", "640"]
STEPS = 15
def call(img_path, hair_num, redraw_max_side, save_grown=None, timeout=300):
data = {"hair_style": str(hair_num), "webui_steps": str(STEPS),
"redraw_max_side": str(redraw_max_side)}
t0 = time.perf_counter()
try:
with open(img_path, "rb") as f:
r = requests.post(API, headers={"X-Internal-Token": TOKEN},
files={"image_file": (os.path.basename(img_path), f, "image/jpeg")},
data=data, timeout=timeout)
wall = time.perf_counter() - t0
j = r.json()
if j.get("code") != 0:
return {"ok": False, "error": j.get("message", "")[:80], "wall": wall}
d = j["data"]
hs = d["per_hairstyle"][0]
if save_grown and hs.get("grown_b64"):
b = hs["grown_b64"].split(",")[1] if "," in hs["grown_b64"] else hs["grown_b64"]
with open(save_grown, "wb") as gf:
gf.write(base64.b64decode(b))
return {
"ok": hs.get("ok", False), "wall": wall,
"total_ms": d["total_ms"], "swap_ms": hs.get("swap_ms"),
"comfy_ms": hs.get("comfyui_redraw_ms"),
"error": hs.get("error"),
}
except Exception as e:
return {"ok": False, "error": str(e)[:80], "wall": time.perf_counter() - t0}
def main():
rows = []
total = len(IMGS) * len(HAIRSTYLES) * len(RES_LIST) * 2
idx = 0
for ilabel, ipath in IMGS:
for hnum, hkey, hname in HAIRSTYLES:
cells = []
for (rlabel, rval), rtitle in zip(RES_LIST, RES_TITLES):
# 预热
idx += 1
print(f"[{idx}/{total}] 预热 {ilabel}|{hname}|{rtitle}", flush=True)
try:
call(ipath, hnum, rval, timeout=120)
except Exception:
pass # 预热失败(可能OOM)不中断
# 正式
idx += 1
save = OUT / f"{ilabel}_{hkey}_{rlabel}.jpg"
print(f"[{idx}/{total}] 正式 {ilabel}|{hname}|{rtitle}", flush=True)
r = call(ipath, hnum, rval, save_grown=save, timeout=300)
r["res_label"] = rlabel; r["res_title"] = rtitle
r["grown_path"] = str(save) if r.get("ok") else None
status = f"{r.get('total_ms')}ms" if r.get("ok") else f"FAIL:{r.get('error','')[:30]}"
print(f" -> {status}", flush=True)
cells.append(r)
rows.append({"img": ilabel, "img_path": ipath,
"hair_num": hnum, "hair_key": hkey, "hair_name": hname,
"cells": cells})
with open(OUT / "results.json", "w", encoding="utf-8") as f:
json.dump({"res_titles": RES_TITLES, "rows": rows}, f, ensure_ascii=False, indent=2)
ok = sum(1 for row in rows for c in row["cells"] if c.get("ok"))
print(f"\n✓ 完成: {ok}/{len(rows)*len(RES_LIST)} 成功 -> {OUT/'results.json'}", flush=True)
if __name__ == "__main__":
main()
+103
View File
@@ -0,0 +1,103 @@
#!/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 = ['<th class="col-label">原图</th>']
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'<th class="col-label"><div class="col-title">{t}</div>'
f'<div class="col-stat">均{avg/1000:.1f}s</div></th>')
# 表体
body_rows = []
for r in rows:
label = f'<div class="row-label">{r["img"]}<br><b>{r["hair_name"]}</b></div>'
# 原图缩略图(用 orig 档的结果当原图展示,或用原图文件)
orig_cell = f'<td class="cell-orig"><div class="row-label-cell">{label}</div></td>'
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'<td class="cell-result"><img class="result-img" src="{src}" loading="lazy">'
f'<div class="cell-time">{t/1000:.1f}s</div></td>')
else:
cells.append(f'<td class="cell-result"><div class="na">⚠<br>{c.get("error","")[:20]}</div></td>')
body_rows.append(f'<tr>{"".join(cells)}</tr>')
html = f"""<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>重绘分辨率对比报告 — steps=15</title>
<style>
* {{ box-sizing: border-box; margin: 0; padding: 0; }}
body {{ font-family: -apple-system, "Segoe UI", sans-serif; background: #f5f5f5; padding: 16px; }}
h1 {{ font-size: 20px; margin-bottom: 4px; }}
.subtitle {{ color: #888; font-size: 12px; margin-bottom: 12px; }}
.legend {{ background: #fff; border-radius: 8px; padding: 10px 16px; margin-bottom: 12px; font-size: 12px; color: #555; }}
.scroll-wrap {{ overflow-x: auto; }}
table {{ border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.06); }}
th, td {{ border: 1px solid #eee; padding: 6px; vertical-align: top; text-align: center; }}
th {{ background: #f9fafb; position: sticky; top: 0; }}
.col-label {{ min-width: 130px; max-width: 150px; }}
.col-title {{ font-size: 12px; font-weight: 700; color: #374151; }}
.col-stat {{ font-size: 10px; color: #9ca3af; margin-top: 2px; }}
.row-label {{ font-size: 11px; color: #6b7280; }}
.row-label b {{ color: #1f2937; }}
img {{ border-radius: 4px; max-width: 130px; max-height: 160px; object-fit: contain; background: #f3f4f6; }}
.cell-time {{ font-size: 10px; color: #9ca3af; margin-top: 2px; }}
.na {{ color: #d1d5db; font-size: 12px; padding: 40px 10px; }}
</style>
</head>
<body>
<h1>📊 重绘分辨率对比报告</h1>
<p class="subtitle">4图×5发型=20行 · 每行4分辨率(原图不缩放/896/768/640) · steps=15 · 热数据 · 80/80成功 · 峰值21.2GB · 0 OOM</p>
<div class="legend">列标题下显示<b>平均总耗时</b>。横向滚动查看。原图列含图片名+发型名。每格下方为该次总耗时。</div>
<div class="scroll-wrap">
<table>
<tr>{"".join(headers)}</tr>
{"".join(body_rows)}
</table>
</div>
</body>
</html>"""
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()
+98
View File
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""分辨率对比测试(新提示词版):4图×5发型=20行,每行4种分辨率,steps=15。
提示词固定为 "填充遮罩区域的头发"
热数据:预热1次+正式1次。
"""
import base64
import json
import os
import time
from pathlib import Path
import requests
API = "http://127.0.0.1:8187/api/v1/debug/grow-timing"
TOKEN = "dev-shared-secret-2026"
PROMPT = "填充遮罩区域的头发"
OUT = Path("/home/ubuntu/hair/benchmark_out/bench7")
OUT.mkdir(parents=True, exist_ok=True)
IMGS = [
("asdf", "/home/ubuntu/hair/image/asdf.jpg"),
("qwer", "/home/ubuntu/hair/image/qwer.jpg"),
("girl2", "/home/ubuntu/hair/image/girl_img/girl2.jpg"),
("girl5", "/home/ubuntu/hair/image/girl_img/girl5.jpg"),
]
HAIRSTYLES = [
(1, "ellipse", "椭圆"), (2, "flower", "花瓣"), (3, "heart", "心形"),
(4, "straight", "直线"), (5, "wave", "波浪"),
]
RES_LIST = [("orig", "0"), ("896", "896"), ("768", "768"), ("640", "640")]
RES_TITLES = ["原图(不缩放)", "896", "768", "640"]
STEPS = 15
def call(img_path, hair_num, redraw_max_side, save_grown=None, timeout=300):
data = {"hair_style": str(hair_num), "webui_steps": str(STEPS),
"redraw_max_side": str(redraw_max_side), "redraw_prompt": PROMPT}
t0 = time.perf_counter()
try:
with open(img_path, "rb") as f:
r = requests.post(API, headers={"X-Internal-Token": TOKEN},
files={"image_file": (os.path.basename(img_path), f, "image/jpeg")},
data=data, timeout=timeout)
wall = time.perf_counter() - t0
j = r.json()
if j.get("code") != 0:
return {"ok": False, "error": j.get("message", "")[:80], "wall": wall}
d = j["data"]
hs = d["per_hairstyle"][0]
if save_grown and hs.get("grown_b64"):
b = hs["grown_b64"].split(",")[1] if "," in hs["grown_b64"] else hs["grown_b64"]
with open(save_grown, "wb") as gf:
gf.write(base64.b64decode(b))
return {
"ok": hs.get("ok", False), "wall": wall,
"total_ms": d["total_ms"], "swap_ms": hs.get("swap_ms"),
"comfy_ms": hs.get("comfyui_redraw_ms"),
"error": hs.get("error"),
}
except Exception as e:
return {"ok": False, "error": str(e)[:80], "wall": time.perf_counter() - t0}
def main():
rows = []
total = len(IMGS) * len(HAIRSTYLES) * len(RES_LIST) * 2
idx = 0
for ilabel, ipath in IMGS:
for hnum, hkey, hname in HAIRSTYLES:
cells = []
for (rlabel, rval), rtitle in zip(RES_LIST, RES_TITLES):
idx += 1
print(f"[{idx}/{total}] 预热 {ilabel}|{hname}|{rtitle}", flush=True)
try:
call(ipath, hnum, rval, timeout=120)
except Exception:
pass
idx += 1
save = OUT / f"{ilabel}_{hkey}_{rlabel}.jpg"
print(f"[{idx}/{total}] 正式 {ilabel}|{hname}|{rtitle}", flush=True)
r = call(ipath, hnum, rval, save_grown=save, timeout=300)
r["res_label"] = rlabel; r["res_title"] = rtitle
r["grown_path"] = str(save) if r.get("ok") else None
status = f"{r.get('total_ms')}ms" if r.get("ok") else f"FAIL:{r.get('error','')[:30]}"
print(f" -> {status}", flush=True)
cells.append(r)
rows.append({"img": ilabel, "img_path": ipath,
"hair_num": hnum, "hair_key": hkey, "hair_name": hname,
"cells": cells})
with open(OUT / "results.json", "w", encoding="utf-8") as f:
json.dump({"res_titles": RES_TITLES, "prompt": PROMPT, "rows": rows}, f, ensure_ascii=False, indent=2)
ok = sum(1 for row in rows for c in row["cells"] if c.get("ok"))
print(f"\n✓ 完成: {ok}/{len(rows)*len(RES_LIST)} 成功 -> {OUT/'results.json'}", flush=True)
if __name__ == "__main__":
main()
+121
View File
@@ -0,0 +1,121 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""swap步数 + 重绘分辨率 对比测试(热数据)。
每个组合: 预热1次(丢弃) + 正式测1次(取热数据)。
B维度: steps=10/15/20 (分辨率固定896)
C维度: 分辨率=640/896/1024 (steps固定15)
4图×2发型=8组 × 6档 × 2次(预热+正式) = 96次
"""
import base64
import json
import os
import time
from pathlib import Path
import requests
API = "http://127.0.0.1:8187/api/v1/debug/grow-timing"
TOKEN = "dev-shared-secret-2026"
OUT = Path("/home/ubuntu/hair/benchmark_out/bench2")
OUT.mkdir(parents=True, exist_ok=True)
IMGS = [
("asdf", "/home/ubuntu/hair/image/asdf.jpg"),
("qwer", "/home/ubuntu/hair/image/qwer.jpg"),
("girl2", "/home/ubuntu/hair/image/girl_img/girl2.jpg"),
("girl5", "/home/ubuntu/hair/image/girl_img/girl5.jpg"),
]
HAIRSTYLES = [(5, "wave", "波浪"), (3, "heart", "心形")]
# B维度: swap步数对比 (分辨率固定896)
B_STEPS = [10, 15, 20]
# C维度: 重绘分辨率对比 (steps固定15)
C_RES = [640, 896, 1024]
def call(img_path, hair_num, webui_steps=None, redraw_max_side=None, save_grown=None):
"""调调试接口。返回 dict。save_grown 非None时把结果图存到该路径。"""
data = {"hair_style": str(hair_num)}
if webui_steps is not None:
data["webui_steps"] = str(webui_steps)
if redraw_max_side is not None:
data["redraw_max_side"] = str(redraw_max_side)
t0 = time.perf_counter()
try:
with open(img_path, "rb") as f:
r = requests.post(API, headers={"X-Internal-Token": TOKEN},
files={"image_file": (os.path.basename(img_path), f, "image/jpeg")},
data=data, timeout=300)
wall = time.perf_counter() - t0
j = r.json()
if j.get("code") != 0:
return {"ok": False, "error": j.get("message", "")[:100], "wall": wall}
d = j["data"]
hs = d["per_hairstyle"][0]
if save_grown and hs.get("grown_b64"):
b = hs["grown_b64"].split(",")[1] if "," in hs["grown_b64"] else hs["grown_b64"]
with open(save_grown, "wb") as gf:
gf.write(base64.b64decode(b))
return {
"ok": hs.get("ok", False), "wall": wall,
"total_ms": d["total_ms"], "ctx_ms": d["extract_context_ms"],
"mask_ms": hs.get("mask_ms"), "swap_ms": hs.get("swap_ms"),
"blend_ms": hs.get("blend_ms"), "comfy_ms": hs.get("comfyui_redraw_ms"),
"error": hs.get("error"),
}
except Exception as e:
return {"ok": False, "error": str(e)[:100], "wall": time.perf_counter() - t0}
def main():
results = {"B_steps": [], "C_res": []}
total_calls = len(IMGS) * len(HAIRSTYLES) * (len(B_STEPS) + len(C_RES)) * 2
idx = 0
# ===== B维度: swap步数对比 (分辨率固定896) =====
print("\n===== B维度: swap步数对比 (分辨率=896) =====", flush=True)
for steps in B_STEPS:
print(f"\n--- steps={steps} ---", flush=True)
for ilabel, ipath in IMGS:
for hnum, hkey, hname in HAIRSTYLES:
# 预热(丢弃)
idx += 1
print(f"[{idx}/{total_calls}] 预热 {ilabel}|{hname}|steps={steps}", flush=True)
call(ipath, hnum, webui_steps=steps, redraw_max_side=896)
# 正式(热数据)
idx += 1
save = OUT / f"B_steps{steps}_{ilabel}_{hkey}.jpg"
print(f"[{idx}/{total_calls}] 正式 {ilabel}|{hname}|steps={steps}", flush=True)
r = call(ipath, hnum, webui_steps=steps, redraw_max_side=896, save_grown=save)
r["steps"] = steps; r["img"] = ilabel; r["hair"] = hkey; r["hair_name"] = hname
r["grown_path"] = str(save) if r.get("ok") else None
print(f" -> total={r.get('total_ms')}ms swap={r.get('swap_ms')}ms comfy={r.get('comfy_ms')}ms ok={r.get('ok')}", flush=True)
results["B_steps"].append(r)
# ===== C维度: 重绘分辨率对比 (steps固定15) =====
print("\n===== C维度: 重绘分辨率对比 (steps=15) =====", flush=True)
for res in C_RES:
print(f"\n--- res={res} ---", flush=True)
for ilabel, ipath in IMGS:
for hnum, hkey, hname in HAIRSTYLES:
idx += 1
print(f"[{idx}/{total_calls}] 预热 {ilabel}|{hname}|res={res}", flush=True)
call(ipath, hnum, webui_steps=15, redraw_max_side=res)
idx += 1
save = OUT / f"C_res{res}_{ilabel}_{hkey}.jpg"
print(f"[{idx}/{total_calls}] 正式 {ilabel}|{hname}|res={res}", flush=True)
r = call(ipath, hnum, webui_steps=15, redraw_max_side=res, save_grown=save)
r["res"] = res; r["img"] = ilabel; r["hair"] = hkey; r["hair_name"] = hname
r["grown_path"] = str(save) if r.get("ok") else None
print(f" -> total={r.get('total_ms')}ms swap={r.get('swap_ms')}ms comfy={r.get('comfy_ms')}ms ok={r.get('ok')}", flush=True)
results["C_res"].append(r)
with open(OUT / "results.json", "w", encoding="utf-8") as f:
json.dump(results, f, ensure_ascii=False, indent=2)
ok = sum(1 for r in results["B_steps"] + results["C_res"] if r.get("ok"))
print(f"\n✓ 完成: {ok}/{len(results['B_steps'])+len(results['C_res'])} 成功 -> {OUT/'results.json'}", flush=True)
if __name__ == "__main__":
main()
+157
View File
@@ -0,0 +1,157 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""生成 swap步数 + 重绘分辨率 对比报告 HTML。"""
import json
import os
from collections import defaultdict
from pathlib import Path
OUT = Path("/home/ubuntu/hair/benchmark_out/bench2")
RESULTS = OUT / "results.json"
HTML = OUT / "report.html"
def img_src(path):
if not path or not os.path.isfile(path):
return None
# benchmark_out/bench2/xxx.jpg -> bench2/xxx.jpg (报告在 static/ 下部署时调整)
p = str(path)
return "bench2/" + os.path.basename(p)
def main():
d = json.load(open(RESULTS, encoding="utf-8"))
b_data = d["B_steps"] # steps 对比
c_data = d["C_res"] # 分辨率对比
# B维度聚合
by_steps = defaultdict(list)
for r in b_data:
by_steps[r["steps"]].append(r)
b_summary = []
for s in sorted(by_steps):
rs = by_steps[s]
b_summary.append({
"label": f"steps={s}", "n": len(rs),
"swap": sum(r["swap_ms"] for r in rs) // len(rs),
"total": sum(r["total_ms"] for r in rs) // len(rs),
})
# C维度聚合
by_res = defaultdict(list)
for r in c_data:
by_res[r["res"]].append(r)
c_summary = []
for res in sorted(by_res):
rs = by_res[res]
c_summary.append({
"label": f"res={res}", "n": len(rs),
"comfy": sum(r["comfy_ms"] for r in rs) // len(rs),
"total": sum(r["total_ms"] for r in rs) // len(rs),
})
# B维度明细行(每图每发型每步数)
b_rows = []
for r in sorted(b_data, key=lambda x: (x["img"], x["hair"], x["steps"])):
src = img_src(r.get("grown_path"))
b_rows.append(f"""<tr>
<td>{r['img']}</td><td>{r['hair_name']}</td><td>{r['steps']}</td>
<td>{r.get('swap_ms','?')}</td><td>{r.get('comfy_ms','?')}</td><td>{r.get('total_ms','?')}</td>
<td>{f'<img src="{src}" loading="lazy">' if src else ''}</td></tr>""")
# C维度明细行
c_rows = []
for r in sorted(c_data, key=lambda x: (x["img"], x["hair"], x["res"])):
src = img_src(r.get("grown_path"))
c_rows.append(f"""<tr>
<td>{r['img']}</td><td>{r['hair_name']}</td><td>{r['res']}</td>
<td>{r.get('swap_ms','?')}</td><td>{r.get('comfy_ms','?')}</td><td>{r.get('total_ms','?')}</td>
<td>{f'<img src="{src}" loading="lazy">' if src else ''}</td></tr>""")
def bar_row(label, val, max_val, color, unit="ms"):
pct = max(1, val / max_val * 100) if max_val else 0
return f'<div class="step-row"><div class="step-name">{label}</div>' \
f'<div class="step-bar-wrap"><div class="step-bar {color}" style="width:{pct}%">{val}{unit}</div></div>' \
f'<div class="step-time">{val}{unit}</div></div>'
# B维度汇总条形图
b_max_swap = max(s["swap"] for s in b_summary)
b_bars = "".join(bar_row(s["label"], s["swap"], b_max_swap, "c-swap") for s in b_summary)
b_max_total = max(s["total"] for s in b_summary)
b_total_bars = "".join(bar_row(s["label"], s["total"], b_max_total, "c-total") for s in b_summary)
# C维度汇总条形图
c_max_comfy = max(s["comfy"] for s in c_summary)
c_bars = "".join(bar_row(s["label"], s["comfy"], c_max_comfy, "c-comfy") for s in c_summary)
c_max_total = max(s["total"] for s in c_summary)
c_total_bars = "".join(bar_row(s["label"], s["total"], c_max_total, "c-total") for s in c_summary)
html = f"""<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>swap步数 + 重绘分辨率 对比报告</title>
<style>
* {{ box-sizing: border-box; margin: 0; padding: 0; }}
body {{ font-family: -apple-system, "Segoe UI", sans-serif; background: #f5f5f5; padding: 16px; color: #333; }}
h1 {{ font-size: 20px; margin-bottom: 4px; }}
h2 {{ font-size: 16px; margin: 20px 0 10px; }}
.subtitle {{ color: #888; font-size: 12px; margin-bottom: 14px; }}
.card {{ background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 16px; overflow: hidden; }}
.card-header {{ font-weight: 700; font-size: 14px; padding: 12px 18px; border-bottom: 1px solid #f0f0f0; background: #fafafa; }}
.card-body {{ padding: 18px; }}
.summary-grid {{ display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }}
.step-row {{ display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }}
.step-name {{ width: 100px; flex-shrink: 0; font-weight: 600; }}
.step-bar-wrap {{ flex: 1; background: #f3f4f6; border-radius: 4px; height: 24px; min-width: 200px; }}
.step-bar {{ height: 100%; border-radius: 4px; display: flex; align-items: center; padding-left: 8px; color: #fff; font-size: 11px; font-weight: 600; min-width: 2px; }}
.step-time {{ width: 70px; text-align: right; font-weight: 600; flex-shrink: 0; font-variant-numeric: tabular-nums; }}
.c-swap {{ background: #f59e0b; }} .c-comfy {{ background: #ef4444; }} .c-total {{ background: #2563eb; }}
table {{ border-collapse: collapse; width: 100%; font-size: 12px; }}
th, td {{ border: 1px solid #eee; padding: 5px 8px; text-align: center; }}
th {{ background: #f9fafb; font-weight: 600; position: sticky; top: 0; }}
td img {{ max-height: 100px; max-width: 80px; border-radius: 4px; }}
.scroll {{ max-height: 400px; overflow: auto; }}
.note {{ background: #fef3c7; border-radius: 8px; padding: 10px 14px; font-size: 12px; color: #92400e; margin-top: 10px; }}
</style>
</head>
<body>
<h1>📊 swap步数 + 重绘分辨率 对比报告</h1>
<p class="subtitle">4图(asdf/qwer/girl2/girl5) × 2发型(波浪/心形) · 热数据(预热后取第2次) · 48/48成功 · 峰值20.6GB · 0 OOM</p>
<div class="note">💡 结论速览: B维度 steps 10→20 swap从3.0s→3.9s(每步省~90ms)C维度 res 640比896省3s(comfy 4.3s vs 7.3s)1024与896接近。</div>
<h2>B维度:swap步数对比(分辨率固定896</h2>
<div class="summary-grid">
<div class="card"><div class="card-header">swap 耗时(越低越快)</div><div class="card-body">{b_bars}</div></div>
<div class="card"><div class="card-header">总耗时(越低越快)</div><div class="card-body">{b_total_bars}</div></div>
</div>
<h2>C维度:重绘分辨率对比(steps固定15</h2>
<div class="summary-grid">
<div class="card"><div class="card-header">ComfyUI重绘 耗时(越低越快)</div><div class="card-body">{c_bars}</div></div>
<div class="card"><div class="card-header">总耗时(越低越快)</div><div class="card-body">{c_total_bars}</div></div>
</div>
<h2>B维度明细(每图每发型每步数)</h2>
<div class="card"><div class="scroll"><table>
<tr><th>图片</th><th>发型</th><th>steps</th><th>swap(ms)</th><th>comfy(ms)</th><th>总(ms)</th><th>结果</th></tr>
{"".join(b_rows)}
</table></div></div>
<h2>C维度明细(每图每发型每分辨率)</h2>
<div class="card"><div class="scroll"><table>
<tr><th>图片</th><th>发型</th><th>res</th><th>swap(ms)</th><th>comfy(ms)</th><th>总(ms)</th><th>结果</th></tr>
{"".join(c_rows)}
</table></div></div>
</body>
</html>"""
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()
+11 -8
View File
@@ -508,13 +508,14 @@ def _segment_hair(image_bgr, seg_model, landmarks, w, h):
# ---------------------------------------------------------------------------
def _call_swap(image_bgr, hairline_id, is_hr, ext_mask_bool, denoising_strength,
inpainting_fill=1, mask_blur=11, mask_dilate_scale=1.0):
inpainting_fill=1, mask_blur=11, mask_dilate_scale=1.0, webui_steps=None):
"""调 change_hair /api/swapHair/v1,返回与输入同分辨率同对齐的换发型结果(BGR)。
ext_mask_bool 非 None 时作为 ext_mask 传入(swap_mode=ext_mask)。
denoising_strengthwebui img2img 重绘强度(越大生发越激进),透传给换发型。
inpainting_fill / mask_blur / mask_dilate_scale:服务端重绘参数(透传给 change_hair
默认值=服务端原始硬编码值,未传时行为不变)。详见 change_hair 文档。
webui_stepswebui img2img 采样步数,None 用服务端默认(15)。
"""
import requests
@@ -530,6 +531,8 @@ def _call_swap(image_bgr, hairline_id, is_hr, ext_mask_bool, denoising_strength,
"mask_blur": int(mask_blur),
"mask_dilate_scale": float(mask_dilate_scale),
}
if webui_steps is not None:
payload["webui_steps"] = int(webui_steps)
if ext_mask_bool is not None:
mbuf = cv2.imencode(".png", (ext_mask_bool.astype(np.uint8)) * 255)[1]
payload["ext_mask"] = "data:image/png;base64," + base64.b64encode(mbuf.tobytes()).decode()
@@ -855,7 +858,7 @@ def _grow_core(image_bgr, hairline_id, *, is_hr, seg_model, erode_cm, swap_mode,
mb_levels, hairline_push_cm, hairline_edge, blend_method, color_match,
color_match_strength, mb_feather_px, transition_band_px,
inpainting_fill, mask_blur, mask_dilate_scale, rid, render_viz=True,
hair_mask=None):
hair_mask=None, webui_steps=None):
"""接口11 共享核心:遮罩(pushed)→生成→硬贴回→接缝融合,产出 ④ final。
不做任何重绘。返回中间产物 dict(供接口11 构造响应、接口12 取 final+重绘带用):
@@ -897,7 +900,7 @@ def _grow_core(image_bgr, hairline_id, *, is_hr, seg_model, erode_cm, swap_mode,
ext_mask = mask_bool if swap_mode == "ext_mask" else None
swap_result = _call_swap(image_bgr, hairline_id, is_hr, ext_mask, denoising_strength,
inpainting_fill=inpainting_fill, mask_blur=mask_blur,
mask_dilate_scale=mask_dilate_scale)
mask_dilate_scale=mask_dilate_scale, webui_steps=webui_steps)
t_swap = time.time() - t0
# 步骤3:严格按遮罩硬贴回(无融合,用于对比)
@@ -935,7 +938,7 @@ def generate_hairline_grow(image_bgr, hairline_id, is_hr=False, seg_model="segfo
color_match_strength=1.0, mb_feather_px=1,
transition_band_px=-1,
inpainting_fill=1, mask_blur=11, mask_dilate_scale=1.0,
rid=None):
rid=None, webui_steps=None):
"""接口11 完整管线(**不含重绘**,重绘见接口12 generate_hairline_redraw)。
返回可直接进 ok() 的 data dict。未检出人脸抛 NoFaceError。
@@ -957,7 +960,7 @@ def generate_hairline_grow(image_bgr, hairline_id, is_hr=False, seg_model="segfo
color_match=color_match, color_match_strength=color_match_strength,
mb_feather_px=mb_feather_px, transition_band_px=transition_band_px,
inpainting_fill=inpainting_fill, mask_blur=mask_blur,
mask_dilate_scale=mask_dilate_scale, rid=rid)
mask_dilate_scale=mask_dilate_scale, rid=rid, webui_steps=webui_steps)
mask_viz = core["mask_viz"]
alpha = core["alpha"]
w, h = core["w"], core["h"]
@@ -1035,7 +1038,7 @@ def generate_hairline_redraw(image_bgr, hairline_id, is_hr=False, seg_model="seg
inpainting_fill=1, mask_blur=11, mask_dilate_scale=1.0,
comfyui_prompt=None, beauty_alpha=0.6,
band_lo_mult=0.5, band_hi_mult=1.5, rid=None,
hair_mask=None):
hair_mask=None, webui_steps=None):
"""接口12 发际线带重绘。内部先跑接口11 核心拿到 ④ final,再取 ⑤-① 发际线重绘带
(外推↔内推之间、经 baseline 截断只留上部)作遮罩。
@@ -1064,7 +1067,7 @@ def generate_hairline_redraw(image_bgr, hairline_id, is_hr=False, seg_model="seg
mb_feather_px=mb_feather_px, transition_band_px=transition_band_px,
inpainting_fill=inpainting_fill, mask_blur=mask_blur,
mask_dilate_scale=mask_dilate_scale, rid=rid, render_viz=False,
hair_mask=hair_mask)
hair_mask=hair_mask, webui_steps=webui_steps)
final = core["final"]
mask_viz = core["mask_viz"]
w, h = core["w"], core["h"]
@@ -1107,7 +1110,7 @@ def generate_hairline_redraw(image_bgr, hairline_id, is_hr=False, seg_model="seg
"hairline_id": hairline_id,
"blend_method": blend_method,
"hairline_push_cm": round(float(hairline_push_cm), 2),
"comfyui_prompt": comfyui_prompt or "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜",
"comfyui_prompt": comfyui_prompt or "填充遮罩区域的头发",
"beauty_alpha": beauty_alpha,
"px_per_cm": round(float(px_per_cm), 4),
"mask_pixels": mask_viz["mask_pixels"],
+1 -1
View File
@@ -410,7 +410,7 @@
},
"60": {
"inputs": {
"text": "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"
"text": "填充遮罩区域的头发"
},
"class_type": "JjkText",
"_meta": {
+19 -4
View File
@@ -32,18 +32,28 @@ _SEED_NODE = "6" # RandomNoise
_PROMPT_NODE = "60" # JjkText:提示词
_UNET_NODE = "16" # UNETLoader / UnetLoaderGGUFFlux 模型加载
_CLIP_NODE = "61" # CLIPLoaderqwen 文本编码器
_VAE_NODE = "3" # VAELoader
# Flux 模型 → 配套文本编码器映射。切换 unet 时自动同步编码器,避免维度不匹配。
# 规则:4b 系列配 qwen_3_4b9b 系列(fp8/GGUF)配 qwen_3_8b_fp8mixed。
def _clip_for_unet(unet_name: str) -> str | None:
"""根据 unet 文件名推断配套的文本编码器文件名;无法推断返回 None。"""
low = unet_name.lower()
if "4b" in low and "9b" not in low:
return "qwen_3_4b.safetensors"
if "9b" in low:
if "9b" in low: # Flux.2 9B 系列
return "qwen_3_8b_fp8mixed.safetensors"
if "z-image" in low: # Z-Image-Turbo 用 4B 编码器
return "qwen_3_4b.safetensors"
if "4b" in low: # Flux.2 4B
return "qwen_3_4b.safetensors"
return None
# Flux 模型 → 配套 VAE 映射。Z-Image 用 ae.safetensorsFlux.2 系列用 flux2-vae。
def _vae_for_unet(unet_name: str) -> str | None:
"""根据 unet 文件名推断配套 VAE 文件名;无法推断返回 None(保持工作流原值)。"""
low = unet_name.lower()
if "z-image" in low:
return "ae.safetensors"
return None # Flux.2 系列 vae 在工作流里已正确配置,不覆盖
_wf_cache: dict[str, dict] = {} # path → workflow JSON
_wf_output_node: dict[str, str] = {} # path → SaveImage 节点 ID
@@ -153,6 +163,11 @@ def run(rgba_png_bytes: bytes, timeout: float = COMFY_TIMEOUT, prompt: str = Non
clip_name = _clip_for_unet(unet_name)
if clip_node is not None and clip_name is not None:
clip_node["inputs"]["clip_name"] = clip_name
# 同步切换 VAEZ-Image 用 ae.safetensorsFlux.2 保持 flux2-vae
vae_node = wf.get(_VAE_NODE)
vae_name = _vae_for_unet(unet_name)
if vae_node is not None and vae_name is not None:
vae_node["inputs"]["vae_name"] = vae_name
# 诊断:落盘实际提交的工作流 + 输入图,便于和手动 ComfyUI 跑的对比
try:
+2 -2
View File
@@ -16,7 +16,7 @@ from . import comfyui
logger = logging.getLogger("hair.worker")
_DEFAULT_PROMPT = "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"
_DEFAULT_PROMPT = "填充遮罩区域的头发"
_REPO = os.path.dirname(os.path.dirname(__file__))
_REPAINT_WORKFLOW = os.path.join(_REPO, "0716add-hair-api.json")
@@ -62,7 +62,7 @@ def run_redraw(image_bytes: bytes, mask_bytes: bytes,
Args:
image_bytes: 人物图片字节(JPG/PNG
mask_bytes: 遮罩图片字节(支持红/白/alpha 遮罩格式)
prompt: 提示词,None 用默认 "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"
prompt: 提示词,None 用默认 "填充遮罩区域的头发"
timeout: ComfyUI 超时秒数
front: True 时任务插到 ComfyUI 队列最前(接口2 时延敏感路径用)
unet_name: 非 None 时切换 Flux 模型(如 flux-2-klein-9b-Q5_K_M.gguf),None 用工作流默认
+5 -3
View File
@@ -46,7 +46,7 @@ _BLACK_TEXTURE_DIR = os.path.join(_REPO, "hairline_texture_black")
# 关键:ComfyUI 单卡显存装不下 Flux(7.7G)+qwen CLIP(3.9G) 同驻,靠缓存 CLIP 文本条件避免重载。
# prompt 不同会使缓存失效 → 重载 CLIP 并挤出 Flux(每次 +4s)。三接口用同一字符串即可全程命中。
# 与 app.py 接口2/接口3 的默认 prompt 保持一致;可用 REDRAW_PROMPT 覆盖。
_REDRAW_PROMPT = os.getenv("REDRAW_PROMPT", "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜")
_REDRAW_PROMPT = os.getenv("REDRAW_PROMPT", "填充遮罩区域的头发")
# 接口2 女重绘整条管线(swapHair + ComfyUI)送模型前限边。真实照片常达 1257x1495:
# 全分辨率 ComfyUI 重绘要 13~21s 且激活显存把模型挤出。女性路径含 swapHair(SD WebUI ~5.3s
@@ -55,7 +55,7 @@ _REDRAW_PROMPT = os.getenv("REDRAW_PROMPT", "填充遮罩区域的头发,皮
_REDRAW_MAX_SIDE = int(os.getenv("REDRAW_MAX_SIDE", "896"))
def _call_local_redraw(image_png_bytes, mask_png_bytes, timeout=300.0,
max_side=None, unet_name=None):
max_side=None, unet_name=None, prompt=None):
"""直接调 ComfyUI 重绘(替代原 local_test HTTP 服务)。
传 final 图 + 纯红遮罩 PNG,返回重绘后的 PNG bytes。
@@ -63,6 +63,7 @@ def _call_local_redraw(image_png_bytes, mask_png_bytes, timeout=300.0,
max_side:送 ComfyUI 前长边压到多少像素,None 用全局默认 _REDRAW_MAX_SIDE。
unet_name:非 None 时切换 Flux 模型,None 用工作流内置默认。
promptNone 用默认 _REDRAW_PROMPT,否则用传入的提示词。
"""
from .redraw import run_redraw
eff_side = _REDRAW_MAX_SIDE if max_side is None else max_side
@@ -84,7 +85,8 @@ def _call_local_redraw(image_png_bytes, mask_png_bytes, timeout=300.0,
orig_w, orig_h, nw, nh, eff_side)
# front=True:接口2 时延敏感,插到 ComfyUI 队列最前,避免排在接口3/5 的批量任务后面
out = run_redraw(image_png_bytes, mask_png_bytes, timeout=timeout,
prompt=_REDRAW_PROMPT, front=True, unet_name=unet_name)
prompt=prompt if prompt is not None else _REDRAW_PROMPT,
front=True, unet_name=unet_name)
if scale < 1.0 and out:
out = _upscale_png_to(out, orig_w, orig_h)
return out
+3 -3
View File
@@ -48,7 +48,7 @@ cd /home/ubuntu/hair/local_test
|--------|------|------|------|
| image | File | 是 | 人物图片(支持 jpg, png 等常见格式) |
| mask | File | 是 | 遮罩图片(支持 jpg, png,遮罩区域可用红色/白色/alpha 通道标识) |
| prompt | String | 否 | 提示词,默认值:"填充遮罩区域的头发,皮肤加一点磨皮" |
| prompt | String | 否 | 提示词,默认值:"填充遮罩区域的头发" |
#### 遮罩图片格式说明
@@ -70,7 +70,7 @@ cd /home/ubuntu/hair/local_test
curl -X POST http://127.0.0.1:8899/api/generate \
-F "image=@/path/to/person.jpg" \
-F "mask=@/path/to/mask.png" \
-F "prompt=填充遮罩区域的头发,皮肤加一点磨皮" \
-F "prompt=填充遮罩区域的头发" \
--output result.png
```
@@ -85,7 +85,7 @@ files = {
"mask": open("mask.png", "rb"),
}
data = {
"prompt": "填充遮罩区域的头发,皮肤加一点磨皮"
"prompt": "填充遮罩区域的头发"
}
resp = requests.post(url, files=files, data=data, timeout=600)
+1 -1
View File
@@ -206,7 +206,7 @@ def generate():
return jsonify({"error": msg}), 400
image_file = request.files["image"]
mask_file = request.files["mask"]
prompt_text = request.form.get("prompt", "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜")
prompt_text = request.form.get("prompt", "填充遮罩区域的头发")
log.info(
"收到请求: image=%s mask=%s prompt=%r",
image_file.filename, mask_file.filename, prompt_text,
+1 -1
View File
@@ -27,7 +27,7 @@ def prep_and_upload():
def run_once(fname, model, dtype, steps):
wf = A.build_workflow(fname, "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜")
wf = A.build_workflow(fname, "填充遮罩区域的头发")
wf["16"]["inputs"]["unet_name"] = model
wf["16"]["inputs"]["weight_dtype"] = dtype
wf["1"]["inputs"]["steps"] = steps
+1 -1
View File
@@ -33,7 +33,7 @@ def upload(scale=1.0):
def run(fname, steps):
wf = A.build_workflow(fname, "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜")
wf = A.build_workflow(fname, "填充遮罩区域的头发")
wf["16"]["inputs"]["unet_name"] = MODEL
wf["16"]["inputs"]["weight_dtype"] = DTYPE
wf["1"]["inputs"]["steps"] = steps
+1 -1
View File
@@ -30,7 +30,7 @@ SEED = 123456789
imgs = []
labels = []
for steps in [2, 3, 4, 6]:
wf = A.build_workflow(fname, "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜", seed=SEED)
wf = A.build_workflow(fname, "填充遮罩区域的头发", seed=SEED)
wf["16"]["inputs"]["unet_name"] = MODEL
wf["16"]["inputs"]["weight_dtype"] = DTYPE
wf["1"]["inputs"]["steps"] = steps
+1 -1
View File
@@ -55,7 +55,7 @@ button { padding: 10px 24px; border: none; border-radius: 6px; cursor: pointer;
</div>
<div class="controls" style="margin-top:16px">
<label>提示词:</label>
<input type="text" id="promptInput" value="填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜">
<input type="text" id="promptInput" value="填充遮罩区域的头发">
</div>
<div style="text-align:center; margin-top:16px">
<button class="btn-generate" id="generateBtn" disabled>🚀 生成</button>
+1 -1
View File
@@ -25,7 +25,7 @@ resp = requests.post(
"image": ("original.jpg", img_data, "image/jpeg"),
"mask": ("mask.png", mask_data, "image/png"),
},
data={"prompt": "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"},
data={"prompt": "填充遮罩区域的头发"},
timeout=600,
)
+126
View File
@@ -0,0 +1,126 @@
#!/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 = ['<th class="col-label">原图</th>']
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'<th class="col-label"><div class="col-title">{t}</div>'
f'<div class="col-stat">均{avg/1000:.1f}s</div></th>')
body_rows = []
for r in rows:
orig_src = ORIG_SRC.get(r["img"])
label = f'<div class="row-label">{r["img"]}<br><b>{r["hair_name"]}</b></div>'
# 原图列:显示输入原图
orig_cell = (f'<td class="cell-orig"><div class="row-label-cell">{label}</div>'
f'<img class="orig-img" src="{orig_src}"></td>')
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'<td class="cell-result"><img class="result-img" src="{src}" loading="lazy">'
f'<div class="cell-time">{t/1000:.1f}s</div></td>')
else:
cells.append(f'<td class="cell-result"><div class="na">⚠</div></td>')
body_rows.append(f'<tr>{"".join(cells)}</tr>')
html = f"""<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>重绘分辨率对比({title_suffix})</title>
<style>
* {{ box-sizing: border-box; margin: 0; padding: 0; }}
body {{ font-family: -apple-system, sans-serif; background: #f5f5f5; padding: 16px; }}
h1 {{ font-size: 20px; margin-bottom: 4px; }}
.subtitle {{ color: #888; font-size: 12px; margin-bottom: 12px; }}
.legend {{ background: #fff; border-radius: 8px; padding: 10px 16px; margin-bottom: 12px; font-size: 12px; color: #555; }}
.scroll-wrap {{ overflow-x: auto; }}
table {{ border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.06); }}
th, td {{ border: 1px solid #eee; padding: 6px; vertical-align: top; text-align: center; }}
th {{ background: #f9fafb; position: sticky; top: 0; }}
.col-label {{ min-width: 130px; max-width: 150px; }}
.col-title {{ font-size: 12px; font-weight: 700; color: #374151; }}
.col-stat {{ font-size: 10px; color: #9ca3af; margin-top: 2px; }}
.row-label {{ font-size: 11px; color: #6b7280; }}
.row-label b {{ color: #1f2937; }}
.row-label-cell {{ font-size: 11px; color: #6b7280; margin-bottom: 4px; }}
.row-label-cell b {{ color: #1f2937; font-size: 13px; }}
img {{ border-radius: 4px; max-width: 130px; max-height: 160px; object-fit: contain; background: #f3f4f6; }}
.orig-img {{ border: 2px solid #d1d5db; }}
.cell-time {{ font-size: 10px; color: #9ca3af; margin-top: 2px; }}
.na {{ color: #d1d5db; font-size: 12px; padding: 40px 10px; }}
</style>
</head>
<body>
<h1>📊 重绘分辨率对比提示词{title_suffix}</h1>
<p class="subtitle">4×5发型=20 · 每行原图+4分辨率 · steps=15 · 提示词="{prompt}" · 80/80成功 · 0 OOM</p>
<div class="legend">最左列为输入原图列标题下为平均总耗时横向滚动查看</div>
<div class="scroll-wrap">
<table>
<tr>{"".join(headers)}</tr>
{"".join(body_rows)}
</table>
</div>
</body>
</html>"""
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()
Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

+205
View File
@@ -0,0 +1,205 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>swap步数 + 重绘分辨率 对比报告</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, "Segoe UI", sans-serif; background: #f5f5f5; padding: 16px; color: #333; }
h1 { font-size: 20px; margin-bottom: 4px; }
h2 { font-size: 16px; margin: 20px 0 10px; }
.subtitle { color: #888; font-size: 12px; margin-bottom: 14px; }
.card { background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 16px; overflow: hidden; }
.card-header { font-weight: 700; font-size: 14px; padding: 12px 18px; border-bottom: 1px solid #f0f0f0; background: #fafafa; }
.card-body { padding: 18px; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.step-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.step-name { width: 100px; flex-shrink: 0; font-weight: 600; }
.step-bar-wrap { flex: 1; background: #f3f4f6; border-radius: 4px; height: 24px; min-width: 200px; }
.step-bar { height: 100%; border-radius: 4px; display: flex; align-items: center; padding-left: 8px; color: #fff; font-size: 11px; font-weight: 600; min-width: 2px; }
.step-time { width: 70px; text-align: right; font-weight: 600; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.c-swap { background: #f59e0b; } .c-comfy { background: #ef4444; } .c-total { background: #2563eb; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { border: 1px solid #eee; padding: 5px 8px; text-align: center; }
th { background: #f9fafb; font-weight: 600; position: sticky; top: 0; }
td img { max-height: 100px; max-width: 80px; border-radius: 4px; }
.scroll { max-height: 400px; overflow: auto; }
.note { background: #fef3c7; border-radius: 8px; padding: 10px 14px; font-size: 12px; color: #92400e; margin-top: 10px; }
</style>
</head>
<body>
<h1>📊 swap步数 + 重绘分辨率 对比报告</h1>
<p class="subtitle">4图(asdf/qwer/girl2/girl5) × 2发型(波浪/心形) · 热数据(预热后取第2次) · 48/48成功 · 峰值20.6GB · 0 OOM</p>
<div class="note">💡 结论速览: B维度 steps 10→20 swap从3.0s→3.9s(每步省~90ms)C维度 res 640比896省3s(comfy 4.3s vs 7.3s)1024与896接近。</div>
<h2>B维度:swap步数对比(分辨率固定896)</h2>
<div class="summary-grid">
<div class="card"><div class="card-header">swap 耗时(越低越快)</div><div class="card-body"><div class="step-row"><div class="step-name">steps=10</div><div class="step-bar-wrap"><div class="step-bar c-swap" style="width:76.94087403598971%">2993ms</div></div><div class="step-time">2993ms</div></div><div class="step-row"><div class="step-name">steps=15</div><div class="step-bar-wrap"><div class="step-bar c-swap" style="width:88.63753213367609%">3448ms</div></div><div class="step-time">3448ms</div></div><div class="step-row"><div class="step-name">steps=20</div><div class="step-bar-wrap"><div class="step-bar c-swap" style="width:100.0%">3890ms</div></div><div class="step-time">3890ms</div></div></div></div>
<div class="card"><div class="card-header">总耗时(越低越快)</div><div class="card-body"><div class="step-row"><div class="step-name">steps=10</div><div class="step-bar-wrap"><div class="step-bar c-total" style="width:90.79392624728851%">10464ms</div></div><div class="step-time">10464ms</div></div><div class="step-row"><div class="step-name">steps=15</div><div class="step-bar-wrap"><div class="step-bar c-total" style="width:96.13882863340564%">11080ms</div></div><div class="step-time">11080ms</div></div><div class="step-row"><div class="step-name">steps=20</div><div class="step-bar-wrap"><div class="step-bar c-total" style="width:100.0%">11525ms</div></div><div class="step-time">11525ms</div></div></div></div>
</div>
<h2>C维度:重绘分辨率对比(steps固定15)</h2>
<div class="summary-grid">
<div class="card"><div class="card-header">ComfyUI重绘 耗时(越低越快)</div><div class="card-body"><div class="step-row"><div class="step-name">res=640</div><div class="step-bar-wrap"><div class="step-bar c-comfy" style="width:57.23118279569892%">4258ms</div></div><div class="step-time">4258ms</div></div><div class="step-row"><div class="step-name">res=896</div><div class="step-bar-wrap"><div class="step-bar c-comfy" style="width:97.72849462365592%">7271ms</div></div><div class="step-time">7271ms</div></div><div class="step-row"><div class="step-name">res=1024</div><div class="step-bar-wrap"><div class="step-bar c-comfy" style="width:100.0%">7440ms</div></div><div class="step-time">7440ms</div></div></div></div>
<div class="card"><div class="card-header">总耗时(越低越快)</div><div class="card-body"><div class="step-row"><div class="step-name">res=640</div><div class="step-bar-wrap"><div class="step-bar c-total" style="width:68.26090758065926%">7807ms</div></div><div class="step-time">7807ms</div></div><div class="step-row"><div class="step-name">res=896</div><div class="step-bar-wrap"><div class="step-bar c-total" style="width:96.72116813849786%">11062ms</div></div><div class="step-time">11062ms</div></div><div class="step-row"><div class="step-name">res=1024</div><div class="step-bar-wrap"><div class="step-bar c-total" style="width:100.0%">11437ms</div></div><div class="step-time">11437ms</div></div></div></div>
</div>
<h2>B维度明细(每图每发型每步数)</h2>
<div class="card"><div class="scroll"><table>
<tr><th>图片</th><th>发型</th><th>steps</th><th>swap(ms)</th><th>comfy(ms)</th><th>总(ms)</th><th>结果</th></tr>
<tr>
<td>asdf</td><td>心形</td><td>10</td>
<td>2969</td><td>6810</td><td>10189</td>
<td><img src="bench2/B_steps10_asdf_heart.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>心形</td><td>15</td>
<td>3621</td><td>6628</td><td>10619</td>
<td><img src="bench2/B_steps15_asdf_heart.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>心形</td><td>20</td>
<td>3855</td><td>6874</td><td>11106</td>
<td><img src="bench2/B_steps20_asdf_heart.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>波浪</td><td>10</td>
<td>3053</td><td>6601</td><td>10073</td>
<td><img src="bench2/B_steps10_asdf_wave.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>波浪</td><td>15</td>
<td>3403</td><td>6596</td><td>10380</td>
<td><img src="bench2/B_steps15_asdf_wave.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>波浪</td><td>20</td>
<td>3842</td><td>6579</td><td>10815</td>
<td><img src="bench2/B_steps20_asdf_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>心形</td><td>10</td>
<td>3282</td><td>8860</td><td>12601</td>
<td><img src="bench2/B_steps10_girl2_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>心形</td><td>15</td>
<td>3470</td><td>8578</td><td>12439</td>
<td><img src="bench2/B_steps15_girl2_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>心形</td><td>20</td>
<td>4022</td><td>8650</td><td>13057</td>
<td><img src="bench2/B_steps20_girl2_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>波浪</td><td>10</td>
<td>3062</td><td>8561</td><td>12066</td>
<td><img src="bench2/B_steps10_girl2_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>波浪</td><td>15</td>
<td>3542</td><td>8809</td><td>12769</td>
<td><img src="bench2/B_steps15_girl2_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>波浪</td><td>20</td>
<td>3923</td><td>8809</td><td>13167</td>
<td><img src="bench2/B_steps20_girl2_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>心形</td><td>10</td>
<td>2834</td><td>5888</td><td>9042</td>
<td><img src="bench2/B_steps10_girl5_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>心形</td><td>15</td>
<td>3366</td><td>6774</td><td>10478</td>
<td><img src="bench2/B_steps15_girl5_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>心形</td><td>20</td>
<td>3953</td><td>6580</td><td>10866</td>
<td><img src="bench2/B_steps20_girl5_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>波浪</td><td>10</td>
<td>2870</td><td>5837</td><td>9046</td>
<td><img src="bench2/B_steps10_girl5_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>波浪</td><td>15</td>
<td>3302</td><td>6450</td><td>10079</td>
<td><img src="bench2/B_steps15_girl5_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>波浪</td><td>20</td>
<td>3758</td><td>6465</td><td>10567</td>
<td><img src="bench2/B_steps20_girl5_wave.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>心形</td><td>10</td>
<td>2935</td><td>7067</td><td>10388</td>
<td><img src="bench2/B_steps10_qwer_heart.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>心形</td><td>15</td>
<td>3516</td><td>7072</td><td>10985</td>
<td><img src="bench2/B_steps15_qwer_heart.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>心形</td><td>20</td>
<td>3849</td><td>7035</td><td>11243</td>
<td><img src="bench2/B_steps20_qwer_heart.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>波浪</td><td>10</td>
<td>2945</td><td>6996</td><td>10314</td>
<td><img src="bench2/B_steps10_qwer_wave.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>波浪</td><td>15</td>
<td>3369</td><td>7070</td><td>10894</td>
<td><img src="bench2/B_steps15_qwer_wave.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>波浪</td><td>20</td>
<td>3924</td><td>7103</td><td>11382</td>
<td><img src="bench2/B_steps20_qwer_wave.jpg" loading="lazy"></td></tr>
</table></div></div>
<h2>C维度明细(每图每发型每分辨率)</h2>
<div class="card"><div class="scroll"><table>
<tr><th>图片</th><th>发型</th><th>res</th><th>swap(ms)</th><th>comfy(ms)</th><th>总(ms)</th><th>结果</th></tr>
<tr>
<td>asdf</td><td>心形</td><td>640</td>
<td>3214</td><td>4261</td><td>7750</td>
<td><img src="bench2/C_res640_asdf_heart.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>心形</td><td>896</td>
<td>3508</td><td>6882</td><td>10784</td>
<td><img src="bench2/C_res896_asdf_heart.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>心形</td><td>1024</td>
<td>3527</td><td>7010</td><td>10999</td>
<td><img src="bench2/C_res1024_asdf_heart.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>波浪</td><td>640</td>
<td>3355</td><td>3660</td><td>7328</td>
<td><img src="bench2/C_res640_asdf_wave.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>波浪</td><td>896</td>
<td>3436</td><td>6900</td><td>10730</td>
<td><img src="bench2/C_res896_asdf_wave.jpg" loading="lazy"></td></tr><tr>
<td>asdf</td><td>波浪</td><td>1024</td>
<td>3593</td><td>6795</td><td>10847</td>
<td><img src="bench2/C_res1024_asdf_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>心形</td><td>640</td>
<td>3307</td><td>4437</td><td>8036</td>
<td><img src="bench2/C_res640_girl2_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>心形</td><td>896</td>
<td>3582</td><td>8503</td><td>12458</td>
<td><img src="bench2/C_res896_girl2_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>心形</td><td>1024</td>
<td>3816</td><td>9018</td><td>13330</td>
<td><img src="bench2/C_res1024_girl2_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>波浪</td><td>640</td>
<td>3244</td><td>4423</td><td>7946</td>
<td><img src="bench2/C_res640_girl2_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>波浪</td><td>896</td>
<td>3409</td><td>8775</td><td>12558</td>
<td><img src="bench2/C_res896_girl2_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl2</td><td>波浪</td><td>1024</td>
<td>3737</td><td>8979</td><td>13203</td>
<td><img src="bench2/C_res1024_girl2_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>心形</td><td>640</td>
<td>3338</td><td>4985</td><td>8565</td>
<td><img src="bench2/C_res640_girl5_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>心形</td><td>896</td>
<td>3345</td><td>6714</td><td>10403</td>
<td><img src="bench2/C_res896_girl5_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>心形</td><td>1024</td>
<td>3372</td><td>6550</td><td>10264</td>
<td><img src="bench2/C_res1024_girl5_heart.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>波浪</td><td>640</td>
<td>3186</td><td>4381</td><td>7811</td>
<td><img src="bench2/C_res640_girl5_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>波浪</td><td>896</td>
<td>3290</td><td>6447</td><td>10066</td>
<td><img src="bench2/C_res896_girl5_wave.jpg" loading="lazy"></td></tr><tr>
<td>girl5</td><td>波浪</td><td>1024</td>
<td>3256</td><td>6760</td><td>10369</td>
<td><img src="bench2/C_res1024_girl5_wave.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>心形</td><td>640</td>
<td>3289</td><td>4093</td><td>7676</td>
<td><img src="bench2/C_res640_qwer_heart.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>心形</td><td>896</td>
<td>3432</td><td>6912</td><td>10720</td>
<td><img src="bench2/C_res896_qwer_heart.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>心形</td><td>1024</td>
<td>3557</td><td>7164</td><td>11184</td>
<td><img src="bench2/C_res1024_qwer_heart.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>波浪</td><td>640</td>
<td>3240</td><td>3827</td><td>7350</td>
<td><img src="bench2/C_res640_qwer_wave.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>波浪</td><td>896</td>
<td>3368</td><td>7041</td><td>10778</td>
<td><img src="bench2/C_res896_qwer_wave.jpg" loading="lazy"></td></tr><tr>
<td>qwer</td><td>波浪</td><td>1024</td>
<td>3599</td><td>7249</td><td>11303</td>
<td><img src="bench2/C_res1024_qwer_wave.jpg" loading="lazy"></td></tr>
</table></div></div>
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Some files were not shown because too many files have changed in this diff Show More