许可协议: openrail
基础模型: runwayml/stable-diffusion-v1-5
标签:
- 艺术
- 控制网
- 稳定扩散
- controlnet-v1-1
- 图像转图像
复刻来源: ControlNet-1-1-preview/control_v11f1e_sd15_tile
Controlnet - v1.1 - 分块版本
Controlnet v1.1 由 Lvmin Zhang 发布于 lllyasviel/ControlNet-v1-1。
此检查点是将原检查点转换为 diffusers
格式的版本。
可与 Stable Diffusion 结合使用,例如 runwayml/stable-diffusion-v1-5。
更多详情,请参阅 🧨 Diffusers 文档。
ControlNet 是一种通过添加额外条件来控制扩散模型的神经网络结构。

此检查点对应基于分块图像条件的 ControlNet。概念上类似于超分辨率模型,但其用途不仅限于此。它还能在输入(条件)图像相同尺寸下生成细节。
此模型由 takuma104 贡献
模型详情
-
开发者: Lvmin Zhang, Maneesh Agrawala
-
模型类型: 基于扩散的文本到图像生成模型
-
语言: 英语
-
许可协议: CreativeML OpenRAIL M 许可证,改编自 BigScience 和 RAIL Initiative 在负责任 AI 许可领域的合作成果。另见基于 BLOOM Open RAIL 许可证 的相关文章。
-
更多资源: GitHub 仓库, 论文。
-
引用方式:
@misc{zhang2023adding,
title={Adding Conditional Control to Text-to-Image Diffusion Models},
author={Lvmin Zhang and Maneesh Agrawala},
year={2023},
eprint={2302.05543},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
简介
ControlNet 由 Lvmin Zhang 和 Maneesh Agrawala 在论文 Adding Conditional Control to Text-to-Image Diffusion Models 中提出。
摘要如下:
我们提出了一种神经网络结构 ControlNet,通过添加额外输入条件来控制预训练的大型扩散模型。
ControlNet 以端到端方式学习任务特定条件,即使训练数据集较小(< 5万)也能保持鲁棒性。
此外,训练 ControlNet 与微调扩散模型速度相当,可在个人设备上完成。
若拥有强大计算集群,该模型可扩展至海量数据(百万至十亿级)。
实验表明,像 Stable Diffusion 这样的大型扩散模型结合 ControlNet 后,能支持边缘图、分割图、关键点等条件输入。
这将丰富控制大型扩散模型的方法,并推动相关应用发展。
示例
建议将此检查点与 Stable Diffusion v1-5 配合使用,因其基于该模型训练。
实验表明,该检查点也可与其他扩散模型(如 Dreambooth 微调的 Stable Diffusion)配合使用。
- 安装
diffusers
及相关包:
$ 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="最佳质量",
negative_prompt="模糊, 低分辨率, 结构异常, 手部畸形, 裁剪, 最差质量",
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')


v1-1 其他已发布检查点
作者发布了 14 个不同检查点,每个均基于 Stable Diffusion v1-5 训练,对应不同类型条件:
更多信息
更多信息请参阅 Diffusers ControlNet 博客文章 和 官方文档。