Nodes/CMK Flow/CMK FaceSwap Image
ComfyUI Node

CMK FaceSwap Image

Inswapper_128 Is 128px Wide, and That's the Whole Story

By CMKFlow·Created 3 months ago·Updated a day ago· 6
CMK FaceSwap Image
  • target_image
  • source_image
  • opt_selected_target_face
  • opt_selected_source_face
  • image
  • diagnostic
◄enabledtrue►
◄swap_model▾►
◄detector_model▾►
◄face_enhancerOff►
◄target_selectionLargest►
◄source_selectionLargest►
◄blend1.00►
◄bbox_dilation0►
◄crop_factor1.5►
◄drop_size10►
◄feather0►

Every face swap in this ecosystem descends from the same frozen ONNX file, and that file has been 128×128 for years. Understanding that one number explains why CMK FaceSwap Image has a "face_enhancer" dropdown at all, and why almost every default in the node is a compromise.

What it is

A post-process swap: the image already exists, this node replaces one face in it with another face, pixel by pixel. That's a different job from identity tools like IP-Adapter FaceID, InstantID or PuLID, which guide the diffusion model while it generates. Generation-side identity gets you a face that resembles the reference; a swap gets you the reference. In practice people stack them - a generation-side tool gets you 80% of the way and a swap finishes the job - and that's exactly where this node sits.

It's the standalone version. No -Pipe- suffix means you can drop it into any graph with two images and no CMK process state.

How it works

Both faces go through InsightFace: detect, align to the five landmarks, embed. The target face's landmarks define an affine alignment into the swapper's 128×128 input; the source face's ArcFace embedding is projected through the swapper's latent map and decoded into a 128×128 patch, which is then warped back onto the target according to crop_factor and pasted with blend and feather doing the compositing.

Because the patch is born at 128px, a straight paste onto a 1024px face is soft. face_enhancer is the escape hatch: set it to GPEN and the patch gets a restore pass (an ONNX model from your facerestore_models folder) before it's pasted. Off vs GPEN is the single biggest visual difference in this node.

Also worth flagging before you build on it: this pack's public swap paths run a mandatory ContentGuard. It checks source and target locally with NudeNet and InsightFace age estimation, refuses a source face estimated under 25, and fails hard with a diagnostic code. There's no bypass switch in the UI. It's a technical risk limiter, not a consent check, and it will occasionally misfire on stylised faces.

The knobs you'll actually touch

  • swap_model - discovered from .onnx files in ComfyUI/models/insightface, its reswapper and hyperswap folders. inswapper_128.onnx is the default and the one everybody has; the pack also ships adapters for ReSwapper's 128/256 and FaceSwap HyperSwap 256 builds, which is genuinely nice because those are drop-in replacements.
  • target_selection / source_selection - Largest / Leftmost / Rightmost / Topmost / Bottommost / Center. If the wrong person gets swapped, this is the first thing you change.
  • blend - a straight lerp between original and result. 1.0 is "trust the swap"; 0.6 lands swaps that are fighting the lighting.
  • face_enhancer - Off or GPEN. Start with Off to see what the swap alone looks like, then turn GPEN on.
  • enabled - false is a genuine pass-through. The node returns the target unchanged and skips detection and source loading, so you can leave it wired and switched off.

The advanced four - bbox_dilation, crop_factor, drop_size, feather - are worth one run each. drop_size is the minimum face box in pixels: raise it and the detector stops picking up faces in the background. crop_factor 1.5 is fine; lower it and you get tighter, harder edges, higher and you get context bleed.

opt_selected_target_face and opt_selected_source_face take a CMK_SELECTED_FACE from CMK Face Select. Connect those and this node stops detecting on its own - you'll see "Target Source: Input" in the log.

Outputs

image is the swapped batch, same size as the target. diagnostic is a seven-stage comparison payload (target, source, both detection passes, result, difference, final) with a changed_avg metric - the difference image is the honest one. If changed_avg is near zero, your swap did nothing and no amount of blend tuning will fix it.

Install

ComfyUI Manager, search CMK Flow, install the CMKFlow entry, restart. Manually:

git clone https://github.com/CMKFlow/cmk_nodes.git custom_nodes/cmk_nodes
python3 custom_nodes/cmk_nodes/scripts/install_cmk_requirements.py
python3 custom_nodes/cmk_nodes/scripts/check_cmk_resources.py --models-root "/path/to/ComfyUI-Shared"

The resource checker knows about the FaceSwap, InsightFace and GPEN files and can fetch them per item with confirmation. None of them ship in the Python package.

Where people get burned

The 128px ceiling, first and always: if you skip GPEN expect mush at high resolution, and if you use GPEN too hard expect that characteristic over-smooth "installed a new face" look.

Second, the batch alignment. When target and source batch sizes differ, source frames are indexed with min(i, source_count - 1) - the last source frame gets reused. A 1-frame source over a 100-frame target is therefore legal and does what you'd hope.

Third, licensing. The InsightFace library is MIT; the pretrained models are not, and inswapper is research-only. Fine for local experimenting, a real problem the day you want to sell output.

CategoryCMK/Toolbox/Face

Inputs (15)

NameTypeDefaultDescription
target_imageIMAGE—
source_imageIMAGE—
enabledBOOLEANtrue—
swap_modelCOMBO1 options: inswapper_128.onnx
detector_modelCOMBO1 options: buffalo_l
face_enhancerCOMBOOff2 options: Off, GPEN
target_selectionCOMBOLargest6 options: Largest, Leftmost, Rightmost, Topmost, Bottommost, Center
source_selectionCOMBOLargest6 options: Largest, Leftmost, Rightmost, Topmost, Bottommost, Center
blendFLOAT1.000–1—
bbox_dilationINT0-512–512—
crop_factorFLOAT1.51–3—
drop_sizeINT101–8192—
featherINT00–100—
opt_selected_target_faceoptCMK_SELECTED_FACE—
opt_selected_source_faceoptCMK_SELECTED_FACE—

Outputs (2)

NameTypeDescription
imageIMAGE—
diagnosticCMK_DIAGNOSTIC—