SAM Smart Inpainter (SAM3 v0.3)
SAM3 Smart Inpainter in ComfyUI
- image
- model
- clip
- vae
- positive
- negative
- output_image
- inpainted_patch
- segmentation_mask
- debug_info
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:
- Segment. The prompt goes through SAM3 - Meta's open-vocabulary Segment Anything model, running locally off
sam3.pt, no API.face,eyes,hat,logoall work. If the text finds nothing, it falls back to a point prompt (center, face region, or your owncustom_point_x/y). - Clean up the mask. Multiple hits get merged (
union,largest, orhighest_score), then eroded/dilated, blurred, and thresholded. Amin_mask_area/max_mask_areasanity check means a garbage selection doesn't wreck your image - it just passes the original through untouched with a note indebug_info. - Crop and inpaint. The node crops the mask's bounding box (with
crop_padding, aspect or square), upscales the crop toinpaint_resolution, VAE-encodes, and denoise-samples only that patch. - Blend back. The patch is downscaled to original size and composited with
blend_mode(featherdefault,mask,hard) andblend_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_modelshows<no models found>- the.ptisn't inmodels/sam3/, or the dropdown hasn't refreshed.- "Mask too small" in
debug_info- lowermin_mask_area. Blurry repaint - raiseinpaint_resolution. Harsh edges - raisemask_bluror switchblend_modetofeather. - 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.
Inputs (34)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| sam_model | COMBO | SAM3 → models/sam3/ | SAM2 → models/sam2/ or models/sams/ | |
| prompt | STRING | face | — |
| text_thresholdopt | FLOAT | 0.350.05–0.95 | — |
| fallback_point_modeopt | COMBO | face_region | 3 options: center, face_region, custom |
| custom_point_xopt | FLOAT | 0.500–1 | — |
| custom_point_yopt | FLOAT | 0.250–1 | — |
| multi_mask_mergeopt | COMBO | union | 3 options: union, largest, highest_score |
| min_mask_areaopt | FLOAT | 0.0050.0001–0.5 | — |
| max_mask_areaopt | FLOAT | 0.950.1–1 | — |
| mask_bluropt | INT | 60–64 | — |
| mask_erosionopt | INT | 00–32 | — |
| mask_dilationopt | INT | 40–64 | — |
| mask_thresholdopt | FLOAT | 0.500.01–0.99 | — |
| invert_maskopt | BOOLEAN | false | — |
| crop_paddingopt | INT | 320–512 | — |
| crop_padding_modeopt | COMBO | aspect | 2 options: aspect, square |
| inpaint_resolutionopt | INT | 768256–2048 | — |
| upscale_methodopt | COMBO | bicubic | 4 options: bicubic, bilinear, lanczos, nearest |
| blend_modeopt | COMBO | feather | 3 options: feather, mask, hard |
| blend_strengthopt | FLOAT | 1.000–1 | — |
| modelopt | MODEL | — | |
| clipopt | CLIP | — | |
| vaeopt | VAE | — | |
| positiveopt | CONDITIONING | — | |
| negativeopt | CONDITIONING | — | |
| sampler_nameopt | COMBO | dpmpp_2m | 44 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +38 |
| scheduleropt | COMBO | karras | 9 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +3 |
| stepsopt | INT | 201–150 | — |
| cfgopt | FLOAT | 7.01–30 | — |
| denoiseopt | FLOAT | 0.550–1 | — |
| seedopt | INT | 00–18446744073709550000 | — |
| noise_mask_featheropt | INT | 80–64 | — |
| deviceopt | COMBO | auto | 4 options: auto, cuda, cpu, mps |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| output_image | IMAGE | — |
| inpainted_patch | IMAGE | — |
| segmentation_mask | MASK | — |
| debug_info | STRING | — |