Skip to main content

MLX port of Meta's Segment Anything 3 (SAM 3) for Apple Silicon.

Project description

sam3_mlx

An unofficial Apple MLX port of SAM 3 / SAM 3.1 image-segmentation components for Apple Silicon.

Python Platform Backend License

sam3_mlx brings selected Segment Anything Model 3 (SAM 3 / SAM 3.1) image components to Apple Silicon through Apple's MLX framework.

Table of contents

Features

  • Image segmentation runtime for SAM 3 / SAM 3.1 on Apple Silicon, with output validated against the official SAM 3 image model.
  • Selected-frame video API backed by the image runtime.
  • Clear errors on unsupported paths. Unported surfaces (training, evaluation, multiplex video, Triton) raise Sam3MlxUnsupportedError.

[!NOTE] SAM 3.1 Object Multiplex / video tracking is experimental and incomplete.

Requirements

  • macOS on Apple Silicon (M-series)
  • Python ≥ 3.13
  • MLX ≥ 0.30
  • SAM 3 / SAM 3.1 checkpoints, obtained separately (see Attribution)

Installation

Install from PyPI:

pip install sam3-mlx

Or add it to a project with uv:

uv add sam3-mlx

For local development from a checkout:

uv sync

Plotting dependencies are optional:

pip install "sam3-mlx[viz]"

Or, from a local checkout:

uv sync --extra viz

Checkpoint conversion helpers are included for advanced use, but PyTorch is not installed by a sam3-mlx extra in this release. Use a separate compatible PyTorch environment before running sam3_mlx.convert.

Verify the install:

python -c "import sam3_mlx; print(sam3_mlx.__version__)"

From a local checkout, you can also run:

python -m compileall -q sam3_mlx tests

Quickstart

Image segmentation

from sam3_mlx import build_sam3_image_model
from sam3_mlx.model.sam3_image_processor import Sam3Processor

model = build_sam3_image_model()
processor = Sam3Processor(model, resolution=1008)

Sam3Processor.resolution is the square image size fed into the ViT backbone. It must be a positive multiple of 14 (the image patch size).

[!TIP] Lower the resolution to speed up inference. Any multiple of 14 works. For example, 672 or 504 run faster than the default 1008, at the cost of fine detail.

Selected-frame video

from sam3_mlx import build_sam3_predictor

predictor = build_sam3_predictor(version="sam3")

build_sam3_predictor() defaults to version="sam3.1" to match the official SAM3 API shape. That path routes to the SAM 3.1 multiplex predictor, which runs on MLX with a locally converted checkpoint (checkpoint_path=..., load_from_HF=False); automatic checkpoint download and conversion are not wired up yet, so the default load_from_HF=True raises Sam3MlxUnsupportedError(reason="video-multiplex"). Use version="sam3" for the selected-frame video slice with automatic weights.

The video slice accepts image paths, image folders, PIL image sequences, and OpenCV-decodable video files.

Limitations

Unsupported paths raise Sam3MlxUnsupportedError:

  • Apple Silicon / MLX only. Requesting any non-MLX device is not supported, and neither is torch.compile.
  • Single-prompt image API. Batch geometric prompts and multiple masks per prompt are not supported; single text or geometric prompts work.
  • SAM 3.1 multiplex needs local weights. The multiplex video predictor runs only from a locally converted checkpoint; automatic download/conversion, multi-GPU video, and TorchCodec decoding are unavailable.
  • Training is currently not supported. Training loops, autograd, distributed execution, and the official eval toolkit are not available yet.

Attribution

Portions of this repository are derived from, adapted from, or structured for parity with the official SAM3 implementation (facebookresearch/sam3). Original SAM materials are copyright Meta Platforms, Inc. and are distributed under the SAM License.

This repository does not ship official Meta checkpoint weights or converted SAM checkpoint weights. Obtain the official checkpoints from Hugging Face (facebook/sam3 and facebook/sam3.1), then comply with the SAM License and any applicable access terms.

License

Distributed under the SAM License; see LICENSE. Not affiliated with or endorsed by Meta.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sam3_mlx-0.1.1.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sam3_mlx-0.1.1-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file sam3_mlx-0.1.1.tar.gz.

File metadata

  • Download URL: sam3_mlx-0.1.1.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sam3_mlx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 167142749ab109ca3bd0e2dce1a1678b61a0e02a664ac77713bb88d13229bec1
MD5 feb666c417da62f1b0e948e4929f8c17
BLAKE2b-256 65f7d5fb0f76070d26e4060b77394aec262cb5c03bfd0efb479fed578e8d7cf2

See more details on using hashes here.

File details

Details for the file sam3_mlx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sam3_mlx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sam3_mlx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 797eff3053106775bb09b9cacbdabdcf57148df4ce4b0db16475bcb96a4a2f8f
MD5 881d06569e41a754f590679b1f6e0da9
BLAKE2b-256 29a9ddac87c450ab70bbf230a1385953102fe76a4824fee9e4b7d89603c258b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page