模型:

CrucibleAI/ControlNetMediaPipeFace

英文

ControlNet LAION 人脸数据集

目录:

  • 概述: 样本、内容和构建
  • 使用方法: 下载、训练和推断
  • 许可证
  • 鸣谢和感谢

概述:

此数据集旨在训练具有人脸表情的 ControlNet。它包含了用于瞳孔的关键点,以便于注视方向。训练已在 Stable Diffusion v2.1 版本(512)和 Stable Diffusion v1.5 上进行过测试。

样本:

从 ControlNet + Stable Diffusion v2.1 Base 中精选

1237321 1238321 1239321 12310321 12311321 12312321 12313321 12314321 12315321 12316321 12317321 12318321 12319321 12320321 12321321 12322321 12323321 12324321
Input Face Detection Output

也支持含有多个人脸的图像:

数据集内容:

  • 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 人脸库的选定图像。

数据集构建:

源图像是通过从 LAION 人脸库中提取片段 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 的一些功能。它存在作为临时措施,直到某些未解决的更改合并。

使用方法:

应将包含的 ZIP 文件解压缩到 ControlNet 目录的根目录中。 train_laion_face.py、laion_face_dataset.py 和其他 .py 文件应与 tutorial_train.py 和 tutorial_train_sd21.py 放在一起。我们假设 ControlNet 仓库的检出点为 0acb7e5,但不直接依赖于该仓库。

下载:

基于版权原因,我们无法包含原始目标文件。我们提供了一个脚本 (tool_download_face_targets.py),它将从 training/laion-face-processed/metadata.json 读取并填充目标文件夹。此文件没有任何要求,但如果已安装 tqdm,将使用它。

训练:

当目标文件夹完全填充时,可以在至少具有 24 GB VRAM 的机器上进行训练。我们的模型在 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()  # 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'))

该模型有一些局限性: 虽然在跟踪注视和嘴部姿势方面经验上要好于以前的尝试,但它仍可能忽略控制。通过在提示中添加诸如“向右看”等细节,可以减轻不良行为。

🧨 扩散器

建议使用带有 Stable Diffusion 2.1 - Base 的检查点,因为该检查点已经针对其进行了训练。从实验上看,该检查点可以与其他扩散模型(如 dreamboothed stable diffusion)一起使用。

要与 Stable Diffusion 1.5 一起使用,请将 subfolder="diffusion_sd15" 插入 from_pretrained 参数中。提供了 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')
    

    许可证:

    源图像: (/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 实现。