Nodes/CMK Flow/CMK InstantID Face Rebuild · Prepare
ComfyUI Node

CMK InstantID Face Rebuild · Prepare

Find the face, cut the crop, build the masks

By CMKFlow·Created 3 months ago·Updated 2 days ago· 6
CMK InstantID Face Rebuild · Prepare
  • TARGET IMAGE
  • SOURCE FACE
  • TARGET IMAGE
  • TARGET ROI
  • SOURCE FACE
  • INPAINT MASK
  • PASTEBACK MASK
  • REBUILD CONTEXT
  • LOG BLOCK
  • diagnostic
◄TARGET FACELargest►
◄HEAD AREA0.75►
◄NECK AREA0.40►
◄MASK FEATHER32►
◄WORKING RESOLUTION1024►
◄DETECT MODELbuffalo_l►
◄DETECT SIZE640►
◄SHAPE STRENGTH0.00►

This is the front half of a face rebuild: it detects faces in your image, picks the one you asked for, computes a generous head-and-neck region around it, cuts that region out at a work resolution, and produces the two masks the rest of the chain needs. Nothing is sampled here. It's detection, geometry and bookkeeping - and the geometry is where the quality lives.

The output that's easiest to underestimate is REBUILD CONTEXT. It's a small CMK_FACE_REBUILD bundle holding the ROI rectangle, the working size, the feather, and the face bbox. The pasteback step uses it to put the crop back exactly where it came from; without it, you're guessing.

The inputs you'll actually touch

  • TARGET IMAGE - one image, batch 1. It errors otherwise ("prototype supports exactly one target image").
  • SOURCE FACE - your reference face. Only used for the optional shape transfer and for passing through.
  • TARGET FACE - Largest (default), Leftmost, Rightmost, Topmost, Bottommost, Center. Which person you're rebuilding.
  • HEAD AREA (0.75) and NECK AREA (0.4) - multipliers that grow the crop and mask around the detected box. Push HEAD AREA up when the haircut matters; push NECK AREA up when the crop is too tight at the jaw and the blend has nowhere to hide.
  • MASK FEATHER (32px) - softness of the mask edge. High feather hides seams but lets the re-render bleed into the surrounding pixels.
  • WORKING RESOLUTION - 768, 1024 (default) or 1280. The crop is resized to this before sampling. This is the single biggest quality/cost lever in the whole chain.
  • DETECT MODEL and DETECT SIZE (640) - advanced.
  • SHAPE STRENGTH - optional, defaults to 0, tooltip: "Deform target face geometry toward dense source landmarks before FaceRebuild. 0 preserves the target shape." Experimental. The Advanced executor deliberately forces it to 0, so if you want to play with landmark warping, this node is where it lives.

Outputs

TARGET IMAGE, TARGET ROI (the crop, at working resolution), SOURCE FACE, INPAINT MASK (broader, at working size), PASTEBACK MASK (inset, full-size, head only), REBUILD CONTEXT, LOG BLOCK, diagnostic.

The two masks being different sizes is deliberate and worth internalising: the inpaint mask gives the model context around the face so the re-render isn't stitched in from nowhere, while the pasteback mask only lets the head (plus neck, if enabled at the pasteback step) overwrite the original. Broader in, narrower out.

Install

cd ComfyUI
git clone https://github.com/CMKFlow/cmk_nodes.git custom_nodes/cmk_nodes
python3 custom_nodes/cmk_nodes/scripts/install_cmk_requirements.py

Or ComfyUI Manager → search CMK Flow (registry cmk-flow) → install → restart. Manual clones don't run pip, hence the installer script; it's what pulls insightface, onnxruntime, ultralytics and the rest, and it prints CMK dependency check: OK when the imports all resolve.

Then check your face models, because this node needs one the moment you run it:

python3 custom_nodes/cmk_nodes/scripts/check_cmk_resources.py --models-root "/path/to/ComfyUI-Shared"

The detector dropdown lists whatever InsightFace packs sit under models/insightface/models - typically buffalo_l. If you're headed for InstantID proper, note that InstantID's own face analysis always loads antelopev2 by name, and that one is a manual download.

Enable Vue Nodes / Nodes 2.0 as well; CMK warns at startup when it's off and its dynamic widgets degrade without it.

Where it goes wrong

No face detected means no output. If the selector can't resolve - you asked for Rightmost and there's one person - the chain stops before you get a crop. Asking for Largest is the safe default while you're setting up.

ContentGuard runs here. The prepare path inspects the target image through CMK's local guard: NudeNet for explicit content and InsightFace for age estimation. A hard abort is possible and there's no override in the public surface. The guard is a technical risk limiter, not a consent check, and it can be wrong in both directions - but when it fires, that's what happened, so don't go hunting for a broken model download.

TARGET IMAGE is a legit passthrough of the input, so you can wire it straight into the pasteback as TARGET IMAGE and skip keeping an extra branch around for the original.

CategoryCMK/Toolbox/Face

Inputs (10)

NameTypeDefaultDescription
TARGET IMAGEIMAGE—
SOURCE FACEIMAGE—
TARGET FACECOMBOLargest6 options: Largest, Leftmost, Rightmost, Topmost, Bottommost, Center
HEAD AREAFLOAT0.750–2—
NECK AREAFLOAT0.400–2—
MASK FEATHERINT320–64—
WORKING RESOLUTIONCOMBO10243 options: 768, 1024, 1280
DETECT MODELCOMBObuffalo_l1 options: buffalo_l
DETECT SIZEINT640128–1280—
SHAPE STRENGTHoptFLOAT0.000–1Deform target face geometry toward dense source landmarks before FaceRebuild. 0 preserves the target shape.

Outputs (8)

NameTypeDescription
TARGET IMAGEIMAGE—
TARGET ROIIMAGE—
SOURCE FACEIMAGE—
INPAINT MASKMASK—
PASTEBACK MASKMASK—
REBUILD CONTEXTCMK_FACE_REBUILD—
LOG BLOCKCMK_LOG_BLOCK—
diagnosticCMK_DIAGNOSTIC—