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

此检查点对应基于 修复图像 条件的 ControlNet。
模型详情
简介
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 一起使用,因为检查点已在其上训练。
实验上,该检查点也可以与其他扩散模型(如 dreamboothed stable diffusion)一起使用。
- 安装
diffusers
及相关包:
$ pip install diffusers transformers accelerate
- 运行代码:
from diffusers import StableDiffusionControlNetInpaintPipeline, ControlNetModel
from diffusers.utils import load_image
import numpy as np
import torch
init_image = load_image(
"https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_inpaint/boy.png"
)
init_image = init_image.resize((512, 512))
generator = torch.Generator(device="cpu").manual_seed(1)
mask_image = load_image(
"https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_inpaint/boy_mask.png"
)
mask_image = mask_image.resize((512, 512))
def make_inpaint_condition(image, image_mask):
image = np.array(image.convert("RGB")).astype(np.float32) / 255.0
image_mask = np.array(image_mask.convert("L")).astype(np.float32) / 255.0
assert image.shape[0:1] == image_mask.shape[0:1], "image and image_mask must have the same image size"
image[image_mask > 0.5] = -1.0
image = np.expand_dims(image, 0).transpose(0, 3, 1, 2)
image = torch.from_numpy(image)
return image
control_image = make_inpaint_condition(init_image, mask_image)
controlnet = ControlNetModel.from_pretrained(
"lllyasviel/control_v11p_sd15_inpaint", torch_dtype=torch.float16
)
pipe = StableDiffusionControlNetInpaintPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
)
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload()
image = pipe(
"a handsome man with ray-ban sunglasses",
num_inference_steps=20,
generator=generator,
eta=1.0,
image=init_image,
mask_image=mask_image,
control_image=control_image,
).images[0]



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