CMK InstantID Face Rebuild · Prepare
Find the face, cut the crop, build the masks
- TARGET IMAGE
- SOURCE FACE
- TARGET IMAGE
- TARGET ROI
- SOURCE FACE
- INPAINT MASK
- PASTEBACK MASK
- REBUILD CONTEXT
- LOG BLOCK
- diagnostic
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) andNECK AREA(0.4) - multipliers that grow the crop and mask around the detected box. PushHEAD AREAup when the haircut matters; pushNECK AREAup 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) or1280. The crop is resized to this before sampling. This is the single biggest quality/cost lever in the whole chain.DETECT MODELandDETECT 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.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| TARGET IMAGE | IMAGE | — | |
| SOURCE FACE | IMAGE | — | |
| TARGET FACE | COMBO | Largest | 6 options: Largest, Leftmost, Rightmost, Topmost, Bottommost, Center |
| HEAD AREA | FLOAT | 0.750–2 | — |
| NECK AREA | FLOAT | 0.400–2 | — |
| MASK FEATHER | INT | 320–64 | — |
| WORKING RESOLUTION | COMBO | 1024 | 3 options: 768, 1024, 1280 |
| DETECT MODEL | COMBO | buffalo_l | 1 options: buffalo_l |
| DETECT SIZE | INT | 640128–1280 | — |
| SHAPE STRENGTHopt | FLOAT | 0.000–1 | Deform target face geometry toward dense source landmarks before FaceRebuild. 0 preserves the target shape. |
Outputs (8)
| Name | Type | Description |
|---|---|---|
| TARGET IMAGE | IMAGE | — |
| TARGET ROI | IMAGE | — |
| SOURCE FACE | IMAGE | — |
| INPAINT MASK | MASK | — |
| PASTEBACK MASK | MASK | — |
| REBUILD CONTEXT | CMK_FACE_REBUILD | — |
| LOG BLOCK | CMK_LOG_BLOCK | — |
| diagnostic | CMK_DIAGNOSTIC | — |