Nodes/ComfyUI-Sapiens2-Easy/Sapiens2 Segmentation Advanced
ComfyUI Node

Sapiens2 Segmentation Advanced

Segmentation With the Training Wheels Off

By Bogyie·Created 4 months ago·Updated 4 months ago· 29
Sapiens2 Segmentation Advanced
  • model
  • image
  • mask
  • preview
  • foreground_mask
  • merged_mask
  • masks
  • labels
  • result
overlay_opacity0.55
preserve_backgroundfalse
invertfalse
parts

The easy Sapiens2 Segmentation node gives you a person mask in three clicks. This is the same model with the instrument panel exposed - the version you reach for when you need to control the preview, constrain where segmentation runs, and poke at the raw results. Same 29-class label set (28 foreground body parts plus background), same per-pixel classification, but six outputs and three extra controls.

How it works

Identical engine to the easy node: the Sapiens2 seg model assigns every pixel a class id, parts selects which classes matter, and everything merges into masks. The Advanced difference is where you can inject constraints and pull out internals:

  • mask (optional) - an input mask that limits where segmentation applies. Hand the node the output of an earlier mask and it multiplies its segmentation by it, so you can say "segment within this region only." This is the control the easy node lacks, and it's how you restrict a person mask to a pre-cropped or pre-masked area.
  • preserve_background - only does anything when you've wired a mask. It decides what happens to the area outside that mask: off (the default) means that region goes black, on means the original photo shows through. Flip it on when you want the subject classified but the scene visible around it.
  • overlay_opacity - how transparent the colored part overlay in preview is. Purely cosmetic, default 0.55.

The inputs that matter

Honestly, for most jobs the only new ones worth touching are mask (when you want to constrain the region) and overlay_opacity (when the preview is too noisy to read). parts and invert work exactly like the easy node - parts empty means all foreground parts, and the visual row UI accepts things like Face / all or Arm / left lower.

The outputs

  • preview - the part overlay at your chosen opacity.
  • foreground_mask - a clean person/foreground mask from the inference itself, before any part merging. If you only need "subject vs. background," grab this one.
  • merged_mask - the merged selection mask, the usual thing to wire downstream into the normal and pointmap nodes.
  • masks - per-part mask batch for the selected parts.
  • labels - a SAPIENS2_LABELS object with class ids mapped to part names/groups.
  • result - a SAPIENS2_RESULT carrying the raw data, including masked_class_ids (the class map after your input mask was applied) and selected_part_ids. This is the "I'm building a graph that inspects internals" output; you can ignore it for plain masking.

Installing it

It's part of Bogyie/ComfyUI-Sapiens2-Easy:

cd ComfyUI/custom_nodes
git clone https://github.com/Bogyie/ComfyUI-Sapiens2-Easy.git
cd ComfyUI-Sapiens2-Easy
python install.py

Restart ComfyUI, or install via ComfyUI Manager. It takes the same SAPIENS2_MODEL from a loader with task = segmentation (first-run weight download, and it's a big one - start on 0.4b/0.8b).

Where people get burned

The biggest trap is treating this as a better version of the easy node and reaching for it everywhere. It isn't - for "cut the person out," the easy node is less to configure and does the same job. This node earns its keep when you're chaining masks (a prior mask constrains the segmentation) or compositing previews into a report. Otherwise, the same warnings as its little sibling apply: don't run normal/pointmap without a mask, and if you're on Apple Silicon with scrambled labels, it's the MPS thing again - auto never picks MPS, and you shouldn't either unless you've verified your PyTorch/MPS build.

CategorySapiens2/Advanced

Inputs (7)

NameTypeDefaultDescription
modelSAPIENS2_MODEL
imageIMAGE
overlay_opacityFLOAT0.550–1
preserve_backgroundBOOLEANfalse
invertBOOLEANfalse
partsSTRING
maskoptMASK

Outputs (6)

NameTypeDescription
previewIMAGE
foreground_maskMASK
merged_maskMASK
masksMASK
labelsSAPIENS2_LABELS
resultSAPIENS2_RESULT