Fix · SAM 3 / 3.1 · video tracking
Meta SAM Video Tracking Loses Objects Objects vanish behind obstacles, drift onto neighbours or swap IDs with look-alikes. Learn how SAM handles occlusion, which prompts track best, how to refine a track in a few clicks, and where the model’s real limits are.
Start here
What Kind of Tracking Failure?
| You see | Likely cause | Go to |
|---|---|---|
| Mask disappears after the object goes behind something | Occlusion; not re-acquired | Occlusion |
| Object leaves the frame and isn’t picked up on return | Re-entry with changed look | Occlusion · Refine |
| Weak from the start, fails early | Prompted on a poor frame | Prompts |
| Mask slowly grows onto background or a neighbour | Drift | Refine |
| IDs swap when similar objects cross | Look-alike distractors | ID swaps |
| Returning object gets a new ID | Detected as new | ID swaps |
| Everything breaks at a scene cut | Different shot | Cuts & long videos |
| Lost during fast motion or blur | Large jump between frames | Limitations |
| Nothing tracked at all | Not a tracking problem | Empty masks |
Background
How SAM 3 Keeps Track
Knowing the mechanism explains when it fails and which fix will work.
- Tracker: carries each object forward using a memory of earlier frames, including the frames you prompted.
- Occlusion signal: it predicts whether the object is visible, so a hidden object can have no mask without being dropped.
- Detector: with text or example prompts, finds matches on every frame; matches are linked to tracks by overlap.
- Self-correction: Meta periodically re-prompts the tracker with confident detections (every 16 frames by default in the paper) to recover from temporary failures.
- Clicks you add are stored as strong memories, which is why one correction often fixes the rest of the clip.
Occlusion
Objects Hidden Behind Something
Short, partial occlusions usually recover by themselves. Long or full ones, especially when the object reappears looking different, need help.
Recovers on its own
- Partly hidden for a few frames.
- Reappears looking similar, near where it vanished.
- No similar objects nearby.
Needs a correction
- Fully hidden for a long stretch.
- Turns around, changes pose or lighting while hidden.
- Reappears next to a look-alike, or off-screen and back.
- Fix: on the first frame it’s clearly back, add a positive click with the same object ID, then propagate forward from there.
- Occluder grabbed instead? Add a negative click on the occluder.
- Expect gaps: no mask while hidden is correct behaviour, not an error; fill gaps in post if your use needs it.
Prompts
Prompts That Track Well
A track is only as good as its starting point. Prompt where the object is clearest, then propagate both ways.
- Pick the frame: fully visible, sharp, not overlapping similar objects; it doesn’t need to be frame 0.
- Propagate both ways from that frame (
propagation_direction="both"). - One specific object: click it; text prompts follow every instance and can swap among look-alikes.
- Many of a kind: text or an example box, then remove unwanted IDs.
- Add a second prompt on a frame where the object looks very different (front vs back).
- Prompt basics: select one object in video
Refinement
Refine a Track in a Few Clicks
Corrections are just more prompts for the same object ID on the frames that went wrong.
- 1Scanthe masks for empty frames, sudden size changes and jumps (script).
- 2Go to the first bad frame,not the worst one.
- 3Click:positive on the object; negative on whatever it leaked onto.
- 4Re-propagatefrom that frame forward.
- 5Removeghost or duplicate IDs; repeat until the scan is clean.
ID swaps
Look-Alikes, ID Swaps and New IDs
Similar objects that touch or cross are the hardest case for any tracker.
- Swap after crossing: on the first swapped frame, positive click on the right object and negative on the other, for each affected ID.
- Prompt each look-alike separately with its own ID before they meet.
- Returning object gets a new ID: refine the old ID on the reappearance frame and remove the new one, or link IDs in post-processing.
- Crowds: try SAM 3.1, which Meta reports handles crowded scenes better.
Cuts & long videos
Scene Cuts and Long Videos
SAM 3’s concept task is defined on short clips (up to about 30 seconds in the paper). Edited videos and long recordings need splitting.
Code
Code: Find Bad Frames, Correct, Re-Propagate
find_bad_frames.py
# find_bad_frames.py: flag frames where a track was lost, jumped or leaked
import numpy as np
def iou(a, b):
inter = np.logical_and(a, b).sum()
union = np.logical_or(a, b).sum()
return inter / union if union else 1.0
def find_bad_frames(masks, min_area=50, max_area_change=0.5, min_iou=0.3):
"""masks: {frame_index: bool array} for ONE object id, from propagation."""
flags, prev = {}, None
for f in sorted(masks):
m = np.asarray(masks[f], dtype=bool)
area = int(m.sum())
why = []
if area < min_area:
why.append("lost (empty)")
elif prev is not None and prev.sum() >= min_area:
change = abs(area - prev.sum()) / prev.sum()
if change > max_area_change:
why.append(f"area {'grew' if area > prev.sum() else 'shrank'} {change:.0%}")
if iou(m, prev) < min_iou:
why.append(f"jumped (IoU {iou(m, prev):.2f})")
if why:
flags[f] = why
prev = m
return flags
# flags = find_bad_frames({f: out[1] for f, out in masks_by_frame.items()})
# first_bad = min(flags) if flags else None # correct this frame firstofficial sam3 · correct and re-propagate
# official sam3 video predictor: correct id 1 on its first bad frame, then re-propagate
import torch
def correct(predictor, sid, frame, obj_id, pos, neg=()):
pts = list(pos) + list(neg)
labels = [1] * len(pos) + [0] * len(neg)
predictor.handle_request(dict(
type="add_prompt", session_id=sid, frame_index=frame, obj_id=obj_id,
points=torch.tensor(pts, dtype=torch.float32), # check coordinate scale in the video notebook
point_labels=torch.tensor(labels, dtype=torch.int32)))
correct(predictor, sid, frame=first_bad, obj_id=1, pos=[(0.62, 0.48)], neg=[(0.70, 0.50)])
masks_by_frame = {}
for r in predictor.handle_stream_request(dict(
type="propagate_in_video", session_id=sid,
propagation_direction="forward", start_frame_index=first_bad)):
masks_by_frame[r["frame_index"]] = r["outputs"]
# remove a ghost or duplicate track
predictor.handle_request(dict(type="remove_object", session_id=sid, obj_id=7))official sam3 · prompt mid-clip, propagate both ways
# prompt on the clearest frame and propagate both ways
predictor.handle_request(dict(type="add_prompt", session_id=sid, frame_index=60, text="dog"))
for r in predictor.handle_stream_request(dict(
type="propagate_in_video", session_id=sid,
propagation_direction="both", start_frame_index=60)):
masks_by_frame[r["frame_index"]] = r["outputs"]Transformers · Sam3TrackerVideo correction
# Transformers tracker: add a correction click for object 1 on a later frame, then re-propagate
processor.add_inputs_to_inference_session(
inference_session=session, frame_idx=first_bad, obj_ids=1,
input_points=[[[[220, 280], [300, 260]]]], input_labels=[[[1, 0]]]) # pixels; + and −
for out in model.propagate_in_video_iterator(session):
...ffmpeg · find and split scene cuts
# split at scene cuts, then track each shot separately (re-prompt per shot)
ffmpeg -i input.mp4 -filter:v "select='gt(scene,0.35)',showinfo" -f null - 2>&1 | grep pts_time
# then cut at those times, e.g.:
ffmpeg -i input.mp4 -ss 0 -to 12.4 -c copy shot_01.mp4Request names follow Meta’s video notebook; confirm point coordinate scale and options for your commit. Full pipeline: video segmentation with Python.
Limitations
What SAM 3 Can’t Fully Solve Yet
Some failures are limits of the model, not settings. Plan for them.
| Limit | What to do |
|---|---|
| Fast motion and heavy blur | Higher frame rate source, more corrections, or a motion-aware tracker |
| Many identical objects that interact (herds, crowds, swarms) | Expect ID swaps; correct key frames; post-process identities |
| Long disappearance with big appearance change | Re-prompt on return; link IDs yourself |
| Long videos and edits | Split into shots and chunks |
| Specialised domains (surgery, microscopy) | Fine-tuning or domain-specific SAM extensions |
| Thin, transparent or tiny objects | Higher resolution and corrections; see limitations |
Research add-ons (for example re-prompting with object retrieval, or occlusion-aware memory) improve some of these cases but aren’t part of Meta’s release. Fine-tuning: fine-tune SAM.
Questions
Tracking FAQ
Why does SAM lose an object after it goes behind something?
While hidden, there’s nothing to match. If it comes back looking different or next to a similar object, the tracker may not pick it up again. Add a click on the frame where it reappears, with the same object ID.
How do I fix one bad stretch without redoing the whole video?
Find the first wrong frame, add a positive (and if needed negative) click there for the same object ID, and propagate again from that frame.
Should I prompt with text or with a click?
Text finds and re-detects every instance of a concept, which helps re-acquire objects but can swap identities among look-alikes. A click follows one specific object. For a single important object, click it.
Which frame should I prompt on?
One where the object is fully visible, sharp and not touching similar objects. Then propagate in both directions from there.
Does SAM 3.1 track better than SAM 3?
Meta reports better crowded-scene handling and video segmentation results on 6 of 7 benchmarks; it’s worth trying for scenes with many similar objects.
Why does a returning object get a new ID?
With concept prompts, a reappearing object can be detected as new. Keep IDs consistent by refining with the original ID, or link IDs afterwards in your own code.