Unlock High-Fidelity Face Swapping with Shape Matching Workflow

CN
ComfyUI.org
2025-05-26 13:43:16

1. Workflow Overview

mb550qt57s1jbzh1ke38825b7de548c6a18e41a14d54cf0cb66f1eee24fbc22b44e928ea027058415df.gif

This workflow achieves high-fidelity face swapping with shape matching through:

  1. InstantID Technology: Preserves facial features while replacing targets

  2. FLUX Model Enhancement: Improves skin details & resolution

  3. Dynamic Mask System: Precise fusion boundary control

  4. Color Matching: Ensures natural skin tone transitions

Core Models:

  • DreamShaper XL v2.1 Turbo: Base generation

  • FLUX Accelerator LoRA: Speed/quality booster

  • InstantID ControlNet: Facial feature binding

  • RMBG-1.4: Background removal

2. Components Breakdown

Key Nodes:

  1. InstantID Trio

    • InstantIDModelLoader: Loads ip-adapter_instant_id_sdxl

    • ApplyInstantID: Performs face feature injection

    • Install: Requires ComfyUI_InstantID plugin

  2. Dynamic Mask Chain

    • MaskFastGrow×3: Progressive mask expansion (params: 16/4 → 32/8 → -32/8)

    • MaskComposite: Final synthesis (mode: subtract)

  3. Face Shape Matching

    • CropFaces: Extracts face regions (scale factor 1.2)

    • WarpFacesBack: Reintegrates processed faces

  4. Dependencies:

    • Must download control_instant_id_sdxl.safetensors

    • Recommended: retinaface_resnet50 face detector

3. Workflow Structure

Group Logic:

  • Group 1: InstantID Face Swap

    • Input: Source face + Target portrait

    • Key Nodes: ApplyInstantID + ControlNet

    • Output: Feature-fused latent

  • Group 2: FLUX Refinement

    • Uses FLUX.1-Turbo-Alpha LoRA

    • Sampler: Euler+SGM Uniform

    • Output: 2048x2048 HD face

  • Group 3: Dynamic Masking

    • 3-stage mask growth → Composite → Edge softening

    • Visualizer: MaskPreview+

  • Group 4: Color Matching

    • easy imageColorMatch: ADAIN algorithm

    • Preserves original lighting

4. Inputs & Outputs

Input Parameters:

  • Required:

    • Face image (658x877 PNG)

    • Target image (1780x2048 PNG)

  • Optional:

    • Prompt: "woman" (customizable)

    • Mask expansion (default: 72px)

Outputs:

  • Final Image:

    • Resolution: Original + Super-res

    • Includes: Face comparison slider

  • Intermediate:

    • White-background separation (SplitImageWithAlpha)

    • Mask previews

5. Notes

  • Hardware:

    • Min: RTX 3060 12GB

    • Recommended: RTX 4090 24GB (for 2048x2048)

  • Troubleshooting:

    • Face detection failed:
      → Adjust DetectFaces threshold (default 0.5)
      → Ensure face occupies >15% area

  • Optimization:

    1. Reduce KSampler steps (default 10→8)

    2. Use PurgeVRAM to free memory

    3. Disable live preview for batch processing