🚀 Controlnet - v1.1 - Tile版本
Controlnet v1.1是一种强大的神经网络结构,可通过添加额外条件来控制扩散模型。本项目提供了该模型的特定版本(Tile版本),可与Stable Diffusion结合使用,为图像生成带来更多可能性。
🚀 快速开始
Controlnet v1.1 由 Lvmin Zhang 在 lllyasviel/ControlNet-v1-1 中发布。
此检查点是将 原始检查点 转换为 diffusers
格式后的版本。它可以与 Stable Diffusion 结合使用,例如 runwayml/stable-diffusion-v1-5。
更多详细信息,请查看 🧨 Diffusers文档。
ControlNet是一种神经网络结构,通过添加额外条件来控制扩散模型。

此检查点对应于基于 平铺图像 进行条件控制的ControlNet。从概念上讲,它类似于超分辨率模型,但用途不仅限于此,也可以生成与输入(条件)图像相同大小的细节。
本模型由 takuma104 贡献
✨ 主要特性
- 可与Stable Diffusion结合使用,增强图像生成能力。
- 基于平铺图像进行条件控制,适用于多种图像生成场景。
- 训练速度快,可在个人设备上进行训练。
📦 安装指南
安装依赖包
$ pip install diffusers transformers accelerate
💻 使用示例
基础用法
import torch
from PIL import Image
from diffusers import ControlNetModel, DiffusionPipeline
from diffusers.utils import load_image
def resize_for_condition_image(input_image: Image, resolution: int):
input_image = input_image.convert("RGB")
W, H = input_image.size
k = float(resolution) / min(H, W)
H *= k
W *= k
H = int(round(H / 64.0)) * 64
W = int(round(W / 64.0)) * 64
img = input_image.resize((W, H), resample=Image.LANCZOS)
return img
controlnet = ControlNetModel.from_pretrained('lllyasviel/control_v11f1e_sd15_tile',
torch_dtype=torch.float16)
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5",
custom_pipeline="stable_diffusion_controlnet_img2img",
controlnet=controlnet,
torch_dtype=torch.float16).to('cuda')
pipe.enable_xformers_memory_efficient_attention()
source_image = load_image('https://huggingface.co/lllyasviel/control_v11f1e_sd15_tile/resolve/main/images/original.png')
condition_image = resize_for_condition_image(source_image, 1024)
image = pipe(prompt="best quality",
negative_prompt="blur, lowres, bad anatomy, bad hands, cropped, worst quality",
image=condition_image,
controlnet_conditioning_image=condition_image,
width=condition_image.size[0],
height=condition_image.size[1],
strength=1.0,
generator=torch.manual_seed(0),
num_inference_steps=32,
).images[0]
image.save('output.png')

高级用法
暂无高级用法示例,你可以根据基础用法进行扩展和调整。
📚 详细文档
模型详情
模型介绍
Controlnet由Lvmin Zhang和Maneesh Agrawala在 Adding Conditional Control to Text-to-Image Diffusion Models 中提出。
论文摘要如下:
我们提出了一种神经网络结构ControlNet,用于控制预训练的大型扩散模型以支持额外的输入条件。ControlNet以端到端的方式学习特定任务的条件,即使训练数据集较小(< 50k),学习过程也很稳健。此外,训练ControlNet的速度与微调扩散模型的速度一样快,并且可以在个人设备上进行训练。或者,如果有强大的计算集群可用,模型可以扩展到处理大量(数百万到数十亿)的数据。我们报告称,像Stable Diffusion这样的大型扩散模型可以通过ControlNet进行增强,以支持边缘图、分割图、关键点等条件输入。这可能会丰富控制大型扩散模型的方法,并进一步促进相关应用的发展。
其他已发布的检查点 v1-1
作者发布了14种不同的检查点,每种都在 Stable Diffusion v1-5 上针对不同类型的条件进行了训练:
更多信息
更多信息,请查看 Diffusers ControlNet博客文章 和 官方文档。
📄 许可证
本项目使用 CreativeML OpenRAIL M许可证。