🚀 Controlnet - v1.1 - InPaint Version
ControlNet v1.1は、拡散モデルを追加条件で制御するためのニューラルネットワーク構造です。このチェックポイントは、画像インペイントに対応したバージョンで、Stable Diffusionと組み合わせて使用できます。
🚀 クイックスタート
Controlnet v1.1 は Lvmin Zhang によって lllyasviel/ControlNet-v1-1 でリリースされました。
このチェックポイントは、元のチェックポイント を diffusers
形式に変換したものです。Stable Diffusion、例えば runwayml/stable-diffusion-v1-5 と組み合わせて使用できます。
詳細については、🧨 Diffusers ドキュメント も参照してください。
ControlNetは、追加条件を加えることで拡散モデルを制御するニューラルネットワーク構造です。

このチェックポイントは、インペイント画像 を条件としたControlNetに対応しています。
✨ 主な機能
- 拡散モデルを追加条件で制御できる。
- 小さなトレーニングデータセットでもロバストに学習できる。
- トレーニングが高速で、個人のデバイスでも可能。
📦 インストール
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]

📚 ドキュメント
モデル詳細
導入
Controlnetは、Lvmin ZhangとManeesh Agrawalaによる Adding Conditional Control to Text-to-Image Diffusion Models で提案されました。
概要は以下の通りです。
我々は、事前学習された大規模拡散モデルを制御して追加の入力条件をサポートするためのニューラルネットワーク構造、ControlNetを提案します。ControlNetは、タスク固有の条件をエンドツーエンドで学習し、トレーニングデータセットが小さい場合(< 50k)でもロバストに学習します。さらに、ControlNetのトレーニングは拡散モデルの微調整と同じくらい速く、個人のデバイスでもトレーニングできます。あるいは、強力な計算クラスターが利用可能な場合、モデルは大量(数百万から数十億)のデータに拡張できます。我々は、Stable Diffusionのような大規模拡散モデルにControlNetを追加することで、エッジマップ、セグメンテーションマップ、キーポイントなどの条件付き入力を可能にできることを報告します。これにより、大規模拡散モデルを制御する方法が豊富になり、関連するアプリケーションがさらに促進される可能性があります。
その他のリリースされたチェックポイント v1-1
著者らは、Stable Diffusion v1-5 でそれぞれ異なるタイプの条件付きでトレーニングされた14の異なるチェックポイントをリリースしました。
📄 ライセンス
このモデルは The CreativeML OpenRAIL M license の下で提供されています。