@ -92,7 +92,7 @@ The purpose of this feature is to enhance the quality of the face in the final i
The upscaled inswapper is disabled by default. It can be enabled in the sd options. Understanding the various steps helps explain why results may be unsatisfactory and how to address this issue.
+ **upscaler** : LDSR if None. The LDSR option generally gives the best results but at the expense of a lot of computational time. You should test other models to form an opinion. The 003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN model seems to give good results in a reasonable amount of time. It's not possible to disable upscaling, but it is possible to choose LANCZOS for speed if Codeformer is enabled in the upscaled inswapper. The result is generally satisfactory.
+ **upscaler** : LDSR if None. The LDSR option generally gives the best results but at the expense of a lot of computational time. You should test other models to form an opinion. The 003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN model seems to give good results in a reasonable amount of time. It's not possible to disable upscaling, but it is possible to choose LANCZOS for speed if Codeformer is enabled in the upscaled inswapper. The result is generally satisfactory.
+ **restorer** : The face restorer to be used if necessary. Codeformer generally gives good results.
+ **sharpening** can provide more natural results, but it may also add artifacts. The same goes for **color correction**. By default, these options are set to False.
+ **improved mask:** The segmentation mask for the upscaled swapper is designed to avoid the square mask and prevent degradation of the non-face parts of the image. It is based on the Codeformer implementation. If "Use improved segmented mask (use pastenet to mask only the face)" and "upscaled inswapper" are checked in the settings, the mask will only cover the face, and will not be squared. However, depending on the image, this might introduce different types of problems such as artifacts on the border of the face.
@ -129,36 +129,36 @@ Here are the parameters that can be configured in sd settings and their default
### General Settings :
Name | Description | Default Value
Name | Description | Default Value
---|---|---
faceswaplab_model | Insightface model to use| models[0] if len(models) > 0 else "None"
faceswaplab_keep_original | keep original image before swapping. It true, will show original image | False
faceswaplab_units_count | How many faces units to use(requires restart) | 3
faceswaplab_detection_threshold | Detection threshold to use to detect face, if low will detect non human face as face | 0.5
faceswaplab_model | Insightface model to use| models[0] if len(models) > 0 else "None"
faceswaplab_keep_original | keep original image before swapping. It true, will show original image | False
faceswaplab_units_count | How many faces units to use(requires restart) | 3
faceswaplab_detection_threshold | Detection threshold to use to detect face, if low will detect non human face as face | 0.5
### Default Settings :
These parameters are used to configure the default settings displayed in post-processing.
Name | Description | Default Value
faceswaplab_pp_default_face_restorer | UI Default post processing face restorer (requires restart) | None
faceswaplab_pp_default_face_restorer_visibility | UI Default post processing face restorer visibility (requires restart) | 1
faceswaplab_pp_default_face_restorer_weight | UI Default post processing face restorer weight (requires restart) | 1
These parameters are used to control the upscaled inswapper, see above.
Name | Description | Default Value
faceswaplab_upscaled_swapper | Upscaled swapper. Applied only to the swapped faces. Apply transformations before merging with the original image | False
faceswaplab_upscaled_swapper_erosion | Upscaled swapper mask erosion factor, 1 = default behaviour. The larger it is, the more blur is applied around the face. Too large and the facial change is no longer visible | 1
Name | Description | Default Value
faceswaplab_upscaled_swapper | Upscaled swapper. Applied only to the swapped faces. Apply transformations before merging with the original image | False
faceswaplab_upscaled_swapper_erosion | Upscaled swapper mask erosion factor, 1 = default behaviour. The larger it is, the more blur is applied around the face. Too large and the facial change is no longer visible | 1
These examples show how to use a painting as a source. No post-processing is activated, only the upscaled inswapper with LDSR, Codeformer and segmented mask.
@ -46,7 +46,7 @@ The segmentation mask for the upscaled swapper is designed to avoid the square m
#### How to increase speed of upscaled inswapper?
It is possible to choose LANCZOS for speed if Codeformer is enabled in the upscaled inswapper. The result is generally satisfactory.
It is possible to choose LANCZOS for speed if Codeformer is enabled in the upscaled inswapper. The result is generally satisfactory.
#### Sharpening and color correction in upscaled swapper :
@ -56,7 +56,7 @@ Sharpening can provide more natural results, but it may also add artifacts. The
If you do not see any extensions after restarting, it is likely due to missing requirements, particularly if you're using Windows. Follow the instructions below:
1. Verify that there are no error messages in the terminal.
1. Verify that there are no error messages in the terminal.
2. Double-check the Installation section of this document to ensure all the steps have been followed.
If you are running a specific configuration (for example, Python 3.11), please test the extension with a clean installation of the stable version of Diffusion before reporting an issue. This can help isolate whether the problem is related to your specific configuration or a broader issue with the extension.
@ -65,14 +65,14 @@ If you are running a specific configuration (for example, Python 3.11), please t
The model used in this extension initially reduces the resolution of the target face before generating a 128x128 image. This means that regardless of the original image's size, the resolution of the processed faces will not exceed 128x128. Consequently, this lower resolution might lead to quality limitations in the results.
The output of this process might not meet high expectations, but the use of the face restorer and upscaler can help improve these results to some extent.
The output of this process might not meet high expectations, but the use of the face restorer and upscaler can help improve these results to some extent.
The quality of results is inherently tied to the capabilities of the model and cannot be enhanced beyond its design. FaceSwapLab merely provides an interface for the underlying model. Therefore, unless the model from insighface is retrained and necessary alterations are made in the library (see below), the resulting quality may not meet high expectations.
Consider this extension as a low-cost alternative to more sophisticated tools like Lora, or as an addition to such tools. It's important to **maintain realistic expectations of the results** provided by this extension.
#### Issue: Incorrect Gender Detection
#### Issue: Incorrect Gender Detection
The gender detection functionality is handled by the underlying analysis model. As such, there might be instances where the detected gender may not be accurate. This is a limitation of the model and we currently do not have a way to improve this accuracy from our end.
FaceSwapLab is an extension for Stable Diffusion that simplifies the use of [insighface models](https://insightface.ai/) for 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.
FaceSwapLab is an extension for Stable Diffusion that simplifies the use of [insighface models](https://insightface.ai/) for 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](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.
None,"UI Default post processing face restorer (requires restart)",gr.Dropdown,{"interactive":True,"choices":["None"]+[x.name()forxinshared.face_restorers]},section=section))
"Upscaled swapper mask erosion factor, 1 = default behaviour. The larger it is, the more blur is applied around the face. Too large and the facial change is no longer visible.",
False,"Upscaled swapper. Applied only to the swapped faces. Apply transformations before merging with the original image.",gr.Checkbox,{"interactive":True},section=section))
1,"Upscaled swapper mask erosion factor, 1 = default behaviour. The larger it is, the more blur is applied around the face. Too large and the facial change is no longer visible.",gr.Slider,{"minimum":0,"maximum":10,"step":0.001},section=section))
logger.error("Loading of swapping model failed, please check the requirements (On Windows, download and install Visual Studio. During the install, make sure to include the Python and C++ packages.)")
exceptExceptionase:
logger.error(
"Loading of swapping model failed, please check the requirements (On Windows, download and install Visual Studio. During the install, make sure to include the Python and C++ packages.)"
)
raiseFaceModelException("Loading of swapping model failed")
logger.error("Loading of swapping model failed, please check the requirements (On Windows, download and install Visual Studio. During the install, make sure to include the Python and C++ packages.)")
"Loading of swapping model failed, please check the requirements (On Windows, download and install Visual Studio. During the install, make sure to include the Python and C++ packages.)"
),"If len(faces)>0, the blended embedding should not be the same than the first image"
assertnotnp.array_equal(blended.embedding,faces[0].embedding)iflen(faces)>1elseTrue,"If len(faces)>0, the blended embedding should not be the same than the first image"
assert(notnp.array_equal(unit.reference_face.embedding,src_faces[0].embedding)iflen(unit.faces)>1elseTrue),"Reference face cannot be the same as blended"
assert(all([notnp.array_equal(self._blended_faces.embedding,face.embedding)forfaceinself.faces])iflen(self.faces)>1elseTrue),"Blended faces cannot be the same as one of the face if len(face)>0"
assert(notnp.array_equal(self._blended_faces.embedding,self.reference_face.embedding)iflen(self.faces)>1elseTrue),"Blended faces cannot be the same as reference face if len(face)>0"
assert(
all(
[
notnp.array_equal(
self._blended_faces.embedding,face.embedding
)
forfaceinself.faces
]
)
iflen(self.faces)>1
elseTrue
),"Blended faces cannot be the same as one of the face if len(face)>0"
label="Denoising strenght (will send face to img2img after processing)",
)
inpainting_denoising_prompt=gr.Textbox("Portrait of a [gender]",elem_id="faceswaplab_pp_inpainting_denoising_prompt",label="Inpainting prompt use [gender] instead of men or woman")
inpainting_denoising_negative_prompt=gr.Textbox("",elem_id="faceswaplab_pp_inpainting_denoising_neg_prompt",label="Inpainting negative prompt use [gender] instead of men or woman")
inpaiting_model=gr.Dropdown(choices=["Current"]+sd_models.checkpoint_tiles(),default="Current",label="sd model (experimental)",elem_id="faceswaplab_pp_inpainting_sd_model")