Meta SAM 3 Playground

Guide · SAM 3 / 3.1 · precise selection

How to Select Specific Objects with Meta SAM Text finds every match. When you need exactly one, or exactly the right few, use clicks, boxes, candidate masks, filter rules, negative boxes and video object IDs.

one of many
Animation of selecting one person in a crowdSix people stand in a row. The text prompt “person” masks all six. A single click on the third person masks only that one. Finally, text plus a “largest” filter keeps a single person chosen by a rule. text › “person”6 matches: too many click › this one1 object, exactly where you clicked text “person” + rule: leftmost1 object, chosen by a rule (automatable)
Illustration: all matches, a click, or a rule.

Start here

Which Selection Method Should You Use?

Four questions point you to the right technique.

choose a method
Animated guide to choosing a selection methodFour questions appear in turn with their answers: if you can point at it, click or draw a box; if you can name it but there are many, use text plus a filter rule; if look-alikes get in, add a negative box; if you need it in every video frame, click once to give it an object ID. Can you point at it?click or boxCan you name it but there are many?text + filter ruleLook-alikes getting in?text + negative boxNeed it in every frame?click once → obj_id
Illustration of how to choose.
SituationMethod
Editing one photoClicks or a box
Same choice on 1,000 imagesText + filter rule
Similar objects sneak inText + negative box
“The one holding …”Text + click, or SAM 3 Agent
One object through a videoClick once → object ID

Method 1

Positive and Negative Clicks

The most precise way to select one object. Green adds, red removes.

Method 1
  1. 1Click the centreof the object, not its edge.
  2. 2Too much?Add a negative click on the part that shouldn’t be there (a held bag, a neighbour).
  3. 3Too little?Add a positive click on the missing part (a raised arm, a wheel).
  4. 4Stop at 2–4 clicks.More rarely helps; draw a box instead.

Clicks use SAM 3’s instance (SAM 2-style) mode: one object per selection. Side-by-side examples: prompt examples

Ambiguity

When One Click Means Several Things

A click on a shirt could mean the shirt, the person, or the person with their bag. SAM returns ranked candidates.

three candidates
Animation of multiple mask candidates from one clickOne click on a person’s shirt is ambiguous, so three candidate masks appear: just the shirt with score 0.71, the whole person with score 0.94, and the person plus their bag with score 0.83. The highest-scoring candidate, the whole person, is selected. shirt · 0.71person · 0.94+ bag · 0.83 one click → 3 candidates ranked by score · keep the best or add clicks
Illustrative candidates and scores.
  • Ask for candidates: leave multimask output on for a single click.
  • Keep the best score automatically, or show all three and let the user pick.
  • Remove ambiguity: one more click (positive on the whole, negative on the part) usually settles it.
  • Multiple clicks? Turn multimask off: the clicks already say what you mean.

Method 2

Draw a Box

One box around one object is the fastest selection for clearly separated things.

Method 2
  • Tight but complete: include the whole object, little background.
  • Overlapping objects? Add a click inside the box on the one you mean, or a negative click on the other.
  • Box vs exemplar: in instance mode a box selects that object; as a positive exemplar with text it means “find more like this”. See exemplar boxes.

Method 3

Text + a Filter Rule (Automatable)

For pipelines: let text find every candidate, then choose one in code by size, position, score or nearness.

filter rules
Animation of filter rules after a text promptFive apples of different sizes are all found by the text prompt “apple”. Then three rules pick one each in turn: largest picks the big middle apple, leftmost picks the first apple, and nearest to a marked point picks the apple next to it. text › “apple” rule › largestrule › leftmostrule › nearest to ✕ find with text, choose with code: repeatable for thousands of images
Illustration of choosing one result by rule.
Method 3
  • Largest: the main product in a photo.
  • Leftmost / top / bottom: position words like “the person on the left”.
  • Nearest to a point: a user tap or a known location.
  • Inside a region: one shelf, one lane, one desk.
  • Top-k by score: the three most confident matches.

The describe() and pick() helpers are in the code section.

Method 4

Text + Negative Box

When a text prompt grabs look-alikes, box one as negative to exclude that kind.

Method 4
  • Example: “handle” + negative box on the oven handle → only cupboard handles.
  • Works on a type, not one item: it removes things that look like the negative example.
  • For one specific item use clicks or a rule instead.
  • Animated example and code: negative exemplar boxes

Method 5

Select One Object in a Video

Give the chosen object its own ID on one frame; SAM 3 keeps it through the clip.

single-object tracking
Animation of tracking one chosen object in videoFour runners move along separate lanes at different speeds. One click on the runner in lane two on frame 0 gives it object ID 1. As the runners overtake each other, only runner 1 keeps its green mask. id 1 frame 0 · click → obj_id 1 only the selected runner is tracked
Illustration of tracking one chosen runner.
Method 5
  • Click to select: one click with an obj_id on a clear frame.
  • Or text, then remove: prompt “runner”, then remove the IDs you don’t need.
  • Drift? Add a click for the same obj_id on the frame where it slipped.
  • Full script: video segmentation with Python

Code

Code for Each Selection Method

Pixel coordinates throughout, except where noted.

Transformers · clicks, box, best of 3 candidates

import torch
from PIL import Image
from transformers import Sam3TrackerProcessor, Sam3TrackerModel

model = Sam3TrackerModel.from_pretrained("facebook/sam3", device_map="auto")
processor = Sam3TrackerProcessor.from_pretrained("facebook/sam3")
image = Image.open("street.jpg").convert("RGB")

# A) one positive click + one negative click on the same object (pixel x, y)
inputs = processor(images=image, input_points=[[[[500, 375], [560, 420]]]],
                   input_labels=[[[1, 0]]], return_tensors="pt").to(model.device)
with torch.no_grad():
    out = model(**inputs, multimask_output=False)
mask = processor.post_process_masks(out.pred_masks.cpu(), inputs["original_sizes"])[0][0, 0]

# B) a box around the object: x0, y0, x1, y1
inputs = processor(images=image, input_boxes=[[[420, 300, 640, 520]]], return_tensors="pt").to(model.device)

# C) one ambiguous click → 3 ranked candidates, keep the best
inputs = processor(images=image, input_points=[[[[500, 375]]]], input_labels=[[[1]]], return_tensors="pt").to(model.device)
with torch.no_grad():
    out = model(**inputs)                              # multimask output by default
cands = processor.post_process_masks(out.pred_masks.cpu(), inputs["original_sizes"])[0][0]
best = cands[int(out.iou_scores[0, 0].argmax())]

Ultralytics · clicks and box

from ultralytics import SAM
sam = SAM("sam3.pt")          # or sam3.1_multiplex.pt (images)

sam("street.jpg", points=[500, 375], labels=[1])                           # one click
sam("street.jpg", points=[[[500, 375], [560, 420]]], labels=[[1, 0]])    # + and − on one object
sam("street.jpg", bboxes=[420, 300, 640, 520])                         # one box

any interface · text + filter rule

import numpy as np

def describe(masks, scores):
    # turn SAM 3 outputs into simple facts you can sort on
    objs = []
    for i, (m, s) in enumerate(zip(masks, scores)):
        ys, xs = np.nonzero(m)
        if len(xs):
            objs.append(dict(i=i, score=float(s), area=int(m.sum()),
                             cx=float(xs.mean()), cy=float(ys.mean())))
    return objs

def pick(objs, rule="largest", point=None, region=None, k=1):
    if region:                                       # keep objects centred inside (x0, y0, x1, y1)
        x0, y0, x1, y1 = region
        objs = [o for o in objs if x0 <= o["cx"] <= x1 and y0 <= o["cy"] <= y1]
    key = {
        "largest": lambda o: -o["area"],   "smallest": lambda o: o["area"],
        "leftmost": lambda o: o["cx"],     "rightmost": lambda o: -o["cx"],
        "top": lambda o: o["cy"],          "bottom": lambda o: -o["cy"],
        "score": lambda o: -o["score"],
        "nearest": lambda o: (o["cx"] - point[0]) ** 2 + (o["cy"] - point[1]) ** 2,
    }[rule]
    return sorted(objs, key=key)[:k]

# with the official sam3 processor:
# out = processor.set_text_prompt(state=processor.set_image(image), prompt="apple")
# masks = [m.squeeze().cpu().numpy().astype(bool) for m in out["masks"]]
# chosen = pick(describe(masks, out["scores"]), rule="nearest", point=(380, 115))
# mask = masks[chosen[0]["i"]]

video · official sam3 session

# official sam3 video session: select by click, track only that object
predictor.handle_request(dict(type="add_prompt", session_id=sid, frame_index=0,
                              points=[[0.42, 0.55]], point_labels=[1], obj_id=1))   # check coordinate scale in the video notebook

# or: text first, then drop everyone you don't want
predictor.handle_request(dict(type="add_prompt", session_id=sid, frame_index=0, text="runner"))
for oid in [0, 2, 3]:
    predictor.handle_request(dict(type="remove_object", session_id=sid, obj_id=oid))

video · Transformers tracker

# Transformers: Sam3TrackerVideoModel, one object by click
processor.add_inputs_to_inference_session(
    inference_session=session, frame_idx=0, obj_ids=1,
    input_points=[[[[210, 350]]]], input_labels=[[[1]]])
for out in model.propagate_in_video_iterator(session):
    ...   # masks for object 1 only

Transformers examples follow the official SAM 3 Tracker docs. Setup: install SAM 3 · Python tutorial

No code

Selecting Objects Without Code

In the playground

  • Click the object; add negative clicks to trim.
  • Or type the object, then click the one you want.
  • Zoom in to check edges before exporting.
  • Open the playground

In ComfyUI

  • Native template: text prompts with :N to cap matches, e.g. person:1.
  • ComfyUI-SAM3 pack: point, box and multi-region collector nodes for clicks.
  • ComfyUI setup

Troubleshooting

Selection Problems and Fixes

ProblemFix
Mask includes a neighbourNegative click on the neighbour
Only part of the objectPositive click on the missing part, or use a box
Click selects the wrong level (shirt vs person)Pick another candidate, or add a second click
Text finds many; you need oneFilter rule (largest, leftmost, nearest), or click instead
Filter picks the wrong one sometimesCombine rules (inside region + largest) or add a score threshold
Clicks land in the wrong place in codeCheck pixel vs normalized coordinates for your interface
Selected object drifts in videoCorrect with a click on that frame. Tracking loses objects

Edges look rough after selecting? Improve mask quality · Then cut it out: background removal

Questions

Selecting Objects FAQ

How do I select just one object with SAM 3?

Click it, or draw a box around it. A text prompt returns every match, so to get one, either click instead, or run text and then keep one result by a rule such as largest, leftmost or nearest to a point.

What do negative clicks do?

A negative click marks an area that must not be in the mask. Use it when the mask spills onto a neighbouring object, like a bag held by a person.

Why does one click give three masks?

A single click can be ambiguous (shirt, person, or person plus bag). SAM returns several candidates ranked by a quality score; keep the best one, or add more clicks to remove the ambiguity.

Can I select “the person on the left” with text?

Not reliably with words alone. Prompt “person”, then pick the leftmost result in code. For complex descriptions, use SAM 3 Agent with a multimodal LLM.

How do I keep only one object in a video?

Click the object on one frame so it gets its own object ID, then propagate; or prompt by text and remove the other IDs.

Is a box or a click better?

A box is quicker for clear, separate objects. Clicks are better for oddly shaped or overlapping objects and for fixing mistakes.

Does SAM 3.1 change how selection works?

No. Prompts are the same; SAM 3.1 makes multi-object video tracking faster.

Keep reading