模型简介
模型特点
模型能力
使用案例
🚀 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”,以改善模型的表现。

