模型概述
模型特點
模型能力
使用案例
🚀 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顯存的機器上進行訓練。我們的模型在A6000上訓練了200小時(四個週期)。
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
文件。更新以下兩行代碼,使其指向你訓練好的模型:
model = create_model('./models/cldm_v21.yaml').cpu() # 如果你在SD2.1 base上進行微調,這行無需更改。
model.load_state_dict(load_state_dict('./models/control_sd21_openpose.pth', location='cuda'))
✨ 主要特性
- 專為面部表情訓練:該數據集旨在訓練能處理人類面部表情的ControlNet,包含瞳孔關鍵點以實現視線方向控制。
- 多模型兼容性:訓練已在Stable Diffusion v2.1 base (512)和Stable Diffusion v1.5上進行測試。
- 支持多人臉圖像:模型能夠處理包含多個人臉的圖像。
📦 安裝指南
將包含的ZIP文件解壓到ControlNet目錄的根目錄。train_laion_face.py
、laion_face_dataset.py
和其他.py
文件應與tutorial_train.py
和tutorial_train_sd21.py
放在同一目錄下。我們假設使用的是ControlNet倉庫的0acb7e5版本,但該項目與倉庫無直接依賴關係。
💻 使用示例
基礎用法
使用diffusers
庫進行推理的示例代碼如下:
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')
高級用法
在推理時,可以通過在提示中添加更多細節來改善模型的表現,例如:
image = pipe("a happy family looking right at a dentist advertisement", image=image, num_inference_steps=30).images[0]
image.save('./images_advanced.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}
我們實現了一個名為draw_pupils
的方法,對MediaPipe的部分功能進行了修改,該方法是在某些待合併的更改之前的臨時解決方案。
數據集使用
下載
使用tool_download_face_targets.py
腳本讀取training/laion-face-processed/metadata.json
並填充目標文件夾。
訓練
在目標文件夾填充完畢後,在至少擁有24GB顯存的機器上進行訓練。
推理
使用gradio_face2image.py
進行推理,並更新代碼中的模型路徑。
模型侷限性
模型雖然在跟蹤視線和嘴巴姿勢方面比之前的嘗試有了經驗性的提升,但仍可能忽略控制信息。在提示中添加更多細節,如“looking right”,可以改善這種情況。
🔧 技術細節
模型訓練
模型在Stable Diffusion v2.1 base (512)和Stable Diffusion v1.5上進行訓練,在A6000上訓練了200小時(四個週期)。
推理代碼
使用diffusers
庫進行推理,通過StableDiffusionControlNetPipeline
和ControlNetModel
加載模型,並進行圖像生成。
📄 許可證
源圖像 (/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許可協議。我們的修改也採用相同的許可協議發佈。
致謝
非常感謝Zhang等人提出的ControlNet,Rombach等人(StabilityAI)提出的Stable Diffusion,以及Schuhmann等人提出的LAION。
本文檔的示例圖像來自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完成。
信息表格
屬性 | 詳情 |
---|---|
模型類型 | ControlNet |
訓練數據 | LAION-Face、LAION |
基礎模型 | stabilityai/stable-diffusion-2-1-base |
管道標籤 | image-to-image |
常用提示信息
⚠️ 重要提示
由於版權原因,原始目標文件未包含在數據集中,需要使用
tool_download_face_targets.py
腳本進行下載。
💡 使用建議
在推理時,可以在提示中添加更多細節,如“looking right”,以改善模型的表現。

