驗證Stable Diffusion模型效果 (推理 Inference) Zen Maru Gothic 字型

載入訓練好的 LoRA/ControlNet 模型

from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
import torch

# 載入 ControlNet 模型
controlnet = ControlNetModel.from_pretrained("你的模型路徑", torch_dtype=torch.float16).to("cuda")

# 建立推理管道
pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16
).to("cuda")

# 設定 prompt
prompt = "Zen Maru Gothic style text"

# 讀取一張測試圖片,轉成 Canny 邊緣
from controlnet_aux import CannyDetector
canny_detector = CannyDetector()
image = canny_detector("你的測試圖片路徑")

# 生成圖片
image = pipe(prompt, image=image).images[0]
image.show()

微調 Model (Fine-tune / LoRA 進一步訓練)

如果測試結果 還不夠理想,你可以進一步做 LoRA 微調

  • 增加更多訓練資料(如果 Loss 還沒收斂)
  • 調整 ControlNet 權重controlnet_conditioning_scale
  • 改進 Canny 邊緣檢測(嘗試不同的 low_threshold / high_threshold

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *