OpenPose!!
姿勢推定ですね。知ってます!
OpenPose
OpenPose は関節などの座標を検出し、点と点を結んで棒人間の画像です
この ControlNet では棒人間の姿勢を再現した絵を生成します
controlnet_aux が必要
今回も XxxDetector (今回は OpenposeDetector) を使うので controlnet_aux が必要になります
!pip install -U controlnet_aux
投入画像の準備
from diffusers.utils import load_image from controlnet_aux import OpenposeDetector # 投入画像の準備 init_image_url = "https://huggingface.co/lllyasviel/control_v11p_sd15_openpose/resolve/main/images/input.png" init_image = load_image(init_image_url) processor = OpenposeDetector.from_pretrained('lllyasviel/ControlNet') control_image = processor(init_image, hand_and_face=True)
hand_and_face=True
によって、顔も抽出していそうですね。
ControlNet, Pipeline の準備
import torch from diffusers import ControlNetModel, StableDiffusionControlNetPipeline, UniPCMultistepScheduler # ControlNet の準備 controlnet = ControlNetModel.from_pretrained( "lllyasviel/control_v11p_sd15_openpose", 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 = "chef in the kitchen" image = pipe( prompt, num_inference_steps=30, generator=torch.manual_seed(0), image=control_image ).images[0] image
まとめ
ハゲちゃいました