SAM 3.1 is the easiest way to cut objects out of images and videos in ComfyUI. Type a word like “guitar” or “dog”, and it finds every match and draws a clean mask around each one. No clicking points, no custom nodes.
It works on video too, and it can follow each object from frame to frame.
This guide covers the one model file you need, the two official workflows (image and video), every setting on the SAM3 nodes, prompt tricks like eye:2, and how to turn the masks into transparent cut-outs, inpainting masks or a tracked video.
Everything is checked against ComfyUI’s source code and official templates as of December 2026.
- One file:
sam3.1_multiplex_fp16.safetensors(1.63 GB) inComfyUI/models/checkpoints/, loaded with the normal Load Checkpoint node. - Native support: update ComfyUI, then open the Image Segment (SAM3) or Video Segment (SAM3) template.
- Prompt with words: “guitar”, or several objects at once with counts:
eye:2, window panels:4. The text limit is 32 tokens. - Key settings: threshold 0.5, refine_iterations 2, individual_masks off (one combined mask) or on (one mask per object).
- For tracking in video, use SAM3_VideoTrack, then SAM3_TrackToMask to pick which objects to keep.
New to ComfyUI? Start with my ComfyUI guide for the basics of nodes, models and workflows.
What SAM 3.1 Does
SAM stands for Segment Anything Model, Meta’s family of segmentation models. The first two versions needed you to click on an object or draw a box.
SAM 3 added text prompts. You describe what you want (“red car”, “person”, “window”) and it finds every instance in the picture, each with its own mask and bounding box.
SAM 3.1 is the “multiplex” update, and it’s the version ComfyUI ships templates for. Support is native, added in ComfyUI pull request #13408. You don’t need a custom node pack.
What you can do with it:
- Remove backgrounds from photos by masking the subject and inverting the mask.
- Make inpainting masks without painting them by hand, such as “shirt” or “sky”.
- Mask an object in every frame of a video for recolouring, replacing or blurring.
- Track several objects through a clip and keep only the ones you want.
The model is released under Meta’s SAM License. Read it before using the outputs commercially.
Model File and Folder
You only need one file, from Comfy-Org’s repackaged repo on Hugging Face (Comfy-Org/sam3.1). The template also lists a ModelScope mirror.
| File | Size | Folder |
|---|---|---|
sam3.1_multiplex_fp16.safetensors |
1.63 GB | ComfyUI/models/checkpoints/ |
ComfyUI/models/checkpoints/sam3.1_multiplex_fp16.safetensors
It goes in checkpoints, not a “sam” folder. The templates load it with the standard Load Checkpoint node (CheckpointLoaderSimple). That node gives you both the model and its text encoder, so there’s no separate CLIP file to download.
At 1.63 GB it runs comfortably on 6-8 GB cards. Video is heavier, because every frame is processed. See the video section for ways to keep memory down. For where other model types go, see my ComfyUI model folder cheat sheet.
Image Segmentation Workflow
Update ComfyUI first. The Desktop app follows stable releases, so new templates can appear in the portable or Git version a little earlier.
- Open Workflow → Browse Templates and search for SAM3. Pick Image Segment (SAM3). Or download
utility_image_segment_sam3.jsonfrom Comfy-Org’sworkflow_templatesrepo and drag it onto the canvas. - Load your picture in Load Image.
- Type what to segment in the subgraph’s text field. The template uses
guitar. - Press Run (Ctrl+Enter).
The template wraps the core in a subgraph called “Image Segment (SAM3)”. Inside it you’ll find:
| Node | Template value | Job |
|---|---|---|
| Load Checkpoint | sam3.1_multiplex_fp16 | Loads SAM 3.1 and its text encoder |
| CLIP Text Encode | “guitar” | Turns your words into conditioning |
| SAM3_Detect | threshold 0.5, refine 2, individual_masks false | Finds matches and outputs masks + boxes |
Outside the subgraph, the template shows what to do with the result. MaskPreview shows the raw mask. InvertMask plus Join Image with Alpha builds a cut-out with a transparent background, shown in Preview Image. Save it with a Save Image node if you want a PNG.
Prompting SAM 3: Words, Counts, Points and Boxes
SAM 3 accepts four kinds of prompt. You can combine them.
1. Text (the main one)
Keep it short and concrete: a noun, with a colour or detail if needed. “dog”, “white mug”, “person in red jacket”. The template note warns that the model takes only 32 tokens, so long sentences get cut off.
2. Several objects with counts
Separate subjects with commas, and add :N to cap how many of each it returns. This example from the template finds two eyes and four window panels:
eye:2, window panels:4
Counts are handy when the model finds too many matches, like every face in a crowd when you only want the main two.
3. Points
SAM3_Detect has optional positive_coords and negative_coords inputs. They take JSON with pixel positions:
[{"x": 512, "y": 300}, {"x": 540, "y": 420}]
Positive points say “this belongs to the object”. Negative points say “not this”. Use them to fix a mask that grabbed too much, such as a hand holding the guitar. These inputs only accept a connection, so feed them from a String node or a points editor node.
4. Bounding boxes
The bboxes input limits the search to areas you choose. You can chain detectors this way: run a coarse detection first, then pass its boxes into a second SAM3_Detect for a cleaner mask.
SAM3_Detect Settings Explained
| Setting | Default | Range | What it does |
|---|---|---|---|
| threshold | 0.5 | 0-1 | Minimum confidence for a detection to count |
| refine_iterations | 2 | 0-5 | SAM decoder refinement passes. 0 uses the raw detector masks |
| individual_masks | false | on/off | On: one mask per object. Off: everything merged into one mask |
How to tune them:
- Nothing gets detected: lower threshold to 0.3-0.4, or reword the prompt (“car” instead of “sedan”).
- Wrong objects get included: raise threshold to 0.6-0.7, add a colour or detail, or use a count like
cat:1. - Edges look blocky: raise refine_iterations to 3-4. Each pass costs a little time.
- Need to treat objects separately (for example, recolour one person but not another): turn individual_masks on and pick the mask you need from the batch.
The node outputs masks and bboxes. The boxes can feed another SAM3_Detect, or any node that takes bounding boxes.
Video Segmentation and Object Tracking
There are two ways to work with video. The template uses the simple one.
Option A: the Video Segment template (detect every frame)
Search templates for Video Segment (SAM3) (utility_video_segment_sam3.json). It uses:
- Load Video → Get Video Components, which splits the clip into frames.
- The same Load Checkpoint + CLIP Text Encode (“unicorn” in the sample) + SAM3_Detect chain, run on all frames as a batch.
- MaskPreview to view the mask for every frame.
This is the quickest to set up. Each frame is detected on its own, though, so masks can flicker a little when objects overlap or turn away.
Option B: SAM3_VideoTrack (follow objects through the clip)
For steady, per-object masks, build this chain yourself. All nodes are native:
| Node | Key inputs | Notes |
|---|---|---|
| SAM3_VideoTrack | images, model, conditioning and/or initial_mask; detection_threshold 0.5; max_objects 4; detect_interval 1 | Tracks objects across frames and gives each one an index |
| SAM3_TrackPreview | track_data, images, opacity 0.5, fps 24 | Plays the video with coloured masks over it |
| SAM3_TrackToMask | track_data, object_indices (e.g. “0,2”) | Turns chosen objects into a mask batch. Empty = all |
Tips for tracking:
- max_objects caps how many things are tracked. Initial masks count toward it. 0 means the internal cap of 64.
- detect_interval sets how often it looks for new objects. 1 checks every frame. 5-10 saves a lot of compute on long clips where nothing new enters.
- initial_mask lets you start from an exact mask, for example one from SAM3_Detect on the first frame, with one mask per object.
- Watch the preview first, note which index is which object, then type those numbers in SAM3_TrackToMask.
Comfy uses the same tracker in its SAM 3D Body template (VideoTrack with 0.5 / 4 / 1), which shows how it plugs into bigger pipelines.
Keeping video memory in check
- Trim the clip first with a Video Slice node. Test on 2-5 seconds.
- Downscale large videos before segmenting. 720p is plenty for most masks.
- If you hit out-of-memory errors, see ComfyUI out of memory fixes.
What to Do with the Masks
- Transparent cut-out: InvertMask → Join Image with Alpha → Save Image (PNG). The image template does the same, with a preview in place of the save.
- Inpainting: feed the mask into an inpaint workflow to change only that object. “shirt” + inpaint = new outfit. Grow the mask by a few pixels so the edges blend. My ComfyUI inpainting guide covers the setup.
- Background replacement: mask the person, invert, and composite them over a new image or video.
- Video edits: per-frame masks can drive video inpainting or a ControlNet pass. Save the processed frames with ComfyUI Save Video.
- Depth plus masks: combine a SAM mask with a depth map to blur only the background. See Depth Anything 3 in ComfyUI.
Common Problems and Fixes
| Problem | Likely cause | Fix |
|---|---|---|
| SAM3_Detect node missing (red node) | ComfyUI too old | Update ComfyUI (Git or portable if Desktop lags) |
| Model not in the checkpoint list | Wrong folder | Move the file to models/checkpoints/ and press R to refresh |
| Empty (all black) mask | Threshold too high or prompt too vague | Lower threshold to 0.3-0.4; use a simpler noun |
| Mask covers extra objects | Prompt matches several things | Add :1, a colour, or negative points |
| Long prompt ignored partly | 32-token limit | Shorten; use comma lists instead of sentences |
| Flickering masks in video | Per-frame detection | Use SAM3_VideoTrack instead of SAM3_Detect |
| Out of memory on video | Too many or too large frames | Trim with Video Slice, downscale, raise detect_interval |
FAQ
Do I need a custom node for SAM 3 in ComfyUI?
No. SAM 3.1 is supported natively. Update ComfyUI and use the SAM3 templates or the SAM3_Detect node.
Where does the SAM 3.1 model go?
In ComfyUI/models/checkpoints/. Load it with the standard Load Checkpoint node.
How much VRAM does SAM 3 need?
The fp16 model is 1.63 GB, so images run fine on 6-8 GB cards. Video needs more, depending on clip length and resolution.
Can SAM 3 segment several different objects at once?
Yes. Separate them with commas and optionally add counts, like person:2, dog:1. Turn on individual_masks for a separate mask per object.
What’s the difference between SAM3_Detect and SAM3_VideoTrack?
SAM3_Detect finds objects in each image or frame on its own. SAM3_VideoTrack follows objects across frames and keeps each one’s identity, which gives steadier video masks.
Can I use SAM 3 for background removal?
Yes. Mask the subject, invert the mask and join it with the image as alpha. The image template already does this.
Is SAM 3 free for commercial use?
It’s released under Meta’s SAM License. Check the licence terms for your use case before relying on it commercially.
Sources
- ComfyUI source:
comfy_extras/nodes_sam3.py(SAM3_Detect, SAM3_VideoTrack, SAM3_TrackPreview, SAM3_TrackToMask) - Comfy-Org workflow templates: utility_image_segment_sam3, utility_video_segment_sam3, utility_sam3d_body
- ComfyUI docs: SAM 3 video segmentation tutorial



