fix dependencies. break things.

main
Jay 1 week ago
parent 42d1c75b68
commit 98e26880f8

@ -0,0 +1,153 @@
# FaceSwapLab for a1111/Vlad
Tested on the following versions of stuff:
` python: 3.10.16  •  torch: 2.1.2+cu121  •  xformers: 0.0.23.post1  •  gradio: 3.41.2 `
albumentations set to 1.4.3 in requirements.txt - this should solve loading issues
patched imgutils.py
removed a dependency as it's functionality was disabled
this branch does not implement the issue mentioned here : https://github.com/glucauze/sd-webui-faceswaplab/issues/197
V1.2.3 : Breaking change for settings, please read changelog.
Please read the documentation here : https://glucauze.github.io/sd-webui-faceswaplab/
You can also read the [doc discussion section](https://github.com/glucauze/sd-webui-faceswaplab/discussions/categories/guide-doc)
See [CHANGELOG.md](CHANGELOG.md) for changes in last versions.
FaceSwapLab is an extension for Stable Diffusion that simplifies face-swapping. It has evolved from sd-webui-faceswap and some part of sd-webui-roop. However, a substantial amount of the code has been rewritten to improve performance and to better manage masks.
Some key features include the ability to reuse faces via checkpoints, multiple face units, batch process images, sort faces based on size or gender, and support for vladmantic. It also provides a face inpainting feature.
![](docs/assets/images/main_interface.png)
While FaceSwapLab is still under development, it has reached a good level of stability. This makes it a reliable tool for those who are interested in face-swapping within the Stable Diffusion environment. As with all projects of this type, its expected to improve and evolve over time.
## Disclaimer and license
In short:
+ **Ethical Guideline:** NSFW is now configurable due to performance issue. Please don't use this to do harm.
+ **License:** This software is distributed under the terms of the GNU Affero General Public License (AGPL), version 3 or later.
+ **Model License:** This software uses InsightFace's pre-trained models, which are available for non-commercial research purposes only.
More on this here : https://glucauze.github.io/sd-webui-faceswaplab/
### Known problems (wontfix):
+ Older versions of gradio don't work well with the extension. See this bug : https://github.com/glucauze/sd-webui-faceswaplab/issues/5
## Quick Start
Here are some gifs to explain (non cherry picked, just random pictures) :
## Simple Usage (roop like)
This use codeformer on all faces (including non swapped)
[simple.webm](https://github.com/glucauze/sd-webui-faceswaplab/assets/137925069/de00b685-d441-44f9-bae3-71cd7abef113)
## Advanced options
This is use to improve results. This use upscaling and codeformer only on swapped faces
[advanced.webm](https://github.com/glucauze/sd-webui-faceswaplab/assets/137925069/50630311-bd25-487f-871b-0a44eecd435d)
## Inpainting
This add inpainting on faces :
[inpainting.webm](https://github.com/glucauze/sd-webui-faceswaplab/assets/137925069/3d3508e9-5be4-4566-8c41-8301b2d08355)
## Build and use checkpoints :
[build.webm](https://github.com/glucauze/sd-webui-faceswaplab/assets/137925069/e84e9a3c-840d-4536-9fbb-09ed256406d7)
### Simple
1. Put a face in the reference.
2. Select a face number.
3. Select "Enable."
4. Select "CodeFormer" in **Global Post-Processing** tab.
Once you're happy with some results but want to improve, the next steps are to:
+ Use advanced settings in face units (which are not as complex as they might seem, it's basically fine tuning post-processing for each faces).
+ Use pre/post inpainting to tweak the image a bit for more natural results.
### Better
1. Put a face in the reference.
2. Select a face number.
3. Select "Enable."
4. In **Post-Processing** accordeon:
+ Select "CodeFormer"
+ Select "LDSR" or a faster model "003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN" in upscaler. See [here for a list of upscalers](https://github.com/glucauze/sd-webui-faceswaplab/discussions/29).
+ Use sharpen, color_correction and improved mask
5. Disable "CodeFormer" in **Global Post-Processing** tab (otherwise it will be applied twice)
Don't hesitate to share config in the [discussion section](https://github.com/glucauze/sd-webui-faceswaplab/discussions).
### Features
+ **Face Unit Concept**: Similar to controlNet, the program introduces the concept of a face unit. You can configure up to 10 units (3 units are the default setting) in the program settings (sd).
+ **Vladmantic and a1111 Support**
+ **Batch Processing**
+ **GPU**
+ **Inpainting Fixes** : supports “only masked” and mask inpainting.
+ **Performance Improvements**: The overall performance of the software has been enhanced.
+ **FaceSwapLab Tab**: providing various tools (build, compare, extract, batch)
+ **FaceSwapLab Settings**: FaceSwapLab settings are now part of the sd settings. To access them, navigate to the sd settings section.
+ **Face Reuse Via Checkpoints**: The FaceTools tab now allows creating checkpoints, which facilitate face reuse. When a checkpoint is used, it takes precedence over the reference image, and the reference source image is discarded.
+ **Gender Detection**: The program can now detect gender based on faces.
+ **Face Combination (Blending)**: Multiple versions of a face can be combined to enhance the swapping result. This blending happens during checkpoint creation.)
+ **Preserve Original Images**: You can opt to keep original images before the swapping process.
+ **Multiple Face Versions for Replacement**: The program allows the use of multiple versions of the same face for replacement.
+ **Face Similarity and Filtering**: You can compare faces against the reference and/or source images.
+ **Face Comparison**: face comparison feature.
+ **Face Extraction**: face extraction with or without upscaling.
+ **Improved Post-Processing**: codeformer, gfpgan, upscaling.
+ **Post Inpainting**: This feature allows the application of image-to-image inpainting specifically to faces.
+ **Upscaled Inswapper**: The program now includes an upscaled inswapper option, which improves results by incorporating upsampling, sharpness adjustment, and color correction before face is merged to the original image.
+ **API with typing support**
## Installation
See the documentation here : https://glucauze.github.io/sd-webui-faceswaplab/
"this is the version I'd use"

@ -1,133 +1,3 @@
# FaceSwapLab for a1111/Vlad SHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH.....
V1.2.3 : Breaking change for settings, please read changelog. Don't talk about it.
Please read the documentation here : https://glucauze.github.io/sd-webui-faceswaplab/
You can also read the [doc discussion section](https://github.com/glucauze/sd-webui-faceswaplab/discussions/categories/guide-doc)
See [CHANGELOG.md](CHANGELOG.md) for changes in last versions.
FaceSwapLab is an extension for Stable Diffusion that simplifies face-swapping. It has evolved from sd-webui-faceswap and some part of sd-webui-roop. However, a substantial amount of the code has been rewritten to improve performance and to better manage masks.
Some key features include the ability to reuse faces via checkpoints, multiple face units, batch process images, sort faces based on size or gender, and support for vladmantic. It also provides a face inpainting feature.
![](docs/assets/images/main_interface.png)
While FaceSwapLab is still under development, it has reached a good level of stability. This makes it a reliable tool for those who are interested in face-swapping within the Stable Diffusion environment. As with all projects of this type, its expected to improve and evolve over time.
## Disclaimer and license
In short:
+ **Ethical Guideline:** NSFW is now configurable due to performance issue. Please don't use this to do harm.
+ **License:** This software is distributed under the terms of the GNU Affero General Public License (AGPL), version 3 or later.
+ **Model License:** This software uses InsightFace's pre-trained models, which are available for non-commercial research purposes only.
More on this here : https://glucauze.github.io/sd-webui-faceswaplab/
### Known problems (wontfix):
+ Older versions of gradio don't work well with the extension. See this bug : https://github.com/glucauze/sd-webui-faceswaplab/issues/5
## Quick Start
Here are some gifs to explain (non cherry picked, just random pictures) :
## Simple Usage (roop like)
This use codeformer on all faces (including non swapped)
[simple.webm](https://github.com/glucauze/sd-webui-faceswaplab/assets/137925069/de00b685-d441-44f9-bae3-71cd7abef113)
## Advanced options
This is use to improve results. This use upscaling and codeformer only on swapped faces
[advanced.webm](https://github.com/glucauze/sd-webui-faceswaplab/assets/137925069/50630311-bd25-487f-871b-0a44eecd435d)
## Inpainting
This add inpainting on faces :
[inpainting.webm](https://github.com/glucauze/sd-webui-faceswaplab/assets/137925069/3d3508e9-5be4-4566-8c41-8301b2d08355)
## Build and use checkpoints :
[build.webm](https://github.com/glucauze/sd-webui-faceswaplab/assets/137925069/e84e9a3c-840d-4536-9fbb-09ed256406d7)
### Simple
1. Put a face in the reference.
2. Select a face number.
3. Select "Enable."
4. Select "CodeFormer" in **Global Post-Processing** tab.
Once you're happy with some results but want to improve, the next steps are to:
+ Use advanced settings in face units (which are not as complex as they might seem, it's basically fine tuning post-processing for each faces).
+ Use pre/post inpainting to tweak the image a bit for more natural results.
### Better
1. Put a face in the reference.
2. Select a face number.
3. Select "Enable."
4. In **Post-Processing** accordeon:
+ Select "CodeFormer"
+ Select "LDSR" or a faster model "003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN" in upscaler. See [here for a list of upscalers](https://github.com/glucauze/sd-webui-faceswaplab/discussions/29).
+ Use sharpen, color_correction and improved mask
5. Disable "CodeFormer" in **Global Post-Processing** tab (otherwise it will be applied twice)
Don't hesitate to share config in the [discussion section](https://github.com/glucauze/sd-webui-faceswaplab/discussions).
### Features
+ **Face Unit Concept**: Similar to controlNet, the program introduces the concept of a face unit. You can configure up to 10 units (3 units are the default setting) in the program settings (sd).
+ **Vladmantic and a1111 Support**
+ **Batch Processing**
+ **GPU**
+ **Inpainting Fixes** : supports “only masked” and mask inpainting.
+ **Performance Improvements**: The overall performance of the software has been enhanced.
+ **FaceSwapLab Tab**: providing various tools (build, compare, extract, batch)
+ **FaceSwapLab Settings**: FaceSwapLab settings are now part of the sd settings. To access them, navigate to the sd settings section.
+ **Face Reuse Via Checkpoints**: The FaceTools tab now allows creating checkpoints, which facilitate face reuse. When a checkpoint is used, it takes precedence over the reference image, and the reference source image is discarded.
+ **Gender Detection**: The program can now detect gender based on faces.
+ **Face Combination (Blending)**: Multiple versions of a face can be combined to enhance the swapping result. This blending happens during checkpoint creation.)
+ **Preserve Original Images**: You can opt to keep original images before the swapping process.
+ **Multiple Face Versions for Replacement**: The program allows the use of multiple versions of the same face for replacement.
+ **Face Similarity and Filtering**: You can compare faces against the reference and/or source images.
+ **Face Comparison**: face comparison feature.
+ **Face Extraction**: face extraction with or without upscaling.
+ **Improved Post-Processing**: codeformer, gfpgan, upscaling.
+ **Post Inpainting**: This feature allows the application of image-to-image inpainting specifically to faces.
+ **Upscaled Inswapper**: The program now includes an upscaled inswapper option, which improves results by incorporating upsampling, sharpness adjustment, and color correction before face is merged to the original image.
+ **API with typing support**
## Installation
See the documentation here : https://glucauze.github.io/sd-webui-faceswaplab/

@ -1,9 +1,9 @@
cython cython
ifnude
insightface==0.7.3 insightface==0.7.3
onnx>=1.14.0 onnx>=1.14.0
protobuf>=3.20.2 protobuf>=3.20.2
opencv-python opencv-python
albumentations==1.4.3
pandas pandas
pydantic pydantic
safetensors safetensors

@ -1,9 +1,9 @@
protobuf>=3.20.2 protobuf>=3.20.2
cython cython
ifnude
insightface==0.7.3 insightface==0.7.3
onnx>=1.14.0 onnx>=1.14.0
onnxruntime>=1.15.0 onnxruntime>=1.15.0
albumentations==1.4.3
opencv-python opencv-python
pandas pandas
pydantic pydantic

@ -49,7 +49,7 @@ def on_ui_settings() -> None:
shared.opts.add_option( shared.opts.add_option(
"faceswaplab_nsfw_threshold", "faceswaplab_nsfw_threshold",
shared.OptionInfo( shared.OptionInfo(
0.7, 1,
"NSFW score threshold. Any image part with a score above this value will be treated as NSFW (use extension responsibly !). 1=Disable filtering", "NSFW score threshold. Any image part with a score above this value will be treated as NSFW (use extension responsibly !). 1=Disable filtering",
gr.Slider, gr.Slider,
{"minimum": 0, "maximum": 1, "step": 0.01}, {"minimum": 0, "maximum": 1, "step": 0.01},

@ -22,7 +22,7 @@ from scripts.faceswaplab_swapping import upscaled_inswapper
from scripts.faceswaplab_swapping.upcaled_inswapper_options import InswappperOptions from scripts.faceswaplab_swapping.upcaled_inswapper_options import InswappperOptions
from scripts.faceswaplab_utils.imgutils import ( from scripts.faceswaplab_utils.imgutils import (
pil_to_cv2, pil_to_cv2,
check_against_nsfw, # check_against_nsfw,
) )
from scripts.faceswaplab_utils.faceswaplab_logging import logger, save_img_debug from scripts.faceswaplab_utils.faceswaplab_logging import logger, save_img_debug
from scripts import faceswaplab_globals from scripts import faceswaplab_globals
@ -713,8 +713,8 @@ def process_image_unit(
if unit.enable: if unit.enable:
faces = get_faces(pil_to_cv2(image)) faces = get_faces(pil_to_cv2(image))
if check_against_nsfw(image): # if check_against_nsfw(image):
return [(image, info)] # return [(image, info)]
if not unit.blend_faces and not force_blend: if not unit.blend_faces and not force_blend:
src_faces = unit.faces src_faces = unit.faces
logger.info(f"will generate {len(src_faces)} images") logger.info(f"will generate {len(src_faces)} images")

@ -13,7 +13,7 @@ from scripts.faceswaplab_utils.typing import BoxCoords, CV2ImgU8, PILImage
from scripts.faceswaplab_utils.faceswaplab_logging import logger from scripts.faceswaplab_utils.faceswaplab_logging import logger
def check_against_nsfw(img: PILImage) -> bool: #def check_against_nsfw(img: PILImage) -> bool:
""" """
Check if an image exceeds the Not Safe for Work (NSFW) score. Check if an image exceeds the Not Safe for Work (NSFW) score.
@ -22,14 +22,17 @@ def check_against_nsfw(img: PILImage) -> bool:
Returns: Returns:
bool: True if any part of the image is considered NSFW, False otherwise. bool: True if any part of the image is considered NSFW, False otherwise.
If this is hardcoded to 0.7, what the fuck does faceswaplab_settings.py do?
""" """
NSFW_SCORE_THRESHOLD = get_sd_option("faceswaplab_nsfw_threshold", 0.7) # NSFW_SCORE_THRESHOLD = get_sd_option("faceswaplab_nsfw_threshold", 0.7)
# For testing purpose : # For testing purpose :
if NSFW_SCORE_THRESHOLD >= 1: # if NSFW_SCORE_THRESHOLD >= 1:
return False # return False
"""
from ifnude import detect from ifnude import detect
shapes: List[bool] = [] shapes: List[bool] = []
@ -42,7 +45,7 @@ def check_against_nsfw(img: PILImage) -> bool:
shapes.append(chunk["score"] > NSFW_SCORE_THRESHOLD) shapes.append(chunk["score"] > NSFW_SCORE_THRESHOLD)
return any(shapes) return any(shapes)
"""
def pil_to_cv2(pil_img: PILImage) -> CV2ImgU8: def pil_to_cv2(pil_img: PILImage) -> CV2ImgU8:
""" """

Loading…
Cancel
Save