Nodes/SAM3_SmartInpainter/SAM Mask Generator (SAM3 v0.3)
ComfyUI Node

SAM Mask Generator (SAM3 v0.3)

SAM3's text-prompt masks, without the repaint

By majidfida·Created 4 months ago·Updated 2 months ago· 0
SAM Mask Generator (SAM3 v0.3)
  • image
  • mask
  • mask_preview
  • debug_info
sam_model
promptface
text_threshold0.35
mask_blur6
mask_dilation4
mask_erosion0
invert_maskfalse
deviceauto

If the Smart Inpainter in this pack is the one-stop detect-and-fix node, this is just the detection half. You feed it an image, type face, and it hands you a mask - no diffusion, no blending, no checkpoint required. You take that mask and do something else with it.

Honestly, that's the more flexible node of the two. Three jobs where it shines:

  1. Preview before you commit. Run this first to see exactly what SAM3 would select before you burn a full inpaint pass. The mask_preview output is white-on-black, so coverage is visible at a glance.
  2. Drive any other inpaint pipeline. Wire mask into whatever mask-based workflow you already trust - a plain inpaint node, Set Latent Noise Mask, or Impact Pack tooling. You get SAM3's text-prompt segmentation feeding a system you know, instead of adopting the whole smart-inpaint stack at once.
  3. Mask math beyond inpainting. Selecting a logo, a scarf, or a background object for compositing. With invert_mask you get "everything except the face" in one click, which is a handy trick for keeping a subject untouched while everything else gets edited.

How it works

The mechanism is the same engine as the pack's bigger node: the sam3 Python package turns your prompt into masks, text_threshold filters out low-confidence hits, and if the prompt finds nothing it falls back to a point prompt at the image center. Note it's the trimmed version - it doesn't carry the face_region/custom fallback options the Smart Inpainter has, just center. After that it applies the same cleanup chain: erosion, dilation, gaussian blur, optional invert. No crop, no upscale, no sampling. In and out in a fraction of the time of a repaint pass.

Inputs that matter

  • prompt - multiline, default "face". This is the whole game: the mask is only as good as the words.
  • text_threshold - default 0.35. Lower it (toward 0.25) to catch smaller or more ambiguous things; raise it if you're getting extra junk in the mask.
  • mask_blur, mask_dilation, mask_erosion - edge cleanup. If the mask has holes, add dilation; if it bleeds past the object, erosion.
  • invert_mask - flips the selection. Off by default.
  • device - auto/cuda/cpu/mps. auto is fine unless you specifically want to force CPU or MPS.

The sam_model dropdown and the model-file requirement are identical to the parent node - same list, same models/sam3/ folder, same <no models found> failure mode if the weight is missing.

Three outputs: mask (a proper MASK you wire into any MASK input), mask_preview (the same thing as an IMAGE you can actually look at), and debug_info (a STRING with coverage percentage and any reasons the prompt came up empty).

Installing it

Same pack, same install as its sibling. ComfyUI Manager (search SAM3 Smart Inpainter) or manually:

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

The critical dependency is the wrapper that provides the sam3 package - install ComfyUI-Easy-Sam3 (git clone https://github.com/yolain/ComfyUI-Easy-Sam3.git) or ComfyUI-RMBG, then put sam3.pt in ComfyUI/models/sam3/. No wrapper, no mask: you'll get a runtime "sam3 package not found" error.

Gotchas

  • Same wrapper dependency as the big node - that's the one install step people skip, and it fails at runtime, not install time.
  • It doesn't crash on an empty result. If the prompt finds nothing, you get a zero mask plus an explanation in debug_info instead of a hard failure mid-workflow. That's friendlier than most segmentation nodes, though you should still read debug_info when the mask looks wrong.
  • There's no repaint here. If you wire this up expecting the image to change, you've got the wrong node for the job - take the mask and feed it into an inpaint node. Remember the author's caveat from the README: the repo isn't monitored, so treat it as community-shared as-is.
Categoryimage/inpainting

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
sam_modelCOMBO1 options: <no models found>
promptSTRINGface
text_thresholdoptFLOAT0.350.05–0.95
mask_bluroptINT60–64
mask_dilationoptINT40–64
mask_erosionoptINT00–32
invert_maskoptBOOLEANfalse
deviceoptCOMBOauto4 options: auto, cuda, cpu, mps

Outputs (3)

NameTypeDescription
maskMASK
mask_previewIMAGE
debug_infoSTRING