🚀 Small SDXL - controlnet: Canny
Small SDXL - controlnet: Canny 是基於 stabilityai/stable - diffusion - xl - base - 1.0 訓練的控制網絡權重,採用 Canny 條件。此檢查點比原始的 XL 控制網絡檢查點小 7 倍。下面為你展示一些示例圖片。
🚀 快速開始
安裝依賴
確保首先安裝所需的庫:
pip install accelerate transformers safetensors opencv-python diffusers
運行示例代碼
安裝完成後,就可以運行以下代碼:
from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
from diffusers.utils import load_image
from PIL import Image
import torch
import numpy as np
import cv2
prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting"
negative_prompt = "low quality, bad quality, sketches"
image = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png")
controlnet_conditioning_scale = 0.5
controlnet = ControlNetModel.from_pretrained(
"diffusers/controlnet-canny-sdxl-1.0-small",
torch_dtype=torch.float16
)
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
controlnet=controlnet,
vae=vae,
torch_dtype=torch.float16,
)
pipe.enable_model_cpu_offload()
image = np.array(image)
image = cv2.Canny(image, 100, 200)
image = image[:, :, None]
image = np.concatenate([image, image, image], axis=2)
image = Image.fromarray(image)
images = pipe(
prompt, negative_prompt=negative_prompt, image=image, controlnet_conditioning_scale=controlnet_conditioning_scale,
).images
images[0].save(f"hug_lab.png")

更多詳細信息,請查看 StableDiffusionXLControlNetPipeline
的官方文檔。
✨ 主要特性
- 體積小巧:此檢查點比原始的 XL 控制網絡檢查點小 7 倍。
- 實驗性:該檢查點處於實驗階段,有很大的改進空間,歡迎社區在此基礎上進行優化並提供反饋。
💻 使用示例
基礎用法
from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
from diffusers.utils import load_image
from PIL import Image
import torch
import numpy as np
import cv2
prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting"
negative_prompt = "low quality, bad quality, sketches"
image = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png")
controlnet_conditioning_scale = 0.5
controlnet = ControlNetModel.from_pretrained(
"diffusers/controlnet-canny-sdxl-1.0-small",
torch_dtype=torch.float16
)
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
controlnet=controlnet,
vae=vae,
torch_dtype=torch.float16,
)
pipe.enable_model_cpu_offload()
image = np.array(image)
image = cv2.Canny(image, 100, 200)
image = image[:, :, None]
image = np.concatenate([image, image, image], axis=2)
image = Image.fromarray(image)
images = pipe(
prompt, negative_prompt=negative_prompt, image=image, controlnet_conditioning_scale=controlnet_conditioning_scale,
).images
images[0].save(f"hug_lab.png")
高級用法
目前文檔未提及高級用法相關代碼,可參考官方文檔進行更多探索。
🔧 技術細節
訓練腳本
訓練腳本基於官方提供的腳本構建,可參考 此處。完整披露可參考 此腳本。
訓練特點
- 未進行蒸餾:此檢查點未執行蒸餾操作,僅使用從 SDXL UNet 初始化的較小 ControlNet。鼓勵社區嘗試進行蒸餾操作,可參考 此資源。
- ControlNet 初始化:關於 ControlNet 的初始化方式,可參考 此代碼塊。
- 無注意力塊:該模型沒有任何注意力塊。
- 性能表現:模型在大多數條件圖像上表現良好,但對於更復雜的條件,較大的檢查點可能效果更好。目前正在努力改進此檢查點的質量,並期待社區提供反饋。
- 參數建議:建議嘗試調整
controlnet_conditioning_scale
和 guidance_scale
參數,以獲得更好的圖像生成質量。
訓練數據
模型在 LAION aesthetic 6 加子集的 300 萬張圖像上進行訓練,批次大小為 256,訓練 50000 步,學習率恆定為 3e - 5。
計算資源
使用一臺配備 8 個 A100 GPU 的機器進行訓練。
混合精度
採用 FP16 混合精度。
📄 許可證
本項目採用 OpenRAIL++ 許可證。
屬性 |
詳情 |
模型類型 |
Small SDXL - controlnet: Canny |
訓練數據 |
LAION aesthetic 6 加子集的 300 萬張圖像 |
⚠️ 重要提示
此檢查點處於實驗階段,有很大的改進空間,鼓勵社區在此基礎上進行構建、改進並提供反饋。
💡 使用建議
建議嘗試調整 controlnet_conditioning_scale
和 guidance_scale
參數,以獲得更好的圖像生成質量。
示例圖片
示例 1
prompt: aerial view, a futuristic research complex in a bright foggy jungle, hard lighting

示例 2
prompt: a woman, close up, detailed, beautiful, street photography, photorealistic, detailed, Kodak ektar 100, natural, candid shot

示例 3
prompt: megatron in an apocalyptic world ground, runied city in the background, photorealistic

示例 4
prompt: a couple watching sunset, 4k photo
