🚀 SDXL-controlnet: Canny
SDXL-controlnet: Canny是基于Canny条件,在stabilityai/stable-diffusion-xl-base-1.0上训练得到的ControlNet权重。以下是一些示例图片:
示例图片
提示词 |
图片 |
a couple watching a romantic sunset, 4k photo |
 |
ultrarealistic shot of a furry blue bird |
 |
a woman, close up, detailed, beautiful, street photography, photorealistic, detailed, Kodak ektar 100, natural, candid shot |
 |
Cinematic, neoclassical table in the living room, cinematic, contour, lighting, highly detailed, winter, golden hour |
 |
a tornado hitting grass field, 1980's film grain. overcast, muted colors. |
 |
🚀 快速开始
安装依赖库
首先,你需要安装以下库:
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",
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
的官方文档。
🔧 技术细节
训练脚本
我们的训练脚本基于此处提供的官方训练脚本构建。
训练数据
该检查点首先在调整为最大最小尺寸为384的laion 6a数据集上训练20,000步,然后在调整为最大最小尺寸为1024并过滤为仅包含最小尺寸为1024的图像的laion 6a数据集上再训练20,000步。我们发现进一步的高分辨率微调对于图像质量是必要的。
计算资源
使用一台配备8张A100显卡的机器。
批量大小
采用数据并行,单GPU批量大小为8,总批量大小为64。
超参数
恒定学习率为1e-4,按批量大小缩放后总学习率为64e-4。
混合精度
采用fp16。
📄 许可证
本项目采用OpenRail++许可证。
信息表格
属性 |
详情 |
模型类型 |
SDXL-controlnet: Canny |
基础模型 |
runwayml/stable-diffusion-v1-5 |
训练数据 |
先在调整为最大最小尺寸为384的laion 6a数据集上训练20,000步,再在调整为最大最小尺寸为1024并过滤为仅包含最小尺寸为1024的图像的laion 6a数据集上训练20,000步 |
计算资源 |
一台配备8张A100显卡的机器 |
批量大小 |
单GPU批量大小为8,总批量大小为64 |
超参数 |
恒定学习率为1e-4,按批量大小缩放后总学习率为64e-4 |
混合精度 |
fp16 |
许可证 |
OpenRail++ |