Nodes/Fat Mex Nodes/Fat Mex Head Mask
ComfyUI Node

Fat Mex Head Mask

Ask SAM3 what to cut out

By FatMex·Created 7 months ago·Updated 7 months ago· 3
Fat Mex Head Mask
  • image
  • mask
  • preview
mask_prompthair. head. face.
grow_pixels15
confidence0.20
sam3_model_pathmodels/sam3/sam3.pt

Before you can swap a head, inpaint a region, or composite a cutout, you need a mask. This node gets you one from a sentence. It wraps SAM3 - the newest line of Meta's promptable segmentation models - into LoadSAM3Model + SAM3Grounding + GrowMask, so you type "hair. head. face." and out comes a grown mask ready to feed an inpaint, plus a visualization so you can see what it caught.

That's the whole value: SAM3 does text-grounded, zero-shot segmentation. No clicking points, no drawing boxes - describe it, get a mask. For head swaps specifically (which is what this pack is mostly doing), the default prompt is already tuned for exactly that job.

How it works

Three steps behind one interface:

  1. Load the SAM3 model - cached after first use so subsequent runs don't reload it.
  2. Ground the text prompt - SAM3 segments everything matching mask_prompt, filtered by a confidence threshold (default 0.2). Lower it and it catches more (and more false positives); raise it and it gets pickier.
  3. Grow the mask - grow_pixels (default 15) dilates the mask so edges bleed slightly into skin and background, which is the feathering you want before an inpaint so the seam vanishes. The grow logic replicates ComfyUI's GrowMask.

The mask_prompt uses SAM3's text format - separate items with periods: "hair. head. face." by default, but "shirt. jacket." or "dog." work the same way. It's a grounding prompt, not a natural-language paragraph.

Outputs are mask (the MASK you wire into an inpaint, composite, or detailer) and preview (an IMAGE of the mask visualization so you can sanity-check what the model decided to cut).

The input that trips people up

sam3_model_path defaults to models/sam3/sam3.pt, with the tooltip promising auto-download if it's missing. That auto-download behavior lives in the ComfyUI-SAM3 pack, not here - so this node is only as good as that dependency.

Install

This node is the one Fat Mex node with a hard external requirement. First install the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/FatMex/ComfyUI-FatMex-Nodes.git FatMex-Nodes
pip install -r FatMex-Nodes/requirements.txt

Then install ComfyUI-SAM3 (search it in ComfyUI Manager, or git clone https://github.com/neverbiasu/ComfyUI-SAM3 into custom_nodes/). Without it, this node raises an import error telling you exactly that. Restart ComfyUI after both.

Where people get burned

  • Missing ComfyUI-SAM3 - the number one failure, and the error is clear about it. It's a separate pack; the Fat Mex install doesn't bring it.
  • "Hair. head. face." is a head mask, not a face mask. If you want only the face region (for a face-focused inpaint), change the prompt. The default grabs the full head including hair, which is what you want for head swaps - but know which one you're getting.
  • Confidence tuning. At 0.2 the model can grab extra objects it decides match. If your mask includes random background, raise the threshold. If it misses, lower it.
  • SAM3 model download. It's a multi-hundred-MB .pt the first time. It downloads once and caches; subsequent runs are fast thanks to the node's caching.
CategoryFat Mex

Inputs (5)

NameTypeDefaultDescription
imageIMAGEThe image to create a mask from.
mask_promptoptSTRINGhair. head. face.What to mask. SAM3 text grounding prompt. Separate items with periods.
grow_pixelsoptINT150–100Expand the mask by this many pixels (feathering).
confidenceoptFLOAT0.200–1SAM3 detection confidence threshold.
sam3_model_pathoptSTRINGmodels/sam3/sam3.ptPath to SAM3 model (auto-downloads if missing).

Outputs (2)

NameTypeDescription
maskMASK
previewIMAGE