SAM 3.1 Release (#503)

Summary:
SAM 3.1 multiplex video tracking for the OSS sam3 repository.

Features:
- Multiplex architecture: batch N objects into fixed-capacity buckets for efficient multi-object tracking (16 objects per bucket)
- Unified API: build_sam3_predictor(version="sam3.1") with auto-download from HuggingFace (facebook/sam3.1)
- Flash Attention 3, torch.compile support (~31 FPS compiled on H100)
- Text prompts, point prompts, box prompts, object removal, refinement
- Clean inheritance: Sam3MultiplexBase extends Sam3VideoBase
- Shared base predictor (Sam3BasePredictor) for both SAM3 and SAM3.1

Performance (H100, 5 objects, compiled):
- SAM 3.1: ~31 FPS
- Memory: ~17.7 GB

Usage:
  from sam3 import build_sam3_predictor predictor = build_sam3_predictor()  # auto-downloads SAM 3.1 from HF

Pull Request resolved: https://github.com/facebookresearch/sam3/pull/503

Reviewed By: josephgreer

Differential Revision: D98500763

Pulled By: arpitkalla

fbshipit-source-id: e2b74568f24bb4ecfb3144a4e8ec559aae6db5e8
This commit is contained in:
Arpit Kalla
2026-03-27 10:18:58 -07:00
committed by meta-codesync[bot]
parent 86ed770940
commit 9f22cb976f
79 changed files with 20772 additions and 792 deletions
+15 -15
View File
@@ -158,22 +158,22 @@ def plot_mask(mask, color="r", ax=None):
def normalize_bbox(bbox_xywh, img_w, img_h):
# Assumes bbox_xywh is in XYWH format
if isinstance(bbox_xywh, list):
assert len(bbox_xywh) == 4, (
"bbox_xywh list must have 4 elements. Batching not support except for torch tensors."
)
assert (
len(bbox_xywh) == 4
), "bbox_xywh list must have 4 elements. Batching not support except for torch tensors."
normalized_bbox = bbox_xywh.copy()
normalized_bbox[0] /= img_w
normalized_bbox[1] /= img_h
normalized_bbox[2] /= img_w
normalized_bbox[3] /= img_h
else:
assert isinstance(bbox_xywh, torch.Tensor), (
"Only torch tensors are supported for batching."
)
assert isinstance(
bbox_xywh, torch.Tensor
), "Only torch tensors are supported for batching."
normalized_bbox = bbox_xywh.clone()
assert normalized_bbox.size(-1) == 4, (
"bbox_xywh tensor must have last dimension of size 4."
)
assert (
normalized_bbox.size(-1) == 4
), "bbox_xywh tensor must have last dimension of size 4."
normalized_bbox[..., 0] /= img_w
normalized_bbox[..., 1] /= img_h
normalized_bbox[..., 2] /= img_w
@@ -245,9 +245,9 @@ def visualize_formatted_frame_output(
num_outputs = len(outputs_list)
if titles is None:
titles = [f"Set {i + 1}" for i in range(num_outputs)]
assert len(titles) == num_outputs, (
"length of `titles` should match that of `outputs_list` if not None."
)
assert (
len(titles) == num_outputs
), "length of `titles` should match that of `outputs_list` if not None."
_, axes = plt.subplots(1, num_outputs, figsize=figsize)
if num_outputs == 1:
@@ -703,9 +703,9 @@ def get_all_annotations_for_frame(
# Get the frame
video_df_current = video_df[video_df.id == video_id]
assert len(video_df_current) == 1, (
f"Expected 1 video row, got {len(video_df_current)}"
)
assert (
len(video_df_current) == 1
), f"Expected 1 video row, got {len(video_df_current)}"
video_row = video_df_current.iloc[0]
file_name = video_row.file_names[frame_idx]
file_path = os.path.join(