ComfyUI Node

💀Image SAM

Select any object by typing what it is — 💀Image SAM turns a prompt into a mask

By S4MUEL-404·Created about a year ago·Updated 10 months ago· 4
💀Image SAM
  • image
  • segmented_image
  • mask
sam_model_namesam_vit_b (375MB)
grounding_dino_model_nameGroundingDINO_SwinT_OGC (694MB)
promptobject
threshold0.30

Type "cat", get the cat's mask. That's the whole pitch of 💀Image SAM, and it's the headline AI node in the S4Tool-Image pack. Instead of painting or clicking points on an image, you describe the thing you want isolated and the node finds it - because it stacks two models: GroundingDINO does the "find the object from a text prompt" job and returns a bounding box, then Segment Anything (SAM) refines that box into a precise pixel mask. It's the same prompt-driven segmentation trick that powers a lot of popular workflows, packaged into a single node.

Where this shines in a real workflow: you've inpainted, regenerated, or generated a character and you need a clean cutout to composite or to drive a masked edit. You drop the image in, type what you want, and out come both the masked-off image and the raw MASK tensor for downstream nodes. No manual masking. The catch is the same as with any two-model pipeline - it's heavy, and setup is the fiddly part.

The inputs that matter

  • sam_model_name - pick your SAM checkpoint. Default is sam_vit_b (375MB). There's a real ladder here: sam_vit_h (2.56GB) is the most accurate original, sam_hq_vit_h is the high-quality variant that's noticeably better on fine edges (hair, fur), and mobile_sam(39MB) if you're on a tight VRAM budget and can accept worse boundaries. For most people sam_vit_b is the sensible default; reach for HQ when edges matter.
  • grounding_dino_model_name - GroundingDINO_SwinT_OGC (694MB) or the bigger, more accurate GroundingDINO_SwinB (938MB).
  • image - the IMAGE you want to segment.
  • prompt - the object description. Defaults to "object" which finds the most salient thing. Be specific: "person", "dog", "the red car".
  • threshold (0–1, default 0.3) - how confident GroundingDINO must be before it commits to a detection. Lower it when objects aren't being found; raise it when you're getting spurious boxes.

Outputs: segmented_image (the cutout, background removed) and mask - the MASK you'll actually route into inpaint, compositing, or mask-edit nodes.

Install - read this twice

The pack installs normally:

cd ComfyUI/custom_nodes/
git clone https://github.com/S4MUEL-404/ComfyUI-S4Tool-Image.git
pip install -r ComfyUI-S4Tool-Image/requirements.txt

Then the extra step that trips everyone: GroundingDINO needs BERT, and the README is emphatic that you install it by hand. This is the #1 reason this node fails for people:

cd ComfyUI/models/
git clone https://huggingface.co/google-bert/bert-base-uncased

The code will try to fall back to downloading BERT from Hugging Face at first run if it's not there, but that's exactly when you get a silent hang or a runtime error. Do the manual clone. The SAM checkpoints and GroundingDINO weights themselves auto-download on first use into ComfyUI/models/sams/ and ComfyUI/models/grounding-dino/ - that's a few hundred MB to over a GB depending on what you pick, so the first queue run takes a while.

Troubleshooting

  • "SAM functionality will fail" - you skipped the BERT step. Clone google-bert/bert-base-uncased into ComfyUI/models/ and restart.
  • Object not found - lower threshold toward 0.1 and make the prompt more specific.
  • Ragged edges - switch to an HQ model (sam_hq_vit_h or sam_hq_vit_l) and be patient; SAM's masks are decent but not matte-quality on hair.
  • Out of memory - drop to sam_vit_b or mobile_sam, and avoid the 2.5GB ViT-H on small cards.

One honest note: this node overlaps heavily with the newer 💀Image SAM2 in the same pack, which adds SAM2.1 models and a bunch of cleanup parameters. If you're starting fresh, SAM2 is usually the better first stop - this one is the older, simpler workhorse. And if you want background removal specifically (not arbitrary object selection), 💀Image RMBG in the same pack is lighter and purpose-built for that.

Category💀S4Tool

Inputs (5)

NameTypeDefaultDescription
sam_model_nameCOMBOsam_vit_b (375MB)7 options: sam_vit_h (2.56GB), sam_vit_l (1.25GB), sam_vit_b (375MB), sam_hq_vit_h (2.57GB), sam_hq_vit_l (1.25GB), sam_hq_vit_b (379MB), +1
grounding_dino_model_nameCOMBOGroundingDINO_SwinT_OGC (694MB)2 options: GroundingDINO_SwinT_OGC (694MB), GroundingDINO_SwinB (938MB)
imageIMAGE
promptSTRINGobject
thresholdFLOAT0.300–1

Outputs (2)

NameTypeDescription
segmented_imageIMAGE
maskMASK