🚀 Controlnet - 深度版本
ControlNet是一种神经网络结构,通过添加额外条件来控制扩散模型。此检查点对应于基于深度估计的ControlNet,可与Stable Diffusion结合使用。

✨ 主要特性
- 能够为预训练的大型扩散模型添加额外输入条件,支持如边缘图、分割图、关键点等多种条件输入。
- 以端到端的方式学习特定任务条件,即使训练数据集较小(< 50k),学习过程也很稳健。
- 训练速度与微调扩散模型相当,可在个人设备上进行训练,也能在强大的计算集群上处理大量数据。
📦 安装指南
若要使用该模型,需安装diffusers
及相关依赖包:
$ pip install diffusers transformers accelerate
💻 使用示例
基础用法
from transformers import pipeline
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
from PIL import Image
import numpy as np
import torch
from diffusers.utils import load_image
depth_estimator = pipeline('depth-estimation')
image = load_image("https://huggingface.co/lllyasviel/sd-controlnet-depth/resolve/main/images/stormtrooper.png")
image = depth_estimator(image)['depth']
image = np.array(image)
image = image[:, :, None]
image = np.concatenate([image, image, image], axis=2)
image = Image.fromarray(image)
controlnet = ControlNetModel.from_pretrained(
"lllyasviel/sd-controlnet-depth", torch_dtype=torch.float16
)
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16
)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_xformers_memory_efficient_attention()
pipe.enable_model_cpu_offload()
image = pipe("Stormtrooper's lecture", image, num_inference_steps=20).images[0]
image.save('./images/stormtrooper_depth_out.png')



📚 详细文档
模型详情
发布的检查点
作者发布了8种不同的检查点,每种都基于 Stable Diffusion v1 - 5 在不同类型的条件下进行训练:
训练情况
深度模型在300万个深度图像 - 标题对上进行训练。深度图像使用Midas生成。该模型以Stable Diffusion 1.5为基础模型,使用Nvidia A100 80G GPU训练了500小时。
博客文章
如需更多信息,请查看 ControlNet官方博客文章。
📄 许可证
本模型采用 The CreativeML OpenRAIL M license。