Face Editor for Stable Diffusion. This Extension is useful for the following purposes:
This is a extension of AUTOMATIC1111's Stable Diffusion Web UI. If you are using SD.Next, use the sd.next branch.
If you feel uncomfortable with the facial contours, try increasing the "Mask size" value. This discomfort often occurs when the face is not facing straight ahead.
If the forelock interferes with rendering the face properly, generally, selecting "Hair" from "Affected areas" results in a more natural image.
This setting modifies the mask area as illustrated below:
When multiple faces are close together, one face may collapse under the influence of the other. In such cases, enable "Use minimal area (for close faces)".
Use "Prompt for face" option if you want to change the facial expression.
Faces can be individually directed with prompts separated by ||
(two vertical lines).
@@
, the normal prompts (written at the top of the screen) will be expanded at that position.__name__
syntax and the text file in the directory of the wildcards extension as well as the normal prompts.If you wish to modify the face of an already existing image instead of creating a new one, follow these steps:
0
. This setting is good for preventing changes to areas other than the faces and for reducing processing time.This script performs the following steps:
First, image(s) are generated as usual according to prompts and other settings. This script acts as a post-processor for those images.
Select a workflow. "Search workflows in subdirectories" can be enabled in the Face Editor section of the "Settings" tab to try some experimental workflows. You can also add your own workflows.
For more detailed information, please refer to the Workflow Editor section.
When pasting the generated image to its original location, the rectangle of the detected face area is used. If this option is not enabled, the generated image itself is pasted. In other words, enabling this option applies a smaller face image, while disabling it applies a larger face image.
This option allows you to save the original, unmodified image.
This option allows you to display the original, unmodified image.
This option enables the display of images that depict detected faces and masks. If the generated image is unnatural, enabling it may reveal the cause.
Prompt for generating a new face. If this parameter is not specified, the prompt entered at the top of the screen is used.
For more information, please see: here.
Size of the mask area when inpainting to blend the new face with the whole image.
Size of the blur area when inpainting to blend the new face with the whole image.
Use this parameter when you want to reduce the number of faces to be detected. If more faces are found than the number set here, the smaller faces will be ignored.
Confidence threshold for face detection. Set a lower value if you want to detect more faces.
Specify the size of the margin for face cropping by magnification.
If other parameters are exactly the same but this value is different, the atmosphere of the new face created will be different.
Specifies one side of the image size when creating a face image. If you are using the SDXL model, we recommend changing to 1024. For other models, there is usually no need to change from the default value (512), but you may see interesting changes if you do.
Ignore if the size of the detected face is larger than the size specified in "Size of the face when recreating".
For more information, please see: here.
Select the upscaler to be used to scale the face image.
Denoising strength for generating a new face. If the value is too small, facial collapse cannot be corrected, but if it is too large, it is difficult to blend with the entire image.
This option defines the angle, in degrees, above which tilt correction will be automatically applied to detected faces. For instance, if set to 20, any face detected with a tilt greater than 20 degrees will be adjusted. However, if the "Adjust tilt for detected faces" option in the Face Editor section of the "Settings" tab is enabled, tilt correction will always be applied, regardless of the tilt adjustment threshold value.
Paste an image cut out in the shape of a face instead of a square image.
For more information, please see: here.
Denoising strength when inpainting to blend the new face with the whole image. If the border lines are too prominent, increase this value.
If you want to use this script as an extension (alwayson_scripts) in the API, specify "face editor ex" as the script name as follows:
"alwayson_scripts": {
"face editor ex": {
"args": [{"prompt_for_face": "smile"}]
},
By specifying an object as the first argument of args as above, parameters can be specified by keywords. We recommend this approach as it can minimize the impact of modifications to the software. If you use a script instead of an extension, you can also specify parameters in the same way as follows:
"script_name": "face editor",
"script_args": [{"prompt_for_face": "smile"}],
Workflow Editor is where you can customize and experiment with various options beyond just the standard settings.
This project includes several example workflows to help you get started. Each example provides a JSON definition for a specific use case, which can be used as is or customized to suit your needs. To access these example workflows from the Workflow Editor, you need to enable the "Search workflows in subdirectories" option located in the Face Editor section of the "Settings" tab.
For more details about these example workflows and how to use them, please visit the workflows/examples/README.md.
In this project, the components used in the workflow are also referred to as "inferencers". These inferencers are part of the process that modifies the faces in the generated images:
The "General components" provide the basic functionalities for these categories, and they can be used without the need for additional software installations. On the other hand, each functionality can also be achieved by different technologies or methods, which are categorized here as "Additional components". These "Additional components" provide more advanced or specialized ways to perform the tasks of face detection, face processing, and mask generation.
In this project, the components used in the workflow are also referred to as "inferencers". These inferencers fall into three functional categories: Face Detectors, Face Processors, and Mask Generators.
Note: When using "Additional components", ensure that the features you want to use are enabled in the "Additional Components" section of the "Settings" tab under "Face Editor". For detailed descriptions and usage of each component, please refer to the corresponding README.
face_detector
(string or object, required): The face detector component to be used in the workflow.
name
of the face detector implementation.name
(string, required): The name of the face detector implementation.params
(object, optional): Parameters for the component, represented as key-value pairs.rules
(array or object, required): One or more rules to be applied.
when
and then
:when
(object, optional): The condition for the rule.
tag
(string, optional): A tag corresponding to the type of face detected by the face detector. This tag can optionally include a query following the tag name, separated by a '?'. This query is a complex condition that defines attribute-value comparisons using operators. The query can combine multiple comparisons using logical operators. For example, a tag could be "face?age<30&gender=M", which means that the tag name is "face" and the query is "age<30&gender=M". The query indicates that the rule should apply to faces that are identified as male and are less than 30 years old.=
: Checks if the attribute is equal to the value.<
: Checks if the attribute is less than the value.>
: Checks if the attribute is greater than the value.<=
: Checks if the attribute is less than or equal to the value.>=
: Checks if the attribute is greater than or equal to the value.!=
: Checks if the attribute is not equal to the value.~=
: Checks if the attribute value contains the value.*=
: Checks if the attribute value starts with the value.=*
: Checks if the attribute value ends with the value.~*
: Checks if the attribute value does not contain the value.&
: Represents logical AND.|
: Represents logical OR.criteria
(string, optional): This determines which faces will be processed, based on their position or size. Available options for position include 'left', 'right', 'center', 'top', 'middle', 'bottom'. For size, 'small', 'large' are available. The selection of faces to be processed that match the specified criteria can be defined in this string, following the pattern {position/size}:{index range}
. The {index range}
can be a single index, a range of indices, or a combination of these separated by a comma. For example, specifying left:0 will process the face that is located the most to the left on the screen. left:0-2 will process the three faces that are the most left, and left:0,2,5 will process the most left face, the third from the left, and the sixth from the left. If left is specified without an index or range, it will default to processing the face most left in the frame. Essentially, this is the same as specifying left:0.then
(object or array of objects, required): The job or list of jobs to be executed if the when
condition is met.
face_processor
(object or string, required): The face processor component to be used in the job.
name
of the face processor implementation.name
(string, required): The name of the face processor implementation.params
(object, optional): Parameters for the component, represented as key-value pairs.mask_generator
(object or string, required): The mask generator component to be used in the job.
name
of the mask generator implementation.name
(string, required): The name of the mask generator implementation.params
(object, optional): Parameters for the component, represented as key-value pairs.Rules are processed in the order they are specified. Once a face is processed by a rule, it will not be processed by subsequent rules. The last rule can be specified with then
only (i.e., without when
), which will process all faces that have not been processed by previous rules.
In the "Face Editor" section of the "Settings" tab, the following settings can be configured.
Overview
"Search workflows in subdirectories" is a setting option that controls whether Face Editor includes subdirectories in its workflow search.
Value and Impact
The value is a boolean, with either True
or False
to be specified. The default value is False
, which indicates that the search does not include subdirectories. When set to True
, the workflow search extends into subdirectories, allowing for the reference of sample workflows.
Overview
"Additional components" is a setting option that specifies the additional components available for use in Face Editor.
Value and Impact
This setting is a series of checkboxes labeled with component names. Checking a box (setting to Enabled) activates the corresponding component in Face Editor.
Overview
"Save original image if face detection fails" is a setting option that specifies whether to save the original image if face detection fails.
Value and Impact
The value is a boolean, with either True
or False
to be specified. The default value is True
, which means that the original image will be saved if face detection fails.
Overview
"Adjust tilt for detected faces" is a setting option that specifies whether to adjust the tilt for detected faces.
Value and Impact
The value is a boolean, with either True
or False
to be specified. The default value is False
, indicating that no tilt correction will be applied when a face is detected. Even when "Adjust tilt for detected faces" is not enabled, the tilt correction may still be applied based on the "Tilt adjustment threshold" setting.
Overview
"Auto face size adjustment by model" is a setting option that determines whether the Face Editor automatically adjusts the size of the face based on the selected model.
Value and Impact
The setting is a checkbox. When checked (enabled):
Overview
"The position in postprocess at which this script will be executed" is a setting option that specifies the position at which this script will be executed during postprocessing.
Value and Impact
The value is an integer, with a value from 0 to 99 to be specified. A smaller value means that the script will be executed earlier. The default value is 99
, which indicates that this script will likely be executed last during postprocessing.
We warmly welcome contributions to this project! If you're someone who is interested in machine learning, face processing, or just passionate about open-source, we'd love for you to contribute.
FaceDetector
, FaceProcessor
, and MaskGenerator
: If you have alternative approaches or models for any of these components, we'd be thrilled to include your contributions in our project.Before starting your contribution, please make sure to check out our existing code base and follow the general structure. If you have any questions, don't hesitate to open an issue. We appreciate your understanding and cooperation.
We're excited to see your contributions and are always here to help or provide guidance if needed. Happy coding!