Skip to main content

Maintained MLX port of SAM 3.1-oriented image segmentation components.

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.0.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.0-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sam3_mlx-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 5c2776db423a5bb8802a6992a18feebbd564a0173ea33260989bb4e327e08ddc
MD5 449412e4fae715f6c456077e29386b35
BLAKE2b-256 a7c79784f69415393e5a99fe20b2fced418c85dff009101e47e023e0e32c6be7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sam3_mlx-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1734354fb5253b8456dd6ae7f39fd8733b5c51a499f6ae798ca0371a6ddc309e
MD5 18b6bd38bdfd2b14cc4e280bbbfd5404
BLAKE2b-256 e2d3a01e388baa8ac227be929116d38d8676318e26711fafe4043d901cb972d3

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