ジャコ Lab

プログラミング関連のメモ帳的ブログです

ControlNet の Scribble を使ってみる

lllyasviel/control_v11p_sd15_scribble · Hugging Face

もう少しで diffusers の ControlNet 完全制覇です。残すところあと4つ!
今回は Scribble を使ってみます。

Scribble

Google 翻訳っと!

落書き

なるほど!

今回も controlnet_aux は必要です

!pip install -U controlnet_aux

投入画像の準備

from diffusers.utils import load_image
from controlnet_aux import HEDdetector

init_image_url = "https://huggingface.co/lllyasviel/control_v11p_sd15_scribble/resolve/main/images/input.png"
init_image = load_image(init_image_url)

processor = HEDdetector.from_pretrained('lllyasviel/Annotators')
control_image = processor(init_image, scribble=True)

(左) 投入画像 | (右) HEDdetector で抽出した画像

scribble=Trueの部分がやっぱり気になる。消してみたらどうなるか?

scribble 引数無し

なるほど!

ControlNet, Pipeline の準備

import torch
from diffusers import ControlNetModel, StableDiffusionControlNetPipeline, UniPCMultistepScheduler

# ControlNet の準備
controlnet = ControlNetModel.from_pretrained(
    "lllyasviel/control_v11p_sd15_scribble",
    torch_dtype=torch.float16
)

# Pipeline の準備
pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float16,
    controlnet=controlnet
)
pipe.enable_model_cpu_offload()

# スケジューラーの設定
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
変わり映えの無いいつものやつ

パイプライン実行

prompt = "royal chamber with fancy bed"
image = pipe(
    prompt,
    num_inference_steps=30,
    generator=torch.manual_seed(0),
    image=control_image
).images[0]
image

ControlNet の Scribble で生成した画像

まとめ

scribble=True

(左) device="cpu" | (右) device="cuda"

scribble=False

(左) device="cpu" | (右) device="cuda"

そういえば

Model Card 上の生成物とは全然違いましたね。
クオリティが高すぎて、全然気にしてませんでした。

(左) Model Card 上の生成物 | (右) 今回の生成物