モデル概要
モデル特徴
モデル能力
使用事例
🚀 ControlNet LAION顔データセット
このデータセットは、人間の顔の表情でControlNetをトレーニングするために設計されています。瞳孔のキーポイントを含み、視線方向をコントロールできます。Stable Diffusion v2.1 base (512) とStable Diffusion v1.5でのトレーニングがテストされています。
🚀 クイックスタート
このセクションでは、ControlNet LAION顔データセットの概要、使用方法、ライセンス、クレジットについて説明します。
✨ 主な機能
- 人間の顔の表情でControlNetをトレーニングするためのデータセットです。
- 瞳孔のキーポイントを含み、視線方向をコントロールできます。
- Stable Diffusion v2.1 base (512) とStable Diffusion v1.5でのトレーニングがテストされています。
📦 インストール
ダウンロード
著作権の理由から、元のターゲットファイルを含めることはできません。tool_download_face_targets.py
スクリプトを提供しています。このスクリプトは training/laion-face-processed/metadata.json
を読み取り、ターゲットフォルダを作成します。このファイルには依存関係はありませんが、tqdmがインストールされている場合は使用されます。
トレーニング
ターゲットフォルダが完全に作成されたら、少なくとも24GBのVRAMを持つマシンでトレーニングを実行できます。私たちのモデルは、A6000で200時間(4エポック)トレーニングされました。
python tool_add_control.py ./models/v1-5-pruned-emaonly.ckpt ./models/controlnet_sd15_laion_face.ckpt
python ./train_laion_face_sd15.py
推論
gradio_face2image.py
を提供しています。以下の2行を更新して、トレーニングしたモデルを指定してください。
model = create_model('./models/cldm_v21.yaml').cpu() # If you fine-tune on SD2.1 base, this does not need to change.
model.load_state_dict(load_state_dict('./models/control_sd21_openpose.pth', location='cuda'))
このモデルにはいくつかの制限があります。経験的に、視線と口のポーズの追跡において以前の試みよりも優れていますが、コントロールを無視することがあります。プロンプトに「右を見ている」などの詳細を追加すると、この問題を軽減できます。
Diffusersを使用する場合
このチェックポイントは Stable Diffusion 2.1 - Base でトレーニングされているため、これと一緒に使用することをおすすめします。実験的に、他の拡散モデル(dreamboothed stable diffusionなど)とも使用できます。
Stable Diffusion 1.5と一緒に使用する場合は、from_pretrained
の引数に subfolder="diffusion_sd15"
を追加してください。v1.5の半精度バリアントも提供されていますが、テストされていません。
diffusers
と関連パッケージをインストールします。
pip install diffusers transformers accelerate
- 以下のコードを実行します。
from PIL import Image
import numpy as np
import torch
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
from diffusers.utils import load_image
image = load_image(
"https://huggingface.co/CrucibleAI/ControlNetMediaPipeFace/resolve/main/samples_laion_face_dataset/family_annotation.png"
)
# Stable Diffusion 2.1-base:
controlnet = ControlNetModel.from_pretrained("CrucibleAI/ControlNetMediaPipeFace", torch_dtype=torch.float16, variant="fp16")
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-base", controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16
)
# OR
# Stable Diffusion 1.5:
controlnet = ControlNetModel.from_pretrained("CrucibleAI/ControlNetMediaPipeFace", subfolder="diffusion_sd15")
pipe = StableDiffusionControlNetPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", controlnet=controlnet, safety_checker=None)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
# Remove if you do not have xformers installed
# see https://huggingface.co/docs/diffusers/v0.13.0/en/optimization/xformers#installing-xformers
# for installation instructions
pipe.enable_xformers_memory_efficient_attention()
pipe.enable_model_cpu_offload()
image = pipe("a happy family at a dentist advertisement", image=image, num_inference_steps=30).images[0]
image.save('./images.png')
💻 使用例
基本的な使用法
# 推論のコード例
from PIL import Image
import numpy as np
import torch
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
from diffusers.utils import load_image
image = load_image(
"https://huggingface.co/CrucibleAI/ControlNetMediaPipeFace/resolve/main/samples_laion_face_dataset/family_annotation.png"
)
# Stable Diffusion 2.1-base:
controlnet = ControlNetModel.from_pretrained("CrucibleAI/ControlNetMediaPipeFace", torch_dtype=torch.float16, variant="fp16")
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-base", controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16
)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_xformers_memory_efficient_attention()
pipe.enable_model_cpu_offload()
image = pipe("a happy family at a dentist advertisement", image=image, num_inference_steps=30).images[0]
image.save('./images.png')
📚 ドキュメント
概要
このデータセットは、人間の顔の表情でControlNetをトレーニングするために設計されています。瞳孔のキーポイントを含み、視線方向をコントロールできます。Stable Diffusion v2.1 base (512) とStable Diffusion v1.5でのトレーニングがテストされています。
サンプル
ControlNet + Stable Diffusion v2.1 Baseから選ばれたサンプルです。
入力 | 顔検出 | 出力 |
---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
複数の顔が含まれる画像もサポートされています。



データセットの内容
train_laion_face.py
- ControlNetトレーニングのエントリーポイントです。laion_face_dataset.py
- データセットの反復処理を行うコードです。クロッピングとリサイズがここで行われます。tool_download_face_targets.py
-metadata.json
を読み取り、ターゲットフォルダを作成するツールです。tool_generate_face_poses.py
- ソース画像を生成するために使用された元のファイルです。再現性のために含まれていますが、トレーニングには必要ありません。training/laion-face-processed/prompt.jsonl
-laion_face_dataset
が読み取るファイルです。画像のプロンプトが含まれています。training/laion-face-processed/metadata.json
- 関連データのLAIONからの抜粋です。ターゲットデータセットのダウンロードにも使用されます。training/laion-face-processed/source/xxxxxxxxx.jpg
- 検出が行われた画像です。ターゲット画像から生成されます。training/laion-face-processed/target/xxxxxxxxx.jpg
- LAION Faceから選ばれた画像です。
データセットの構築
ソース画像は、LAION Faceからスライス00000を取得し、特殊な構成パラメータでMediaPipeの顔検出器に通すことで生成されました。
MediaPipeで使用される色と線の太さは以下の通りです。
f_thick = 2
f_rad = 1
right_iris_draw = DrawingSpec(color=(10, 200, 250), thickness=f_thick, circle_radius=f_rad)
right_eye_draw = DrawingSpec(color=(10, 200, 180), thickness=f_thick, circle_radius=f_rad)
right_eyebrow_draw = DrawingSpec(color=(10, 220, 180), thickness=f_thick, circle_radius=f_rad)
left_iris_draw = DrawingSpec(color=(250, 200, 10), thickness=f_thick, circle_radius=f_rad)
left_eye_draw = DrawingSpec(color=(180, 200, 10), thickness=f_thick, circle_radius=f_rad)
left_eyebrow_draw = DrawingSpec(color=(180, 220, 10), thickness=f_thick, circle_radius=f_rad)
mouth_draw = DrawingSpec(color=(10, 180, 10), thickness=f_thick, circle_radius=f_rad)
head_draw = DrawingSpec(color=(10, 200, 10), thickness=f_thick, circle_radius=f_rad)
iris_landmark_spec = {468: right_iris_draw, 473: left_iris_draw}
私たちは、MediaPipeの一部の機能を変更した draw_pupils
メソッドを実装しています。保留中の変更がマージされるまでの暫定措置として存在します。
🔧 技術詳細
ソース画像は、LAION Faceからスライス00000を取得し、特殊な構成パラメータでMediaPipeの顔検出器に通すことで生成されました。MediaPipeで使用される色と線の太さはコード内で定義されており、draw_pupils
メソッドを実装して一部の機能を変更しています。
📄 ライセンス
ソース画像 (/training/laion-face-processed/source/)
この作品はCC0 1.0でマークされています。このライセンスのコピーを表示するには、http://creativecommons.org/publicdomain/zero/1.0 を訪問してください。
トレーニング済みモデル
私たちのトレーニング済みControlNetチェックポイントは、CreativeML Open RAIL-Mの下でリリースされています。
ソースコード
lllyasviel/ControlNetは、Apache License 2.0の下でライセンスされています。私たちの変更は同じライセンスの下でリリースされています。
クレジットと感謝
ControlNetのZhangら、Stable DiffusionのRombachら (StabilityAI)、LAIONのSchuhmannらに大きな感謝を捧げます。
このドキュメントのサンプル画像はUnsplashから取得されており、CC0です。
@misc{zhang2023adding,
title={Adding Conditional Control to Text-to-Image Diffusion Models},
author={Lvmin Zhang and Maneesh Agrawala},
year={2023},
eprint={2302.05543},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@misc{rombach2021highresolution,
title={High-Resolution Image Synthesis with Latent Diffusion Models},
author={Robin Rombach and Andreas Blattmann and Dominik Lorenz and Patrick Esser and Björn Ommer},
year={2021},
eprint={2112.10752},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@misc{schuhmann2022laion5b,
title={LAION-5B: An open large-scale dataset for training next generation image-text models},
author={Christoph Schuhmann and Romain Beaumont and Richard Vencu and Cade Gordon and Ross Wightman and Mehdi Cherti and Theo Coombes and Aarush Katta and Clayton Mullis and Mitchell Wortsman and Patrick Schramowski and Srivatsa Kundurthy and Katherine Crowson and Ludwig Schmidt and Robert Kaczmarczyk and Jenia Jitsev},
year={2022},
eprint={2210.08402},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
このプロジェクトはCrucible AIによって可能になりました。

