今日は、NormalBae を使ってみます。
Bae って何なんでしょう?
中身的には法線マップを使った ControlNet っぽいんですが。。。
NormalBae?
どうやら、Blender や Unity 等では Normal Map と呼ばれる法線マップを使う ControlNet のようです。
私の知っている法線マップは、テクスチャ画像の情報で、モデル表面に凹凸や溝、傷などがあるかのように見せるために使います。
controlnet_aux モジュールをインストール
今回も controlnet_aux モジュールを使います。
使用するクラスは NormalBaeDetector となります。
!pip install controlnet_aux
投入画像の準備
from diffusers.utils import load_image from controlnet_aux import NormalBaeDetector # 投入画像の準備 init_image_url = "https://huggingface.co/lllyasviel/control_v11p_sd15_normalbae/resolve/main/images/input.png" init_image = load_image(init_image_url) processor = NormalBaeDetector.from_pretrained("lllyasviel/Annotators") control_image = processor(init_image)
ControlNet, Pipeline の準備
import torch from diffusers import ControlNetModel, StableDiffusionControlNetPipeline, UniPCMultistepScheduler # ControlNet の準備 controlnet = ControlNetModel.from_pretrained( "lllyasviel/control_v11p_sd15_normalbae", torch_dtype=torch.float16 ) # Pipeline の準備 pipe = StableDiffusionControlNetPipeline.from_pretrained( "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, controlnet=controlnet, ).to("cuda") pipe.enable_model_cpu_offload() # スケジューラーの設定 pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
パイプライン実行
prompt = "A head full of roses" image = pipe( prompt, num_inference_steps=30, generator=torch.manual_seed(33), image=control_image ).images[0] image
まとめ
ControlNet、本当に色々できるなぁ...