1import torch
2from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
3from diffusers.utils import load_image
4import cv2, numpy as np
5from PIL import Image
6
7# 1. 載入 SD 1.5 + ControlNet (Canny)
8controlnet = ControlNetModel.from_pretrained(
9 "lllyasviel/control_v11p_sd15_canny", torch_dtype=torch.float16
10)
11pipe = StableDiffusionControlNetPipeline.from_pretrained(
12 "stable-diffusion-v1-5/stable-diffusion-v1-5",
13 controlnet=controlnet, torch_dtype=torch.float16,
14).to("cuda")
15
16# 2. 載入本 LoRA(皮卡丘外觀就在這裡)
17pipe.load_lora_weights("MrbandiTw/always-pikachu-lora-sd15", weight_name="pikachu_lora_v1.safetensors")
18
19# 3. 用宿主圖做 Canny 條件
20src = load_image("charmander.png").convert("RGB").resize((512, 512))
21edges = cv2.Canny(np.array(src), 80, 160)
22canny = Image.fromarray(np.stack([edges] * 3, axis=-1))
23
24# 4. 生成
25image = pipe(
26 prompt="pikachu, yellow body, red cheeks, cute face",
27 negative_prompt="dark head, black head, glass sphere, bubble, reflective orb, "
28 "glossy, transparent dome, helmet, lowres, deformed",
29 image=canny,
30 num_inference_steps=25,
31 guidance_scale=7.5,
32 controlnet_conditioning_scale=0.72,
33 cross_attention_kwargs={"scale": 0.64}, # LoRA 強度
34).images[0]
35image.save("pikachu.png")
LoRA 權重以
CreativeML OpenRAIL-M 釋出。
寶可夢與皮卡丘為 Nintendo / Game Freak / The Pokémon Company 之商標,本模型僅供
研究與教育用途。