「sd插件第一篇」sd-webui-EasyPhoto 您的智能 AI 照片生成器

技术
前言

在人工智能盛行的当下,各类大模型如雨后春笋般争先恐后地破土而出,AI绘画作为其中极其重要的一员也不停地向我们展示出它的强大能力。本文是笔者在做证件照时发现的一款stable-diffusion webui的插件,极其好用,向大家推荐一下。从本篇开始,笔者会陆续推出stable-diffusion和Midjourney相关的内容梳理了,后续会推出一系列的stable-diffusion webui的插件教程和讲解,敬请期待。

[1]简介

EasyPhoto是一款Webui UI插件,用于生成AI肖像画,该代码可用于训练与您相关的数字分身。建议使用 5 到 20 张肖像图片进行训练,最好是半身照片且不要佩戴眼镜(少量可以接受)。训练完成后,我们可以在推理部分生成图像。我们支持使用预设模板图片与上传自己的图片进行推理。

这些是我们的生成结果: [2] [3]

picture.image

我们的ui界面如下:
训练部分: [4]

picture.image

预测部分: [5]

picture.image

[6]新功能

•创建代码!现在支持 Windows 和 Linux。[🔥 2023.09.02]

[7]TODO List

•支持中文界面。 •支持模板背景部分变化。 •支持高分辨率。 •支持多人模板。

[8]快速启动

[9]1. 环境检查

我们已验证EasyPhoto可在以下环境中执行:

Windows 10 的详细信息:

•操作系统: Windows10 •python: python 3.10 •pytorch: torch2.0.1 •tensorflow-cpu: 2.13.0 •CUDA: 11.7 •CUDNN: 8+ •GPU: Nvidia-3060 12G

Linux 的详细信息:

•操作系统 Ubuntu 20.04, CentOS •python: python3.10 & python3.11 •pytorch: torch2.0.1 •tensorflow-cpu: 2.13.0 •CUDA: 11.7 •CUDNN: 8+ •GPU: Nvidia-A10 24G & Nvidia-V100 16G & Nvidia-A100 40G

我们需要大约 60GB 的可用磁盘空间(用于保存权重和数据集),请检查!

[10]2. 相关资料库和权重下载

[11]a. Controlnet

我们需要使用 Controlnet 进行推理。相关软件源是Mikubill/sd-webui-controlnet[12]。在使用 EasyPhoto 之前,您需要安装这个软件源。

此外,我们至少需要三个 Controlnets 用于推理。因此,您需要设置 Multi ControlNet: Max models amount (requires restart) 。 [13]

picture.image

[14]b. 其他依赖关系。

我们与现有的 stable-diffusion-webui 环境相互兼容,启动 stable-diffusion-webui 时会安装相关软件源。

我们所需的权重会在第一次开始训练时自动下载。

[15]3. 插件安装

现在我们支持从 git 安装 EasyPhoto。我们的仓库网址是 https://github.com/aigc-apps/sd-webui-EasyPhoto。[16]

今后,我们将支持从 Available 安装 EasyPhoto。

[17]

picture.image

[18]算法详细信息

[19]1.架构概述

[20]picture.image

在人工智能肖像领域,我们希望模型生成的图像逼真且与用户相似,而传统方法会引入不真实的光照(如人脸融合或roop)。为了解决这种不真实的问题,我们引入了稳定扩散模型的图像到图像功能。生成完美的个人肖像需要考虑所需的生成场景和用户的数字二重身。我们使用一个预先准备好的模板作为所需的生成场景,并使用一个在线训练的人脸 LoRA 模型作为用户的数字二重身,这是一种流行的稳定扩散微调模型。我们使用少量用户图像来训练用户的稳定数字二重身,并在推理过程中根据人脸 LoRA 模型和预期生成场景生成个人肖像图像。

[21]训练细节

[22]picture.image

首先,我们对输入的用户图像进行人脸检测,确定人脸位置后,按照一定比例截取输入图像。然后,我们使用显著性检测模型和皮肤美化模型获得干净的人脸训练图像,该图像基本上只包含人脸。然后,我们为每张图像贴上一个固定标签。这里不需要使用标签器,而且效果很好。最后,我们对稳定扩散模型进行微调,得到用户的数字二重身。

在训练过程中,我们会利用模板图像进行实时验证,在训练结束后,我们会计算验证图像与用户图像之间的人脸 ID 差距,从而实现 Lora 融合,确保我们的 Lora 是用户的完美数字二重身。

此外,我们将选择验证中与用户最相似的图像作为 face_id 图像,用于推理。

[23]3.推理细节

[24]a.第一次扩散:

首先,我们将对接收到的模板图像进行人脸检测,以确定为实现稳定扩散而需要涂抹的遮罩。然后,我们将使用模板图像与最佳用户图像进行人脸融合。人脸融合完成后,我们将使用上述遮罩对融合后的人脸图像进行内绘(fusion_image)。此外,我们还将通过仿射变换(replace_image)把训练中获得的最佳 face_id 图像贴到模板图像上。然后,我们将对其应用 Controlnets,在融合图像中使用带有颜色的 canny 提取特征,在替换图像中使用 openpose 提取特征,以确保图像的相似性和稳定性。然后,我们将使用稳定扩散(Stable Diffusion)结合用户的数字分割进行生成。

[25]b.第二次扩散:

在得到第一次扩散的结果后,我们将把该结果与最佳用户图像进行人脸融合,然后再次使用稳定扩散与用户的数字二重身进行生成。第二次生成将使用更高的分辨率。

[26]参考文献

•insightface:GitHub - deepinsight/insightface: State-of-the-art 2D and 3D Face Analysis Project[27] •cv_resnet50_face:https://www.modelscope.cn/models/damo/cv\_resnet50\_face-detection\_retinaface/summary •cv_u2net_salient:https://www.modelscope.cn/models/damo/cv\_u2net\_salient-detection/summary •cv_unet_skin_retouching_torch:https://www.modelscope.cn/models/damo/cv\_unet\_skin\_retouching\_torch/summary •cv_unet-image-face-fusion:https://www.modelscope.cn/models/damo/cv\_unet-image-face-fusion\_damo/summary •kohya:GitHub - bmaltais/kohya_ss[28] •controlnet-webui:GitHub - Mikubill/sd-webui-controlnet: WebUI extension for ControlNet[29]

[30]许可证

本项目采用 Apache License (Version 2.0)[31].

声明

本文大部分内容整理自:GitHub - aigc-apps/sd-webui-EasyPhoto: 📷 EasyPhoto | Your Smart AI Photo Generator.[32],后续会推出一系列的stable-diffusion webui的插件教程和讲解,敬请期待。

References

[1] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#%E7%AE%80%E4%BB%8B
[2] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/images/results\_1.jpg
[3] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/images/results\_2.jpg
[4] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/images/train\_ui.jpg
[5] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/images/infer\_ui.jpg
[6] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#%E6%96%B0%E5%8A%9F%E8%83%BD
[7] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#todo-list
[8] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#%E5%BF%AB%E9%80%9F%E5%90%AF%E5%8A%A8
[9] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#1-%E7%8E%AF%E5%A2%83%E6%A3%80%E6%9F%A5
[10] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#2-%E7%9B%B8%E5%85%B3%E8%B5%84%E6%96%99%E5%BA%93%E5%92%8C%E6%9D%83%E9%87%8D%E4%B8%8B%E8%BD%BD
[11] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#a-controlnet
[12] Mikubill/sd-webui-controlnet: https://github.com/Mikubill/sd-webui-controlnet
[13] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/images/controlnet\_num.png
[14] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#b-%E5%85%B6%E4%BB%96%E4%BE%9D%E8%B5%96%E5%85%B3%E7%B3%BB
[15] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#3-%E6%8F%92%E4%BB%B6%E5%AE%89%E8%A3%85
[16] https://github.com/aigc-apps/sd-webui-EasyPhoto。: https://github.com/aigc-apps/sd-webui-EasyPhoto%E3%80%82
[17] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/images/install.jpg
[18] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#%E7%AE%97%E6%B3%95%E8%AF%A6%E7%BB%86%E4%BF%A1%E6%81%AF
[19] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#1%E6%9E%B6%E6%9E%84%E6%A6%82%E8%BF%B0
[20] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/images/overview.jpg
[21] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#%E8%AE%AD%E7%BB%83%E7%BB%86%E8%8A%82
[22] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/images/train\_detail.jpg
[23] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#3%E6%8E%A8%E7%90%86%E7%BB%86%E8%8A%82
[24] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#a%E7%AC%AC%E4%B8%80%E6%AC%A1%E6%89%A9%E6%95%A3
[25] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#b%E7%AC%AC%E4%BA%8C%E6%AC%A1%E6%89%A9%E6%95%A3
[26] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE
[27] GitHub - deepinsight/insightface: State-of-the-art 2D and 3D Face Analysis Project: https://github.com/deepinsight/insightface
[28] GitHub - bmaltais/kohya_ss: https://github.com/bmaltais/kohya\_ss
[29] GitHub - Mikubill/sd-webui-controlnet: WebUI extension for ControlNet: https://github.com/Mikubill/sd-webui-controlnet
[30] : https://github.com/aigc-apps/sd-webui-EasyPhoto/blob/main/README\_zh-CN.md#%E8%AE%B8%E5%8F%AF%E8%AF%81
[31] Apache License (Version 2.0): https://github.com/modelscope/modelscope/blob/master/LICENSE
[32] GitHub - aigc-apps/sd-webui-EasyPhoto: 📷 EasyPhoto | Your Smart AI Photo Generator.: https://github.com/aigc-apps/sd-webui-EasyPhoto

0
0
0
0
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论