67 lines
3.2 KiB
Python
67 lines
3.2 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
# 2026-10-02 PD 지시(자율 반복) — "완성 된 이미지를 모아 학습을 거듭해 … 체계를 구축". 합격본을 학습 데이터셋 목록(dataset.json)에 쌓는다.
|
||
|
|
# python icon_dataset.py add <고른 목록 json> <그림 폴더> <출처: pd|auto> 고른 그림을 목록에 더한다(같은 파일은 한 번만)
|
||
|
|
# python icon_dataset.py list 목록 요약
|
||
|
|
# 고른 목록 json: {"<이름>": "<파일 이름>", …}. 파일 이름 규칙 <round>_<대상>_s<강도>_<순번>.png 에서 대상을 읽어 묘사(캡션)를 찾는다.
|
||
|
|
# 그림은 moba_anfg/dataset/ 로 사본을 모은다(1024 투명 · 여백 통일 = icon_finalize.finalize).
|
||
|
|
import io, json, os, re, sys
|
||
|
|
import comfy_moba_anfg as gen
|
||
|
|
from icon_finalize import finalize
|
||
|
|
|
||
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
|
|
ROOT = os.path.join(HERE, "moba_anfg")
|
||
|
|
DS_DIR = os.path.join(ROOT, "dataset")
|
||
|
|
DS_JSON = os.path.join(ROOT, "dataset.json")
|
||
|
|
|
||
|
|
|
||
|
|
def table_for(tag):
|
||
|
|
"""회차 이름 → 그 회차가 쓴 대상 표. 같은 이름(ring 등)이라도 회차마다 묘사가 다르므로 회차로 표를 고른다.
|
||
|
|
(2026-10-02 수정: 처음에는 표를 합쳐 찾아 a2 그림에 a1 묘사가 붙었다 — v1 학습은 그 잘못된 캡션으로 돌았다.)"""
|
||
|
|
if tag in ("a1", "a4"):
|
||
|
|
table = gen.SUBJECTS
|
||
|
|
elif tag in ("a2", "a5n", "a5v"):
|
||
|
|
table = gen.SUBJECTS_FR
|
||
|
|
elif tag == "a3":
|
||
|
|
table = gen.SUBJECTS_SHAPE
|
||
|
|
else:
|
||
|
|
table = gen.SUBJECTS_ALL
|
||
|
|
return dict((x[0], x[1]) for x in table)
|
||
|
|
|
||
|
|
|
||
|
|
def load():
|
||
|
|
return json.load(io.open(DS_JSON, encoding="utf-8")) if os.path.exists(DS_JSON) else []
|
||
|
|
|
||
|
|
|
||
|
|
def add(picks_path, folder, source):
|
||
|
|
picks = json.load(io.open(picks_path, encoding="utf-8"))
|
||
|
|
data = load()
|
||
|
|
have = set(e["src"] for e in data)
|
||
|
|
os.makedirs(DS_DIR, exist_ok=True)
|
||
|
|
n = 0
|
||
|
|
for name, fn in sorted(picks.items()):
|
||
|
|
if fn in have:
|
||
|
|
continue
|
||
|
|
m = re.match(r"^([a-z0-9]+)_(.+)_s\d+_\d+\.png$", fn)
|
||
|
|
if not m:
|
||
|
|
print("이름 규칙이 아니라 건너뜀:", fn); continue
|
||
|
|
tag, subject = m.group(1), m.group(2)
|
||
|
|
# 생성 때 남긴 곁파일(<그림>.txt)이 있으면 그 묘사를 쓴다. 없으면(예전 회차) 회차의 대상 표에서 찾는다.
|
||
|
|
side = os.path.join(folder, fn[:-4] + ".txt")
|
||
|
|
caption = io.open(side, encoding="utf-8").read().strip() if os.path.exists(side) else table_for(tag).get(subject)
|
||
|
|
if not caption:
|
||
|
|
print("묘사를 못 찾아 건너뜀:", fn); continue
|
||
|
|
out_name = "%s_%s.png" % (tag, fn[len(tag) + 1:-4])
|
||
|
|
finalize(os.path.join(folder, fn)).save(os.path.join(DS_DIR, out_name))
|
||
|
|
data.append({"file": out_name, "src": fn, "caption": caption, "source": source})
|
||
|
|
n += 1
|
||
|
|
json.dump(data, io.open(DS_JSON, "w", encoding="utf-8"), ensure_ascii=False, indent=1)
|
||
|
|
print("추가 %d · 전체 %d (pd %d)" % (n, len(data), sum(1 for e in data if e["source"] == "pd")))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
if sys.argv[1] == "add":
|
||
|
|
add(sys.argv[2], sys.argv[3], sys.argv[4])
|
||
|
|
else:
|
||
|
|
data = load()
|
||
|
|
print("전체 %d · pd %d" % (len(data), sum(1 for e in data if e["source"] == "pd")))
|