Nodes/comfyui-instantId-faceswap/Create mask from Kps
ComfyUI Node

Create mask from Kps

Turning a handful of face points into a usable mask

By nosiu·Created 3 years ago·Updated about a year ago· 264
Create mask from Kps
  • kps_data
  • mask
grow_by4

Most masking in a face-swap workflow comes from you - you draw it, or a segmentation node draws it for you. This node exists for the one case where there's nothing to draw a mask on in the first place: you're generating a face from scratch off a set of keypoints (KPS) rather than swapping one onto an existing photo, and downstream nodes still need a MASK to know where that face is going.

What it's for

This pack, nosiu's ComfyUI implementation of InstantID, runs in two pretty different modes. Mode one is the classic face swap: give it a pose photo, draw a mask over the face, and it fills that region with a new identity. Mode two - added when the pack was rewritten from scratch to run natively on ComfyUI's own backend instead of leaning on diffusers - is generation from nothing but a face reference and a set of KPS you place by hand with the Draw KPS or 3D KPS from Image nodes. No source photo, so no mask to paint. MaskFromKps builds one directly from where you put the keypoints instead, which is what lets the "type a prompt, place some dots, get a face" workflows feed into the same downstream nodes - like Preprocess Image for InstantId - that expect a mask input regardless of which mode produced it.

Inputs and output

Two inputs, and the second one has a trap baked into it:

  • kps_data - the KPS_DATA coming out of a Draw KPS or 3D KPS node. Not an image, not a mask - the pack's own keypoint data type, so it only connects to nodes that actually output it.
  • grow_by (default 4, range 1–10) - how much padding to add around the tight bounding box of the keypoints. The math, straight from the pack's own docs: the margin added on each side equals the mask's dimension divided by grow_by. A 20-pixel-wide KPS spread with grow_by at 10 gets 2 pixels added per side. That means the slider runs backwards from what you'd guess - a higher number gives a smaller mask, not a bigger one. Want a generous mask? Turn grow_by down toward 1, not up toward 10.

One output, mask (MASK), which wires straight into anything expecting a mask - most naturally Preprocess Image for InstantId (Advanced)'s mask input.

Installing it

Same install as every node in this pack, since they all ship together: ComfyUI Manager, search comfyui-instantId-faceswap, install. By hand: cd ComfyUI/custom_nodes && git clone https://github.com/nosiu/comfyui-instantId-faceswap, then pip install -r requirements.txt inside that folder, then restart. This node itself is pure geometry - no models, nothing to download. But you'll need something to feed it, and the nodes that actually do face detection and generation elsewhere in the pack need the antelopev2 InsightFace models and the InstantID IP-Adapter/ControlNet weights fetched by hand into ComfyUI/models/insightface, ipadapter, and controlnet (or pointed at via extra_model_paths.yaml). Worth knowing up front: those InsightFace weights are non-commercial research models - fine for personal work, a real blocker if this pipeline is going behind anything you charge for.

Where people get tripped up

The grow_by direction is the genuine gotcha - it's easy to crank it up expecting a bigger mask and get a tighter one instead, because "grow by 10" reads like "grow a lot." Treat it as a divisor, not a multiplier, and it clicks immediately.

Beyond that, errors on this pack tend not to be about this node at all - they're about the model folder layout. Early adopters of this exact pack have posted fighting extra_model_paths.yaml to get InsightFace, ControlNet, and IPAdapter paths all recognized at once. If MaskFromKps itself throws, it's almost always upstream: kps_data isn't actually connected, or you've wired in the output of a node that returns a plain image or mask instead of the pack's KPS_DATA type. Check the wire before you suspect the node.

CategoryInstantId Faceswap

Inputs (2)

NameTypeDefaultDescription
kps_dataKPS_DATA
grow_byINT41–10

Outputs (1)

NameTypeDescription
maskMASK