Implementation of a/faceswap based on a/InstantID for ComfyUI. Allows usage of a/LCM Lora which can produce good results in only a few generation steps. NOTE:Works ONLY with SDXL checkpoints.
<sub>About | Installation guide | Custom nodes | Workflows | Tips | Changelog</sub>
Implementation of faceswap based on InstantID for ComfyUI. </br> Works ONLY with SDXL checkpoints </br> </br>
<sub>About | Installation guide | Custom nodes | Workflows | Tips | Changelog</sub>
pip install -r requirements.txt
to install dependenciesantelopev2 models and put them into ComfyUI/models/insightface/models/antelopev2 folder
Newly added files hierarchy should look like this:
ComfyUI
\---models
\---ipadapter
ipadapter.bin
\---controlnet
\--- FOLDER_YOU_CREATED
config.json
diffusion_pytorch_model.safetensors
\---insightface
\---models
\antelopev2
1k3d68.onnx
2d106det.onnx
genderage.onnx
glintr100.onnx
scrfd_10g_bnkps.onnx
*Note You don't need to add the 'ipadapter', and 'controlnet' folders to this specific location if you already have them somewhere else (also you can rename ipadapter.bin and ControlNetModel to something of your liking).
Instead, You can edit ComfyUI/extra_model_paths.yaml
and add folders containing those files to the config.
<sub>About | Installation guide | Custom nodes | Workflows | Tips | Changelog</sub>
Loads Insightface. Models need to be in a specific location. Check the Installation guide for details.
Loads the InstantId adapter and resampler. The model needs to be in a specific location. Check the Installation guide for details. The resampler is used to prepare face embeds for ControlNet and the adapter.
Applies the InstantId adapter to the model. This is optional—you can achieve good results without using this node.
Params:
Applies InstantId ControlNet.
Params:
A subgraph node that bundles several operations into a single node for convenience. It includes the following nodes: LoadInstantIdAdapter, FaceEmbedCombine, ControlNetLoader, InstantIdAdapterApply, and ControlNetInstantIdApply.
This node streamlines the process by loading the InstantId adapter, combining face embeddings, loading the ControlNet, and applying both the InstantId adapter and ControlNet in one step.
Prepares face embeds for generation. You can chain multiple face embeds.
Params:
Prepares face embeds for ControlNet and the adapter.
Params:
Returns the angle (in degrees) by which the image must be rotated counterclockwise to align the face. Since there can be more than one face in the image, face search is performed only in the area of the drawn mask, enlarged by the pad parameter.
Note: If the face is rotated by an extreme angle, insightface won't be able to find the correct position of face keypoints, so the rotation angle might not always be accurate. In these cases, manually draw your own KPS.
Params:
Rotates the image by the given angle and expands it.
Params:
Removes the expanded region added by two rotations (first to align the face, and second to return to the original position).
Params:
Allows you to draw your own keypoints (KPS), useful when you get the error "No face detected in pose image"
or when using InstantId to generate images from prompts only. Click and drag the KPS to move them around.
When you place your KPS in the desired position, this node will show the angle by which the image should be rotated to align the face.
Shortcuts:
CTRL + DRAG - move around
CTRL + WHEEL - zoom in / out
ALT + WHEEL - decrease / increase distance of other points from blue point (nose kps)
Params:
image_reference
is provided)image_reference
is provided)Cuts out the mask area wrapped in a square, enlarges it in each direction by the pad
parameter, and resizes it (to dimensions rounded down to multiples of 8). It also creates a control image for InstantId ControlNet.
Note: If the face is rotated by an extreme angle, the prepared control_image
may be drawn incorrectly.
If the insightface
param is not provided, it will not create a control image, and you can use this node as a regular node for inpainting (to cut the masked region with padding and later compose it).
Params:
resize_mode
)resize_mode
width
x height
.
For SDXL, you probably want to use this option with:
width: 1024, height: 1024height
and calculates it based on the aspect ratiowidth
and calculates it based on the aspect ratiowidth
and height
Same as Preprocess Image for InstantId with five additional parameters.
Params:
<sub>About | Installation guide | Custom nodes | Workflows | Tips | Changelog</sub>
You can find example workflows in the /workflows
folder.
Nodes colors legend:
yellow - node from this extension,
blue - inputs, load your controlnets, models, images ...
purple - you might want to configure those
cyan - output images
green - positive prompts
red - negative prompts
If you set the mask blur options remember that it will shrink the area you masked
Face swap: Set your pose image, draw a mask, set your face reference (the face that will replace the masked area in the pose image), and that's it.
Same as simple.json
with an additional node Apply instantId adapter
Same as simple.json
, but allows you to provide two face references. You can use this to merge two different faces or just provide a second reference for the first face.
Face swap: Set your pose image, draw a mask, set your face reference (the face that will replace the masked area in the pose image), and then click the "draw KPS" button on the Draw KPS
node to set your KPS.
Same as draw_kps.json
, but it will also rotate the pose image. After setting your KPS, you should set the angle by which you want to rotate the image to align the face properly.
Same as simple_with_adapter.json
, but it will automatically detect the angle of rotation based on the mask and padding set in the Get Angle from Face
node.
Generates an image based only on the face reference and prompts. Set your face reference, draw the KPS where the face should be drawn, and add prompts like "man sitting in the park."
Same as prompt2image.json
, but this one expects the KPS you draw to be very small, so the face is not detailed (or may even be deformed). Draw a mask on the Draw KPS
node (on the KPS and surrounding area), and it will perform the face swap in that region.
A workflow that generates two faces in one image and enhances them one by one. Set your face references and KPS for one image, then set a second KPS in another region of the picture. Afterward, mask both KPS. Good results depend on your prompts.
<details> <summary>View Example Image</summary> </details>Since you can use the Preprocess Image for InstantId
and Preprocess Image for InstantId (Advanced)
nodes to resize your images with a mask, this workflow is useful for inpainting in general. This workflow shows you how to do it.
<sub>About | Installation guide | Custom nodes | Workflows | Tips | Changelog</sub>
No face detected in pose image
, try drawing a larger mask or increasing the pad
parameter or draw KPS yourself.<sub>About | Installation guide | Custom nodes | Workflows | Tips | Changelog</sub>
Note: Old workflows will not work with this version.
mask_strength
parameter has been fixed; it now functions correctly. Previously, it was stuck at 0.9999 regardless of the chosen value.ip_adapter_scale
parameter has been fixed. If you were using the xformers, this parameter could be stuck at 50.rotate_face
parameter. It will attempt to rotate the image to keep the face straight before processing and rotate it back to the original position afterward.--fp16-vae
argument to disable the default VAE upcasting to float32.resize
and resize_to
options into just resize
for the Faceswap generate node. To emulate the old behavior where resize was unchecked, select don't
.mask_strength
to range from 0.00 to 1.00.pip install -r requirements.txt
or
pip install -U diffusers~=0.26.0