Nodes/SAM3_SmartInpainter/SAM Smart Inpainter (SAM3 v0.3)
ComfyUI Node

SAM Smart Inpainter (SAM3 v0.3)

SAM3 Smart Inpainter in ComfyUI

By majidfida·Created 4 months ago·Updated 2 months ago· 0
SAM Smart Inpainter (SAM3 v0.3)
  • image
  • model
  • clip
  • vae
  • positive
  • negative
  • output_image
  • inpainted_patch
  • segmentation_mask
  • debug_info
sam_model
promptface
text_threshold0.35
fallback_point_modeface_region
custom_point_x0.50
custom_point_y0.25
multi_mask_mergeunion
min_mask_area0.005
max_mask_area0.95
mask_blur6
mask_erosion0
mask_dilation4
mask_threshold0.50
invert_maskfalse
crop_padding32
crop_padding_modeaspect
inpaint_resolution768
upscale_methodbicubic
blend_modefeather
blend_strength1.00
sampler_namedpmpp_2m
schedulerkarras
steps20
cfg7.0
denoise0.55
seed0
noise_mask_feather8
deviceauto

The pitch in one line: you type face into a text box, the node finds every face in the image with SAM3's open-vocabulary segmentation, crops tight around the region, inpaints it with your checkpoint, and feathers the result back in - all inside a single node. No detector model to download separately, no hand-painted mask.

What it actually is under the hood is the classic ADetailer trick - detect, mask, inpaint at full resolution, composite - rebuilt for ComfyUI with a text prompt doing the detecting instead of a YOLO model. The detect-and-repaint loop exists because it fixes a structural problem, not a model bug: a 60-pixel face inside a 1024-wide render has almost no latent budget, so it comes out mangled no matter how good your checkpoint is. The fix is always to give that region its own pass at high resolution, then stitch it back in. That's exactly what mask inpainting still does better than any whole-image edit model - bit-identical unmasked pixels and full-res detail only inside the mask - and this node automates the fiddly crop-paste part of it. If your group shots routinely come back with one melted face at the edge, this is worth a slot in your workflow.

How it works

Four stages, and the debug log tells you which one you're in:

  1. Segment. The prompt goes through SAM3 - Meta's open-vocabulary Segment Anything model, running locally off sam3.pt, no API. face, eyes, hat, logo all work. If the text finds nothing, it falls back to a point prompt (center, face region, or your own custom_point_x/y).
  2. Clean up the mask. Multiple hits get merged (union, largest, or highest_score), then eroded/dilated, blurred, and thresholded. A min_mask_area / max_mask_area sanity check means a garbage selection doesn't wreck your image - it just passes the original through untouched with a note in debug_info.
  3. Crop and inpaint. The node crops the mask's bounding box (with crop_padding, aspect or square), upscales the crop to inpaint_resolution, VAE-encodes, and denoise-samples only that patch.
  4. Blend back. The patch is downscaled to original size and composited with blend_mode (feather default, mask, hard) and blend_strength.

The inputs that actually matter

Most of the knobs are sensible defaults. These are the ones you'll actually set:

  • prompt - the only input you should reach for first. Multiline, default "face". The mask is only as good as the prompt: "woman face" vs "face" matters when you chain nodes.
  • denoise - how much the region changes. 0.4–0.6 for subtle fixes, higher for full replacement.
  • inpaint_resolution - the detail dial. 768 is a good floor; go higher if the region stays blurry.
  • min_mask_area - lower it (toward 0.0005) when you're chasing distant or tiny faces.
  • crop_padding - extra room around the mask so the inpaint doesn't clip context.

Then the plumbing: model, clip, vae, positive, negative come straight from your checkpoint loader and text encoders. They're all optional - leave them disconnected and the node quietly becomes a "smart crop + upscale" preview that shows you exactly what it would have repainted, which is a handy way to sanity-check your prompt before you burn a full pass.

Four outputs: output_image (the final composited result), inpainted_patch (the raw repaired crop before blending), segmentation_mask (the actual MASK, reusable anywhere), and debug_info (a STRING explaining what it did - also printed to the console).

Installing it

ComfyUI Manager can do it if you search for 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   # opencv-python, omegaconf, hydra-core

Windows portable? Swap the pip line for ..\python_embeded\python.exe -m pip install -r SAM3_SmartInpainter\requirements.txt.

Then the part the README hammers, because it's the thing that actually trips people: this node doesn't ship the SAM3 engine. You must install a wrapper that provides the sam3 Python package first:

cd ComfyUI/custom_nodes
git clone https://github.com/yolain/ComfyUI-Easy-Sam3.git   # or 1038lab/ComfyUI-RMBG

Finally, drop sam3.pt (from HuggingFace, Majidfida/Sam3 or facebook/sam3) into ComfyUI/models/sam3/. The node creates that folder for you and lists whatever .pt files it finds in the sam_model dropdown, no config to touch.

Common issues

  • "sam3 package not found. Install ComfyUI‑Easy‑Sam3 or ComfyUI‑RMBG." This is the #1 gotcha, a runtime error, and it means you skipped the wrapper step. Install one, restart, done.
  • sam_model shows <no models found> - the .pt isn't in models/sam3/, or the dropdown hasn't refreshed.
  • "Mask too small" in debug_info - lower min_mask_area. Blurry repaint - raise inpaint_resolution. Harsh edges - raise mask_blur or switch blend_mode to feather.
  • Keep expectations in check. The README is upfront that the author won't monitor issues or PRs - this is community-shared, as-is, MIT. The more heavily populated SAM3 route is TBG-SAM3 plus Impact Pack, which has a much bigger community around it; this node is the lighter all-in-one take.
Categoryimage/inpainting

Inputs (34)

NameTypeDefaultDescription
imageIMAGE
sam_modelCOMBOSAM3 → models/sam3/ | SAM2 → models/sam2/ or models/sams/
promptSTRINGface
text_thresholdoptFLOAT0.350.05–0.95
fallback_point_modeoptCOMBOface_region3 options: center, face_region, custom
custom_point_xoptFLOAT0.500–1
custom_point_yoptFLOAT0.250–1
multi_mask_mergeoptCOMBOunion3 options: union, largest, highest_score
min_mask_areaoptFLOAT0.0050.0001–0.5
max_mask_areaoptFLOAT0.950.1–1
mask_bluroptINT60–64
mask_erosionoptINT00–32
mask_dilationoptINT40–64
mask_thresholdoptFLOAT0.500.01–0.99
invert_maskoptBOOLEANfalse
crop_paddingoptINT320–512
crop_padding_modeoptCOMBOaspect2 options: aspect, square
inpaint_resolutionoptINT768256–2048
upscale_methodoptCOMBObicubic4 options: bicubic, bilinear, lanczos, nearest
blend_modeoptCOMBOfeather3 options: feather, mask, hard
blend_strengthoptFLOAT1.000–1
modeloptMODEL
clipoptCLIP
vaeoptVAE
positiveoptCONDITIONING
negativeoptCONDITIONING
sampler_nameoptCOMBOdpmpp_2m44 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +38
scheduleroptCOMBOkarras9 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +3
stepsoptINT201–150
cfgoptFLOAT7.01–30
denoiseoptFLOAT0.550–1
seedoptINT00–18446744073709550000
noise_mask_featheroptINT80–64
deviceoptCOMBOauto4 options: auto, cuda, cpu, mps

Outputs (4)

NameTypeDescription
output_imageIMAGE
inpainted_patchIMAGE
segmentation_maskMASK
debug_infoSTRING