nosiu / comfyui-instantId-faceswap

Implementation of faceswap based on InstantID for ComfyUI.
Apache License 2.0
162 stars 14 forks source link
ai comfyui instantid python

ComfyUI InstantID Faceswapper v0.0.5

About | Installation guide | Custom nodes | Workflows | Workflow script | Tips | Changelog

Implementation of faceswap based on InstantID for ComfyUI. \ Allows usage of LCM Lora which can produce good results in only a few generation steps.
Works ONLY with SDXL checkpoints.

image image

Installation guide

About | Installation guide | Custom nodes | Workflows | Workflow script | Tips | Changelog

  1. Clone or download this repository and put it into ComfyUI/custom_nodes
  2. Open commandline in the ComfyUI/custom_nodes/comfyui-instantId-faceswap/ folder and type pip install -r requirements.txt to install dependencies
  3. Manually download required files and create required folders:

    • antelopev2 models and put them into ComfyUI/models/insightface/models/antelopev2 folder

      • 1k3d68.onnx
      • 2d106det.onnx
      • genderage.onnx
      • glintr100.onnx
      • scrfd_10g_bnkps.onnx
    • IpAdapter and ControlNet

      • ip-adapter.bin - put it into ComfyUI/models/ipadapter
      • ControlNetModel/diffusion_pytorch_model.safetensors - put it into ComfyUI/models/controlnet/ControlNetModel
      • ControlNetModel/config.json - put it into ComfyUI/models/controlnet/ControlNetModel
    • LCM Lora *Optional (but higly recomended)

      • pytorch_lora_weights.safetensors - put it into ComfyUI/models/loras

Newly added files hierarchy should look like this:

ComfyUI
\---models
    \---ipadapter
           ipadapter.bin
    \---controlnet
        \---ControlNetModel
              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', 'controlnet', and 'lora' folders to this specific location if you already have them somewhere else. Instead, You can edit ComfyUI/extra_model_paths.yaml and add folders containing those files to the config.

Custom nodes

About | Installation guide | Custom nodes | Workflows | Workflow script | Tips | Changelog

Faceswap LCM Lora

params:

Faceswap setup

Loads everything and sets up the pipeline \ params:

Faceswap face embed

Prepares face embeds for the generation, you can chain face embeds to improve results \ params:

Faceswap generate

Generates new face from input Image based on input mask \ params:

Workflows

About | Installation guide | Custom nodes | Workflows | Workflow script | Tips | Changelog

You can find example workflows in the /workflows folder.

Workflow script (beta)

About | Installation guide | Custom nodes | Workflows | Workflow script | Tips | Changelog

The simple script, workflow_generate.py, can generate workflows based on the face images contained in a specific folder. The script will automatically generate appropriate nodes and connect them together. Keep in mind that there is no validation to check if there is a face in the image.

You can copy the workflow_generate.py script anywhere you want for easier access; it has no dependencies inside the custom_node.

Only files with extensions: jpg, jpeg, bmp, png, gif, webp, and jiff will be included in the workflow.

The script will not upload reference images into the ComfyUI/input folder. As a result, you won't be able to preview those images.

If you move, rename, delete image files, or modify paths in any way, the workflow will stop working.

You may see warnings (errors) in the console while loading generated workflows, ignore those.

Usage

arguments:

Example

This command will generate 'albert.json' workflow, which should include all the required nodes for face reference images in the 'C:\Users\Admin\Desktop\ALBERT' folder.

workflow_generate.py C:\Users\Admin\Desktop\ALBERT albert

image

Tips

About | Installation guide | Custom nodes | Workflows | Workflow script | Tips | Changelog

Changelog

About | Installation guide | Custom nodes | Workflows | Workflow script | Tips | Changelog