rapid-anima / scripts /infer_test.py
darask0's picture
Initial commit: rapid-anima distillation codebase
77cc641 verified
Raw
History Blame Contribute Delete
3.32 kB
#!/usr/bin/env python3
"""
Phase 1 検証用: 学習済み LoRA を Anima にロードして、
意図的に「品質タグなしの短いプロンプト」で画像を生成する。
これらが既に良質に出れば、Phase 1 が成功している証拠。
使い方:
python infer_test.py --lora /output/phase1/.../adapter_model.safetensors \
--prompts ./eval_prompts.txt --out /output/phase1_samples
"""
import argparse
import sys
from pathlib import Path
# Anima を diffusers 経由で動かす場合のスケルトン。
# Anima は ComfyUI ネイティブなので、本格運用は ComfyUI API か diffusion-pipe の
# サンプリングコードを使うのが正確。ここでは簡易検証用。
DEFAULT_PROMPTS = [
"1girl, long hair, school uniform, standing in a classroom",
"a black cat sitting on a windowsill at sunset",
"1boy, samurai, holding katana, snowy forest",
"fantasy landscape with floating islands and a waterfall",
"1girl, twintails, smile, holding ice cream, summer",
]
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--lora", required=True, type=Path)
ap.add_argument("--prompts", type=Path, default=None)
ap.add_argument("--out", required=True, type=Path)
ap.add_argument("--steps", type=int, default=30)
ap.add_argument("--cfg", type=float, default=4.5)
ap.add_argument("--seed", type=int, default=42)
args = ap.parse_args()
args.out.mkdir(parents=True, exist_ok=True)
if args.prompts and args.prompts.exists():
prompts = [
line.strip()
for line in args.prompts.read_text(encoding="utf-8").splitlines()
if line.strip()
]
else:
prompts = DEFAULT_PROMPTS
# 推論実装はモデル更新が早いため、ここでは diffusion-pipe 同梱の
# サンプリングユーティリティを subprocess で呼ぶ前提のプレースホルダにしておく。
# 実運用では下の方法のどれかに置き換える:
# (A) ComfyUI を Modal の別 function で立てて API 経由で生成
# (B) diffusion-pipe の sample.py 相当を直接呼ぶ
# (C) diffusers の AnimaPipeline がリリースされ次第そちらに移行
print("=" * 60)
print("Phase 1 検証プロンプト (品質タグ意図的に省略):")
print("=" * 60)
for i, p in enumerate(prompts):
print(f" [{i:02d}] {p}")
print("\n[infer_test] このスクリプトはサンプル一覧と LoRA パスを表示するスケルトンです。")
print(f"[infer_test] LoRA: {args.lora}")
print(f"[infer_test] Output dir: {args.out}")
print(
"\n[infer_test] 実生成は次のいずれかで実行してください:\n"
" 1) ComfyUI ワークフローに anima-preview3-base + この LoRA を読み込み\n"
" (公式リポジトリ同梱の example.png ワークフローから派生させる)\n"
" 2) diffusion-pipe の最新サンプリングコード\n"
" 3) diffusers の Anima 対応版 (リリース次第)\n"
)
# 生成プロンプト一覧をファイルに残しておく
(args.out / "eval_prompts_used.txt").write_text(
"\n".join(prompts), encoding="utf-8"
)
if __name__ == "__main__":
sys.exit(main())