🚀 Pixel Art XL
Pixel Art XL 是一款基於 Stable Diffusion XL 的 LoRA 模型,專注於生成像素風圖像。它能夠將文本描述轉化為精美的像素藝術作品,為用戶帶來獨特的圖像生成體驗。
🚀 快速開始
環境準備
使用該模型前,你需要安裝必要的庫,以下是示例代碼:
from diffusers import DiffusionPipeline, LCMScheduler
import torch
模型加載
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
lcm_lora_id = "latent-consistency/lcm-lora-sdxl"
pipe = DiffusionPipeline.from_pretrained(model_id, variant="fp16")
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.load_lora_weights(lcm_lora_id, adapter_name="lora")
pipe.load_lora_weights("./pixel-art-xl.safetensors", adapter_name="pixel")
pipe.set_adapters(["lora", "pixel"], adapter_weights=[1.0, 1.2])
pipe.to(device="cuda", dtype=torch.float16)
圖像生成
prompt = "pixel, a cute corgi"
negative_prompt = "3d render, realistic"
num_images = 9
for i in range(num_images):
img = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
num_inference_steps=8,
guidance_scale=1.5,
).images[0]
img.save(f"lcm_lora_{i}.png")
✨ 主要特性
- 像素完美:通過將圖像下采樣 8 次(使用最近鄰插值法),可以獲得像素完美的圖像。
- 減少偽影:使用固定的 VAE(如 0.9 或 fp16 修復)可以避免生成圖像出現偽影。
- 高性能:搭配 LCM LoRA 使用,僅需 8 步推理和 1.5 的引導比例,即可快速生成高質量圖像。
- 靈活性高:無需使用 refiner,僅使用 1 個文本編碼器即可工作,無需風格提示和觸發關鍵詞。
💻 使用示例
基礎用法
from diffusers import DiffusionPipeline, LCMScheduler
import torch
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
lcm_lora_id = "latent-consistency/lcm-lora-sdxl"
pipe = DiffusionPipeline.from_pretrained(model_id, variant="fp16")
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.load_lora_weights(lcm_lora_id, adapter_name="lora")
pipe.load_lora_weights("./pixel-art-xl.safetensors", adapter_name="pixel")
pipe.set_adapters(["lora", "pixel"], adapter_weights=[1.0, 1.2])
pipe.to(device="cuda", dtype=torch.float16)
prompt = "pixel, a cute corgi"
negative_prompt = "3d render, realistic"
num_images = 9
for i in range(num_images):
img = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
num_inference_steps=8,
guidance_scale=1.5,
).images[0]
img.save(f"lcm_lora_{i}.png")
高級用法
如果你需要更高的性能,可以使用 LCM LoRA 並調整參數:
from diffusers import DiffusionPipeline, LCMScheduler
import torch
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
lcm_lora_id = "latent-consistency/lcm-lora-sdxl"
pipe = DiffusionPipeline.from_pretrained(model_id, variant="fp16")
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.load_lora_weights(lcm_lora_id, adapter_name="lora")
pipe.load_lora_weights("./pixel-art-xl.safetensors", adapter_name="pixel")
pipe.set_adapters(["lora", "pixel"], adapter_weights=[1.0, 1.2])
pipe.to(device="cuda", dtype=torch.float16)
prompt = "pixel, a cute corgi"
negative_prompt = "3d render, realistic"
num_inference_steps = 8
guidance_scale = 1.5
num_images = 9
for i in range(num_images):
img = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
num_inference_steps=num_inference_steps,
guidance_scale=guidance_scale,
).images[0]
img.save(f"lcm_lora_{i}.png")
📚 詳細文檔
注意事項
⚠️ 重要提示
- 不要使用 refiner。
- 僅使用 1 個文本編碼器即可。
- 無需風格提示和觸發關鍵詞。
- 該模型適用於等軸測和非等軸測風格。
- 支持 0.9 和 1.0 版本。
性能優化
💡 使用建議
- 搭配 LCM LoRA 使用,可提高性能。
- 使用 8 步推理和 1.5 的引導比例。
- Pixel Art XL 的 LoRA 強度設置為 1.2 效果更佳。
模型信息
屬性 |
詳情 |
模型類型 |
LoRA(基於 Stable Diffusion XL) |
訓練數據 |
未提及 |
📄 許可證
本項目採用 CreativeML OpenRAIL-M 許可證。