teawhite's picture
Add files using upload-large-folder tool
51ac7cc verified
Raw History Blame Contribute Delete
4.74 kB
#!/usr/bin/env python3
"""genbench3 · 组合变体与任务清单(maliang venv / 任意 python3 + numpy + PIL)。
combo:每个源 2 个 —— 画风 A(线稿 / 绘画类里门槛分最高的)+ 换玩家、画风 B(其余类里最高的)+ 换 Boss;外观按源轮转,
只用该源单独换外观时通过了门槛的 look。写 outputs/genbench3/combo_plan.json(make_f0.py --combo 的输入)。
both :每个源 1 个 —— orig 上换玩家 + 换 Boss(两张已通过的 char 候选直接合成:两者只在各自角色附近改像素,重叠处取改得
多的那张),写 cands/<tag>/both_<p>+<b>.png。
jobs :orig + gate.json 里通过的 style / char / combo + both → outputs/genbench3/jobs.json。
usage: plan.py combo | both | jobs"""
import json
import re
import sys
import numpy as np
from PIL import Image
G = "/opt/dlami/nvme/zhiyangdeng/maliang/outputs/genbench3"
FAM_A = ("blueprint", "chalkboard", "porcelain", "papyrus", "ukiyoe")
PLAYER_LOOKS = ("silverknight", "ninja", "ranger", "firemage")
BOSS_LOOKS = ("skeletonking", "icetroll", "demonlord", "stonegolem")
def gate():
g = json.load(open(f"{G}/gate.json"))
rows = {(r["tag"], r["name"]): r for r in g["rows"]}
picks = {}
for k, n in g["picks"].items():
tag, slot = k.split("/")
picks.setdefault(tag, {})[slot] = rows[(tag, n)]
return picks
def score(r):
return r["vlm"].get("layout", 0) + r["coarse_p"]
def looks_ok(p, role, order, k):
ok = [lk for lk in order if f"char_{role}_{lk}" in p]
return ok[k % len(ok)] if ok else None, ok
def combo():
picks, plan = gate(), {}
for i, tag in enumerate(sorted(picks)):
p = picks[tag]
styles = sorted([r for s, r in p.items() if s.startswith("style_")], key=score, reverse=True)
a = [r for r in styles if r["style"] in FAM_A]
b = [r for r in styles if r["style"] not in FAM_A]
pl, _ = looks_ok(p, "player", PLAYER_LOOKS, i)
bl, _ = looks_ok(p, "boss", BOSS_LOOKS, i)
plan[tag] = []
if a and pl:
plan[tag].append({"base": a[0]["name"], "style": a[0]["style"], "role": "player", "look": pl})
if b and bl:
plan[tag].append({"base": b[0]["name"], "style": b[0]["style"], "role": "boss", "look": bl})
json.dump(plan, open(f"{G}/combo_plan.json", "w"), indent=1)
print(json.dumps(plan, indent=1))
def both():
picks = gate()
for i, tag in enumerate(sorted(picks)):
p = picks[tag]
pl, _ = looks_ok(p, "player", PLAYER_LOOKS, i + 1) # 与 combo 错开一个外观
bl, _ = looks_ok(p, "boss", BOSS_LOOKS, i + 1)
if not (pl and bl):
print(tag, "跳过(没有通过的 player / boss 外观)")
continue
src = np.asarray(Image.open(f"{G}/sources/{tag}/f0.png").convert("RGB")).astype(np.int16)
ep = np.asarray(Image.open(f"{G}/cands/{tag}/{p[f'char_player_{pl}']['name']}.png").convert("RGB")).astype(np.int16)
eb = np.asarray(Image.open(f"{G}/cands/{tag}/{p[f'char_boss_{bl}']['name']}.png").convert("RGB")).astype(np.int16)
dp, db = ep - src, eb - src
use_p = np.abs(dp).sum(-1, keepdims=True) >= np.abs(db).sum(-1, keepdims=True)
out = (src + np.where(use_p, dp, db)).clip(0, 255).astype(np.uint8)
name = f"both_{pl}+{bl}"
Image.fromarray(out).save(f"{G}/cands/{tag}/{name}.png")
json.dump({"tag": tag, "kind": "both", "name": name, "player": p[f"char_player_{pl}"]["name"],
"boss": p[f"char_boss_{bl}"]["name"], "look": f"{pl}+{bl}"},
open(f"{G}/cands/{tag}/{name}.both.json", "w"), indent=1)
print(tag, name)
def jobs():
picks, out = gate(), []
for tag in sorted(picks):
out.append({"tag": tag, "variant": "orig", "kind": "orig", "f0": f"{G}/sources/{tag}/f0.png"})
for slot, r in sorted(picks[tag].items()):
out.append({"tag": tag, "variant": slot, "kind": r["kind"], "style": r["style"], "role": r["role"],
"look": r["look"], "seed": r["seed"], "f0": f"{G}/cands/{tag}/{r['name']}.png"})
import glob
for f in sorted(glob.glob(f"{G}/cands/{tag}/both_*.both.json")):
b = json.load(open(f))
out.append({"tag": tag, "variant": b["name"], "kind": "both", "style": None, "role": "both", "look": b["look"],
"f0": f"{G}/cands/{tag}/{b['name']}.png"})
json.dump(out, open(f"{G}/jobs.json", "w"), indent=1)
from collections import Counter
print(len(out), Counter(j["kind"] for j in out))
if __name__ == "__main__":
{"combo": combo, "both": both, "jobs": jobs}[sys.argv[1]]()