ComfyUI Node

SAM3 Prompt To Mask

SAM3 prompt-to-mask without the dependency hell

By kinorax·Created 5 months ago·Updated about a month ago· 2
SAM3 Prompt To Mask
  • image
  • mask
  • match_count
  • scores_json
  • boxes_json
promptperson
score_threshold0.15
combine_modeunion
deviceauto

Here's the pitch in one line: type "person" into a field, and out comes a mask of the person in your image. No points, no boxes, no manual polygon scribbling. That's what SAM3 Prompt To Mask gives you - Meta's Segment Anything 3 running locally, driven by text instead of clicks.

SAM3 is the generation of SAM that made prompt-driven segmentation practical. Older SAM variants wanted a point or a bounding box to know what to grab; SAM3 reads a description and finds the thing. Community integration is real but scattered - Impact Pack and a few standalone nodes hook SAM3 in for detection + detailer workflows. Where this node stands out is the single-purpose design: it does exactly text-in, soft-mask-out, and it's built to keep the Python environment from getting wrecked in the process.

The dependency story matters here

This is the detail worth understanding before you install anything. Some existing SAM3 ComfyUI extensions bring heavy pip dependencies that reshuffle your Python environment in ways that break other nodes. This pack's author explicitly decided not to do that. The SAM3 runtime is vendored - the code ships inside the pack - and its dependencies are deliberately minimal: timm, ftfy, regex, iopath, typing_extensions. That's a short, boring list that coexists with everything else you've installed. No onnxruntime fights, no version churn on your base ComfyUI packages.

You do have to supply the model file yourself. Drop sam3.pt into ComfyUI/models/sam3 (grab it from facebook/sam3 on Hugging Face). It's a large download, so budget for it, and note the README's honest caveat: operation is verified with SAM3; SAM3.1 and later are explicitly unverified. If you're on the newest SAM, don't be surprised if results are off.

How it works

Comma-separated prompts are treated as OR conditions - "person, hat" looks for a person or a hat, not a person wearing a hat. Two knobs control what you accept:

  • score_threshold (default 0.15) - detections scoring below this get discarded.
  • combine_mode - union merges all matched masks into one; top1 keeps only the single top-scoring mask per prompt.

There's also a device dropdown (auto / cuda / cpu) for pinning where the runtime runs.

The mask output is deliberately non-binarized - soft values in the 0..1 range, because the author intends thresholding and region cleanup to happen downstream (that's literally what the sibling Remove Small Soft Mask Regions node is for). Beyond the mask you get match_count (how many detections survived), plus scores_json and boxes_json - JSON strings of the detection scores and boxes, useful for debugging or for any custom logic that wants to know where the matches were before you commit to the mask.

Install

Same pack as the rest of this toolkit:

cd ComfyUI/custom_nodes
git clone https://github.com/kinorax/comfyui-info-prompt-toolkit.git
cd comfyui-info-prompt-toolkit
pip install -r requirements.txt

ComfyUI Manager works too - search "ComfyUI-Info-Prompt-Toolkit". Restart, then remember the model file: without sam3.pt in ComfyUI/models/sam3, the node errors the moment it runs.

Where people get burned

The most common failure is forgetting the model placement - the pack installs fine, the node appears, and only at queue time does it complain. Second is expecting a ready-to-use hard mask. It isn't. Feed the soft output through a cleanup + threshold stage before it hits an inpaint or detailer, or your edges will be mush and your background will bleed. And if you're coming from a workflow that assumed SAM3.1 weights, re-read the "unverified" note above - stick to sam3.pt.

CategoryInfo-Prompt-Toolkit/Mask

Inputs (5)

NameTypeDefaultDescription
imageIMAGEInput image batch processed with the same SAM3 text prompt
promptSTRINGpersonText prompt used to select target objects. Comma-separated prompts are treated as OR
score_thresholdFLOAT0.150–1Detections below this score are discarded when scores are available
combine_modeCOMBOunionunion merges all matched masks. top1 keeps only the top-scoring one for each comma-separated prompt
deviceCOMBOautoExecution device for the SAM3 runtime

Outputs (4)

NameTypeDescription
maskMASK
match_countINT
scores_jsonSTRING
boxes_jsonSTRING