Nodes/ComfyUI-Sapiens2/Sapiens2 Body-Part Segmentation
ComfyUI Node

Sapiens2 Body-Part Segmentation

29 body parts, one labeled mask, zero effort

By kijai·Created 4 months ago·Updated 4 months ago· 65
Sapiens2 Body-Part Segmentation
  • image
  • sapiens2_model
  • class_id_mask
  • colored
frames_per_batch1

Body-part segmentation is the quiet workhorse of the Sapiens2 pack. Pointmaps get the demos, but a clean labeled mask of "which pixel is hair, which is apparel, which is skin" unlocks a pile of boring-but-profitable workflows: recoloring clothes with a masked inpaint, relighting skin while leaving clothing alone, building character-consistency masks, or just separating a person from a busy scene with a mask that knows what a hand is. Sapiens2's seg head knows 29 human-body classes - the Goliath-28 set plus an inserted Eyeglass class - which is a lot more granular than the generic "person / background" you get from a background-removal model.

How it works

Wire in an image and a SAPIENS2_MODEL from a Loader that loaded a -seg checkpoint, plus frames_per_batch (default 1, raise for video, lower if you OOM). It runs the frames at 1024×768 and argmaxes the per-class logits into per-pixel class IDs, then gives you two outputs:

  • class_id_mask (MASK) - the class label per pixel, normalized so values run from 0 to 1 (class id divided by num_classes-1). It's a real mask you can preview, blend, or threshold - but the number per pixel is the class ID, which is the whole game here.
  • colored (IMAGE) - the same segmentation rendered with the pack's 29-color palette, so you can eyeball exactly where each class landed. This is your debugging view: if the feet look wrong, the mask is wrong, and you'll see it instantly.

The 29 classes include the useful specifics: Face_Neck, Hair, Apparel, Upper_Clothing / Lower_Clothing, Torso, separate left/right hands and shoes and socks, and even Upper_Lip / Lower_Lip / Tongue for face-detail work.

What to actually do with it

The classic pattern: run seg, then extract one class with Sapiens2 Seg Extract Class and use the resulting binary mask to drive an inpaint or a control. Recolor a shirt by masking Apparel, relight a face by masking Face_Neck, swap a background by inverting Background. Pair it with a detailing workflow - the masking-detection loop where a precise polygon mask means far less visible seams than a rectangle crop.

Where people trip up: the class_id_mask values only mean something to the sibling Seg Extract node, because the normalization depends on the class count. Don't try to threshold it by "value equals 0.5" to grab a class - that's what Sapiens2SegExtract is for, and it knows the real mapping.

Installing

Manager search "ComfyUI-Sapiens2", or git clone https://github.com/kijai/ComfyUI-Sapiens2 into custom_nodes, restart. Grab a seg checkpoint from facebook/sapiens2-seg-1b (the 0.4B is a noticeable step down on hands and small clothing details) and drop it in ComfyUI/models/sapiens2. No pip dependencies; needs a recent ComfyUI since the pack uses the newer io.ComfyNode API. And if you feed this node a non-seg checkpoint, it refuses with a clear "expected 'seg'" error - the pack makes the wrong-model mistake loud, which is a gift.

CategorySapiens2

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
sapiens2_modelSAPIENS2_MODEL
frames_per_batchINT11–256Frames per forward pass. Lower if you OOM.

Outputs (2)

NameTypeDescription
class_id_maskMASK
coloredIMAGE