sam3-mlx 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sam3_mlx-0.1.0/LICENSE +61 -0
- sam3_mlx-0.1.0/MANIFEST.in +15 -0
- sam3_mlx-0.1.0/PKG-INFO +192 -0
- sam3_mlx-0.1.0/README.md +161 -0
- sam3_mlx-0.1.0/pyproject.toml +76 -0
- sam3_mlx-0.1.0/sam3_mlx/__init__.py +55 -0
- sam3_mlx-0.1.0/sam3_mlx/_device.py +2 -0
- sam3_mlx-0.1.0/sam3_mlx/_unsupported.py +363 -0
- sam3_mlx-0.1.0/sam3_mlx/assets/bpe_simple_vocab_16e6.txt.gz +0 -0
- sam3_mlx-0.1.0/sam3_mlx/convert.py +298 -0
- sam3_mlx-0.1.0/sam3_mlx/logger.py +67 -0
- sam3_mlx-0.1.0/sam3_mlx/mlx_runtime.py +85 -0
- sam3_mlx-0.1.0/sam3_mlx/model/__init__.py +1 -0
- sam3_mlx-0.1.0/sam3_mlx/model/act_ckpt_utils.py +36 -0
- sam3_mlx-0.1.0/sam3_mlx/model/box_ops.py +228 -0
- sam3_mlx-0.1.0/sam3_mlx/model/data_misc.py +362 -0
- sam3_mlx-0.1.0/sam3_mlx/model/decoder.py +1496 -0
- sam3_mlx-0.1.0/sam3_mlx/model/edt.py +138 -0
- sam3_mlx-0.1.0/sam3_mlx/model/encoder.py +506 -0
- sam3_mlx-0.1.0/sam3_mlx/model/geometry_encoders.py +830 -0
- sam3_mlx-0.1.0/sam3_mlx/model/grid_sample_mlx.py +198 -0
- sam3_mlx-0.1.0/sam3_mlx/model/io_utils.py +734 -0
- sam3_mlx-0.1.0/sam3_mlx/model/maskformer_segmentation.py +388 -0
- sam3_mlx-0.1.0/sam3_mlx/model/memory.py +222 -0
- sam3_mlx-0.1.0/sam3_mlx/model/model_misc.py +1162 -0
- sam3_mlx-0.1.0/sam3_mlx/model/multiplex_mask_decoder.py +512 -0
- sam3_mlx-0.1.0/sam3_mlx/model/multiplex_utils.py +459 -0
- sam3_mlx-0.1.0/sam3_mlx/model/necks.py +321 -0
- sam3_mlx-0.1.0/sam3_mlx/model/position_encoding.py +111 -0
- sam3_mlx-0.1.0/sam3_mlx/model/roi_align.py +198 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam1_task_predictor.py +441 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_base_predictor.py +270 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_image.py +777 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_image_processor.py +587 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_multiplex_base.py +4330 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_multiplex_detector.py +764 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_multiplex_detector_utils.py +641 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_multiplex_tracking.py +3067 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_multiplex_video_predictor.py +43 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_tracker_base.py +1012 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_tracker_utils.py +465 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_tracking_predictor.py +1461 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_video_base.py +565 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_video_inference.py +675 -0
- sam3_mlx-0.1.0/sam3_mlx/model/sam3_video_predictor.py +151 -0
- sam3_mlx-0.1.0/sam3_mlx/model/text_encoder_ve.py +324 -0
- sam3_mlx-0.1.0/sam3_mlx/model/tokenizer_ve.py +248 -0
- sam3_mlx-0.1.0/sam3_mlx/model/utils/__init__.py +43 -0
- sam3_mlx-0.1.0/sam3_mlx/model/utils/misc.py +116 -0
- sam3_mlx-0.1.0/sam3_mlx/model/utils/sam1_utils.py +94 -0
- sam3_mlx-0.1.0/sam3_mlx/model/utils/sam2_utils.py +240 -0
- sam3_mlx-0.1.0/sam3_mlx/model/video_tracking_multiplex.py +3176 -0
- sam3_mlx-0.1.0/sam3_mlx/model/video_tracking_multiplex_demo.py +1508 -0
- sam3_mlx-0.1.0/sam3_mlx/model/vitdet.py +823 -0
- sam3_mlx-0.1.0/sam3_mlx/model/vl_combiner.py +354 -0
- sam3_mlx-0.1.0/sam3_mlx/model_builder.py +2729 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/__init__.py +7 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/associate_det_trk.py +112 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/compile.py +107 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/connected_components.py +125 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/fa3.py +101 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/fused.py +19 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/iou.py +152 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/masks_ops.py +199 -0
- sam3_mlx-0.1.0/sam3_mlx/perflib/nms.py +160 -0
- sam3_mlx-0.1.0/sam3_mlx/rle.py +244 -0
- sam3_mlx-0.1.0/sam3_mlx/sam/__init__.py +51 -0
- sam3_mlx-0.1.0/sam3_mlx/sam/common.py +66 -0
- sam3_mlx-0.1.0/sam3_mlx/sam/mask_decoder.py +275 -0
- sam3_mlx-0.1.0/sam3_mlx/sam/prompt_encoder.py +159 -0
- sam3_mlx-0.1.0/sam3_mlx/sam/rope.py +165 -0
- sam3_mlx-0.1.0/sam3_mlx/sam/transformer.py +266 -0
- sam3_mlx-0.1.0/sam3_mlx/visualization_utils.py +636 -0
- sam3_mlx-0.1.0/sam3_mlx.egg-info/PKG-INFO +192 -0
- sam3_mlx-0.1.0/sam3_mlx.egg-info/SOURCES.txt +77 -0
- sam3_mlx-0.1.0/sam3_mlx.egg-info/dependency_links.txt +1 -0
- sam3_mlx-0.1.0/sam3_mlx.egg-info/requires.txt +9 -0
- sam3_mlx-0.1.0/sam3_mlx.egg-info/top_level.txt +1 -0
- sam3_mlx-0.1.0/setup.cfg +4 -0
sam3_mlx-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
SAM License
|
|
2
|
+
Last Updated: November 19, 2025
|
|
3
|
+
|
|
4
|
+
“Agreement” means the terms and conditions for use, reproduction, distribution and modification of the SAM Materials set forth herein.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
“SAM Materials” means, collectively, Documentation and the models, software and algorithms, including machine-learning model code, trained model weights, inference-enabling code, training-enabling code, fine-tuning enabling code, and other elements of the foregoing distributed by Meta and made available under this Agreement.
|
|
8
|
+
|
|
9
|
+
“Documentation” means the specifications, manuals and documentation accompanying
|
|
10
|
+
SAM Materials distributed by Meta.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
“Licensee” or “you” means you, or your employer or any other person or entity (if you are entering into this Agreement on such person or entity’s behalf), of the age required under applicable laws, rules or regulations to provide legal consent and that has legal authority to bind your employer or such other person or entity if you are entering in this Agreement on their behalf.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
“Meta” or “we” means Meta Platforms Ireland Limited (if you are located in or, if you are an entity, your principal place of business is in the EEA or Switzerland) or Meta Platforms, Inc. (if you are located outside of the EEA or Switzerland).
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
“Sanctions” means any economic or trade sanctions or restrictions administered or enforced by the United States (including the Office of Foreign Assets Control of the U.S. Department of the Treasury (“OFAC”), the U.S. Department of State and the U.S. Department of Commerce), the United Nations, the European Union, or the United Kingdom.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
“Trade Controls” means any of the following: Sanctions and applicable export and import controls.
|
|
23
|
+
|
|
24
|
+
By using or distributing any portion or element of the SAM Materials, you agree to be bound by this Agreement.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
1. License Rights and Redistribution.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
a. Grant of Rights. You are granted a non-exclusive, worldwide, non-transferable and royalty-free limited license under Meta’s intellectual property or other rights owned by Meta embodied in the SAM Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the SAM Materials.
|
|
31
|
+
|
|
32
|
+
b. Redistribution and Use.
|
|
33
|
+
i. Distribution of SAM Materials, and any derivative works thereof, are subject to the terms of this Agreement. If you distribute or make the SAM Materials, or any derivative works thereof, available to a third party, you may only do so under the terms of this Agreement and you shall provide a copy of this Agreement with any such SAM Materials.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
ii. If you submit for publication the results of research you perform on, using, or otherwise in connection with SAM Materials, you must acknowledge the use of SAM Materials in your publication.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
iii. Your use of the SAM Materials must comply with applicable laws and regulations, including Trade Control Laws and applicable privacy and data protection laws.
|
|
40
|
+
iv. Your use of the SAM Materials will not involve or encourage others to reverse engineer, decompile or discover the underlying components of the SAM Materials.
|
|
41
|
+
v. You are not the target of Trade Controls and your use of SAM Materials must comply with Trade Controls. You agree not to use, or permit others to use, SAM Materials for any activities subject to the International Traffic in Arms Regulations (ITAR) or end uses prohibited by Trade Controls, including those related to military or warfare purposes, nuclear industries or applications, espionage, or the development or use of guns or illegal weapons.
|
|
42
|
+
2. User Support. Your use of the SAM Materials is done at your own discretion; Meta does not process any information nor provide any service in relation to such use. Meta is under no obligation to provide any support services for the SAM Materials. Any support provided is “as is”, “with all faults”, and without warranty of any kind.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
3. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE SAM MATERIALS AND ANY OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OF ANY KIND, AND META DISCLAIMS ALL WARRANTIES OF ANY KIND, BOTH EXPRESS AND IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE SAM MATERIALS AND ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE SAM MATERIALS AND ANY OUTPUT AND RESULTS.
|
|
46
|
+
|
|
47
|
+
4. Limitation of Liability. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY DIRECT OR INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF ANY OF THE FOREGOING.
|
|
48
|
+
|
|
49
|
+
5. Intellectual Property.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
a. Subject to Meta’s ownership of SAM Materials and derivatives made by or for Meta, with respect to any derivative works and modifications of the SAM Materials that are made by you, as between you and Meta, you are and will be the owner of such derivative works and modifications.
|
|
53
|
+
|
|
54
|
+
b. If you institute litigation or other proceedings against Meta or any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the SAM Materials, outputs or results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other rights owned or licensable by you, then any licenses granted to you under this Agreement shall terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold harmless Meta from and against any claim by any third party arising out of or related to your use or distribution of the SAM Materials.
|
|
55
|
+
|
|
56
|
+
6. Term and Termination. The term of this Agreement will commence upon your acceptance of this Agreement or access to the SAM Materials and will continue in full force and effect until terminated in accordance with the terms and conditions herein. Meta may terminate this Agreement if you are in breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete and cease use of the SAM Materials. Sections 3, 4 and 7 shall survive the termination of this Agreement.
|
|
57
|
+
|
|
58
|
+
7. Governing Law and Jurisdiction. This Agreement will be governed and construed under the laws of the State of California without regard to choice of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this Agreement. The courts of California shall have exclusive jurisdiction of any dispute arising out of this Agreement.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
8. Modifications and Amendments. Meta may modify this Agreement from time to time; provided that they are similar in spirit to the current version of the Agreement, but may differ in detail to address new problems or concerns. All such changes will be effective immediately. Your continued use of the SAM Materials after any modification to this Agreement constitutes your agreement to such modification. Except as provided in this Agreement, no modification or addition to any provision of this Agreement will be binding unless it is in writing and signed by an authorized representative of both you and Meta.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
prune tests
|
|
2
|
+
prune dev_docs
|
|
3
|
+
prune scripts
|
|
4
|
+
prune examples
|
|
5
|
+
prune third_party
|
|
6
|
+
prune checkpoints
|
|
7
|
+
|
|
8
|
+
prune sam3_mlx/agent
|
|
9
|
+
prune sam3_mlx/eval
|
|
10
|
+
prune sam3_mlx/train
|
|
11
|
+
prune sam3_mlx/perflib/triton
|
|
12
|
+
|
|
13
|
+
global-exclude .DS_Store
|
|
14
|
+
global-exclude __pycache__
|
|
15
|
+
global-exclude *.py[cod]
|
sam3_mlx-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sam3_mlx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Maintained MLX port of SAM 3.1-oriented image segmentation components.
|
|
5
|
+
Author: Alfredo Sandoval
|
|
6
|
+
License-Expression: LicenseRef-SAM
|
|
7
|
+
Project-URL: Homepage, https://github.com/Alfredo-Sandoval/sam3_mlx
|
|
8
|
+
Project-URL: Repository, https://github.com/Alfredo-Sandoval/sam3_mlx
|
|
9
|
+
Project-URL: Issues, https://github.com/Alfredo-Sandoval/sam3_mlx/issues
|
|
10
|
+
Keywords: sam3,segment-anything,segmentation,mlx,apple-silicon,computer-vision
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: ftfy>=6.3.1
|
|
23
|
+
Requires-Dist: huggingface-hub>=1.1.6
|
|
24
|
+
Requires-Dist: mlx>=0.30.0
|
|
25
|
+
Requires-Dist: numpy>=2.3.5
|
|
26
|
+
Requires-Dist: pillow>=12.2.0
|
|
27
|
+
Requires-Dist: regex>=2025.11.3
|
|
28
|
+
Provides-Extra: viz
|
|
29
|
+
Requires-Dist: matplotlib>=3.10.8; extra == "viz"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# sam3_mlx
|
|
33
|
+
|
|
34
|
+
**An unofficial Apple MLX port of SAM 3 / SAM 3.1 image-segmentation components for Apple Silicon.**
|
|
35
|
+
|
|
36
|
+
[](pyproject.toml)
|
|
37
|
+
[](#requirements)
|
|
38
|
+
[](https://github.com/ml-explore/mlx)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
|
|
41
|
+
`sam3_mlx` brings selected Segment Anything Model 3 (SAM 3 / SAM 3.1) image
|
|
42
|
+
components to Apple Silicon through Apple's [MLX](https://github.com/ml-explore/mlx)
|
|
43
|
+
framework.
|
|
44
|
+
|
|
45
|
+
## Table of contents
|
|
46
|
+
|
|
47
|
+
- [Features](#features)
|
|
48
|
+
- [Requirements](#requirements)
|
|
49
|
+
- [Installation](#installation)
|
|
50
|
+
- [Quickstart](#quickstart)
|
|
51
|
+
- [Limitations](#limitations)
|
|
52
|
+
- [Attribution](#attribution)
|
|
53
|
+
- [License](#license)
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- **Image segmentation runtime** for SAM 3 / SAM 3.1 on Apple Silicon, with
|
|
58
|
+
output validated against the official SAM 3 image model.
|
|
59
|
+
- **Selected-frame video API** backed by the image runtime.
|
|
60
|
+
- **Clear errors on unsupported paths.** Unported surfaces (training,
|
|
61
|
+
evaluation, multiplex video, Triton) raise `Sam3MlxUnsupportedError`.
|
|
62
|
+
|
|
63
|
+
> [!NOTE]
|
|
64
|
+
> SAM 3.1 Object Multiplex / video tracking is experimental and incomplete.
|
|
65
|
+
|
|
66
|
+
## Requirements
|
|
67
|
+
|
|
68
|
+
- macOS on Apple Silicon (M-series)
|
|
69
|
+
- Python ≥ 3.13
|
|
70
|
+
- [MLX](https://github.com/ml-explore/mlx) ≥ 0.30
|
|
71
|
+
- SAM 3 / SAM 3.1 checkpoints, obtained separately (see
|
|
72
|
+
[Attribution](#attribution))
|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
Install from PyPI:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install sam3-mlx
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Or add it to a project with [uv](https://docs.astral.sh/uv/):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
uv add sam3-mlx
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For local development from a checkout:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
uv sync
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Plotting dependencies are optional:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pip install "sam3-mlx[viz]"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Or, from a local checkout:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
uv sync --extra viz
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Checkpoint conversion helpers are included for advanced use, but PyTorch is not
|
|
107
|
+
installed by a `sam3-mlx` extra in this release. Use a separate compatible
|
|
108
|
+
PyTorch environment before running `sam3_mlx.convert`.
|
|
109
|
+
|
|
110
|
+
Verify the install:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
python -c "import sam3_mlx; print(sam3_mlx.__version__)"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
From a local checkout, you can also run:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
python -m compileall -q sam3_mlx tests
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Quickstart
|
|
123
|
+
|
|
124
|
+
### Image segmentation
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from sam3_mlx import build_sam3_image_model
|
|
128
|
+
from sam3_mlx.model.sam3_image_processor import Sam3Processor
|
|
129
|
+
|
|
130
|
+
model = build_sam3_image_model()
|
|
131
|
+
processor = Sam3Processor(model, resolution=1008)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`Sam3Processor.resolution` is the square image size fed into the ViT backbone. It
|
|
135
|
+
must be a positive multiple of `14` (the image patch size).
|
|
136
|
+
|
|
137
|
+
> [!TIP]
|
|
138
|
+
> Lower the resolution to speed up inference. Any multiple of `14` works. For
|
|
139
|
+
> example, `672` or `504` run faster than the default `1008`, at the cost of
|
|
140
|
+
> fine detail.
|
|
141
|
+
|
|
142
|
+
### Selected-frame video
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from sam3_mlx import build_sam3_predictor
|
|
146
|
+
|
|
147
|
+
predictor = build_sam3_predictor(version="sam3")
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`build_sam3_predictor()` defaults to `version="sam3.1"` to match the official
|
|
151
|
+
SAM3 API shape. That path routes to the SAM 3.1 multiplex predictor, which runs
|
|
152
|
+
on MLX with a locally converted checkpoint
|
|
153
|
+
(`checkpoint_path=..., load_from_HF=False`); automatic checkpoint download and
|
|
154
|
+
conversion are not wired up yet, so the default `load_from_HF=True` raises
|
|
155
|
+
`Sam3MlxUnsupportedError(reason="video-multiplex")`. Use `version="sam3"` for
|
|
156
|
+
the selected-frame video slice with automatic weights.
|
|
157
|
+
|
|
158
|
+
The video slice accepts image paths, image folders, PIL image sequences, and
|
|
159
|
+
OpenCV-decodable video files.
|
|
160
|
+
|
|
161
|
+
## Limitations
|
|
162
|
+
|
|
163
|
+
Unsupported paths raise `Sam3MlxUnsupportedError`:
|
|
164
|
+
|
|
165
|
+
- **Apple Silicon / MLX only.** Requesting any non-MLX device is not
|
|
166
|
+
supported, and neither is `torch.compile`.
|
|
167
|
+
- **Single-prompt image API.** Batch geometric prompts and multiple masks per
|
|
168
|
+
prompt are not supported; single text or geometric prompts work.
|
|
169
|
+
- **SAM 3.1 multiplex needs local weights.** The multiplex video predictor runs
|
|
170
|
+
only from a locally converted checkpoint; automatic download/conversion,
|
|
171
|
+
multi-GPU video, and TorchCodec decoding are unavailable.
|
|
172
|
+
- **Training is currently not supported.** Training loops, autograd, distributed
|
|
173
|
+
execution, and the official eval toolkit are not available yet.
|
|
174
|
+
|
|
175
|
+
## Attribution
|
|
176
|
+
|
|
177
|
+
Portions of this repository are derived from, adapted from, or structured for
|
|
178
|
+
parity with the official SAM3 implementation
|
|
179
|
+
([`facebookresearch/sam3`](https://github.com/facebookresearch/sam3)). Original
|
|
180
|
+
SAM materials are copyright Meta Platforms, Inc. and are distributed under the
|
|
181
|
+
SAM License.
|
|
182
|
+
|
|
183
|
+
This repository does not ship official Meta checkpoint weights or converted SAM
|
|
184
|
+
checkpoint weights. Obtain the official checkpoints from Hugging Face
|
|
185
|
+
([`facebook/sam3`](https://huggingface.co/facebook/sam3) and
|
|
186
|
+
[`facebook/sam3.1`](https://huggingface.co/facebook/sam3.1)), then comply with
|
|
187
|
+
the SAM License and any applicable access terms.
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
Distributed under the SAM License; see [`LICENSE`](LICENSE). Not affiliated with
|
|
192
|
+
or endorsed by Meta.
|
sam3_mlx-0.1.0/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# sam3_mlx
|
|
2
|
+
|
|
3
|
+
**An unofficial Apple MLX port of SAM 3 / SAM 3.1 image-segmentation components for Apple Silicon.**
|
|
4
|
+
|
|
5
|
+
[](pyproject.toml)
|
|
6
|
+
[](#requirements)
|
|
7
|
+
[](https://github.com/ml-explore/mlx)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
`sam3_mlx` brings selected Segment Anything Model 3 (SAM 3 / SAM 3.1) image
|
|
11
|
+
components to Apple Silicon through Apple's [MLX](https://github.com/ml-explore/mlx)
|
|
12
|
+
framework.
|
|
13
|
+
|
|
14
|
+
## Table of contents
|
|
15
|
+
|
|
16
|
+
- [Features](#features)
|
|
17
|
+
- [Requirements](#requirements)
|
|
18
|
+
- [Installation](#installation)
|
|
19
|
+
- [Quickstart](#quickstart)
|
|
20
|
+
- [Limitations](#limitations)
|
|
21
|
+
- [Attribution](#attribution)
|
|
22
|
+
- [License](#license)
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Image segmentation runtime** for SAM 3 / SAM 3.1 on Apple Silicon, with
|
|
27
|
+
output validated against the official SAM 3 image model.
|
|
28
|
+
- **Selected-frame video API** backed by the image runtime.
|
|
29
|
+
- **Clear errors on unsupported paths.** Unported surfaces (training,
|
|
30
|
+
evaluation, multiplex video, Triton) raise `Sam3MlxUnsupportedError`.
|
|
31
|
+
|
|
32
|
+
> [!NOTE]
|
|
33
|
+
> SAM 3.1 Object Multiplex / video tracking is experimental and incomplete.
|
|
34
|
+
|
|
35
|
+
## Requirements
|
|
36
|
+
|
|
37
|
+
- macOS on Apple Silicon (M-series)
|
|
38
|
+
- Python ≥ 3.13
|
|
39
|
+
- [MLX](https://github.com/ml-explore/mlx) ≥ 0.30
|
|
40
|
+
- SAM 3 / SAM 3.1 checkpoints, obtained separately (see
|
|
41
|
+
[Attribution](#attribution))
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Install from PyPI:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install sam3-mlx
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or add it to a project with [uv](https://docs.astral.sh/uv/):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
uv add sam3-mlx
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For local development from a checkout:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
uv sync
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Plotting dependencies are optional:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install "sam3-mlx[viz]"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Or, from a local checkout:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
uv sync --extra viz
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Checkpoint conversion helpers are included for advanced use, but PyTorch is not
|
|
76
|
+
installed by a `sam3-mlx` extra in this release. Use a separate compatible
|
|
77
|
+
PyTorch environment before running `sam3_mlx.convert`.
|
|
78
|
+
|
|
79
|
+
Verify the install:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
python -c "import sam3_mlx; print(sam3_mlx.__version__)"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
From a local checkout, you can also run:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
python -m compileall -q sam3_mlx tests
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Quickstart
|
|
92
|
+
|
|
93
|
+
### Image segmentation
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from sam3_mlx import build_sam3_image_model
|
|
97
|
+
from sam3_mlx.model.sam3_image_processor import Sam3Processor
|
|
98
|
+
|
|
99
|
+
model = build_sam3_image_model()
|
|
100
|
+
processor = Sam3Processor(model, resolution=1008)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`Sam3Processor.resolution` is the square image size fed into the ViT backbone. It
|
|
104
|
+
must be a positive multiple of `14` (the image patch size).
|
|
105
|
+
|
|
106
|
+
> [!TIP]
|
|
107
|
+
> Lower the resolution to speed up inference. Any multiple of `14` works. For
|
|
108
|
+
> example, `672` or `504` run faster than the default `1008`, at the cost of
|
|
109
|
+
> fine detail.
|
|
110
|
+
|
|
111
|
+
### Selected-frame video
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from sam3_mlx import build_sam3_predictor
|
|
115
|
+
|
|
116
|
+
predictor = build_sam3_predictor(version="sam3")
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`build_sam3_predictor()` defaults to `version="sam3.1"` to match the official
|
|
120
|
+
SAM3 API shape. That path routes to the SAM 3.1 multiplex predictor, which runs
|
|
121
|
+
on MLX with a locally converted checkpoint
|
|
122
|
+
(`checkpoint_path=..., load_from_HF=False`); automatic checkpoint download and
|
|
123
|
+
conversion are not wired up yet, so the default `load_from_HF=True` raises
|
|
124
|
+
`Sam3MlxUnsupportedError(reason="video-multiplex")`. Use `version="sam3"` for
|
|
125
|
+
the selected-frame video slice with automatic weights.
|
|
126
|
+
|
|
127
|
+
The video slice accepts image paths, image folders, PIL image sequences, and
|
|
128
|
+
OpenCV-decodable video files.
|
|
129
|
+
|
|
130
|
+
## Limitations
|
|
131
|
+
|
|
132
|
+
Unsupported paths raise `Sam3MlxUnsupportedError`:
|
|
133
|
+
|
|
134
|
+
- **Apple Silicon / MLX only.** Requesting any non-MLX device is not
|
|
135
|
+
supported, and neither is `torch.compile`.
|
|
136
|
+
- **Single-prompt image API.** Batch geometric prompts and multiple masks per
|
|
137
|
+
prompt are not supported; single text or geometric prompts work.
|
|
138
|
+
- **SAM 3.1 multiplex needs local weights.** The multiplex video predictor runs
|
|
139
|
+
only from a locally converted checkpoint; automatic download/conversion,
|
|
140
|
+
multi-GPU video, and TorchCodec decoding are unavailable.
|
|
141
|
+
- **Training is currently not supported.** Training loops, autograd, distributed
|
|
142
|
+
execution, and the official eval toolkit are not available yet.
|
|
143
|
+
|
|
144
|
+
## Attribution
|
|
145
|
+
|
|
146
|
+
Portions of this repository are derived from, adapted from, or structured for
|
|
147
|
+
parity with the official SAM3 implementation
|
|
148
|
+
([`facebookresearch/sam3`](https://github.com/facebookresearch/sam3)). Original
|
|
149
|
+
SAM materials are copyright Meta Platforms, Inc. and are distributed under the
|
|
150
|
+
SAM License.
|
|
151
|
+
|
|
152
|
+
This repository does not ship official Meta checkpoint weights or converted SAM
|
|
153
|
+
checkpoint weights. Obtain the official checkpoints from Hugging Face
|
|
154
|
+
([`facebook/sam3`](https://huggingface.co/facebook/sam3) and
|
|
155
|
+
[`facebook/sam3.1`](https://huggingface.co/facebook/sam3.1)), then comply with
|
|
156
|
+
the SAM License and any applicable access terms.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
Distributed under the SAM License; see [`LICENSE`](LICENSE). Not affiliated with
|
|
161
|
+
or endorsed by Meta.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sam3_mlx"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Maintained MLX port of SAM 3.1-oriented image segmentation components."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "LicenseRef-SAM"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.13"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Alfredo Sandoval" },
|
|
11
|
+
]
|
|
12
|
+
keywords = [
|
|
13
|
+
"sam3",
|
|
14
|
+
"segment-anything",
|
|
15
|
+
"segmentation",
|
|
16
|
+
"mlx",
|
|
17
|
+
"apple-silicon",
|
|
18
|
+
"computer-vision",
|
|
19
|
+
]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Development Status :: 4 - Beta",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"Intended Audience :: Science/Research",
|
|
24
|
+
"Operating System :: MacOS",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Image Recognition",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"ftfy>=6.3.1",
|
|
32
|
+
"huggingface-hub>=1.1.6",
|
|
33
|
+
"mlx>=0.30.0",
|
|
34
|
+
"numpy>=2.3.5",
|
|
35
|
+
"pillow>=12.2.0",
|
|
36
|
+
"regex>=2025.11.3",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
viz = [
|
|
41
|
+
"matplotlib>=3.10.8",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/Alfredo-Sandoval/sam3_mlx"
|
|
46
|
+
Repository = "https://github.com/Alfredo-Sandoval/sam3_mlx"
|
|
47
|
+
Issues = "https://github.com/Alfredo-Sandoval/sam3_mlx/issues"
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["setuptools>=77", "wheel"]
|
|
51
|
+
build-backend = "setuptools.build_meta"
|
|
52
|
+
|
|
53
|
+
[tool.setuptools.packages.find]
|
|
54
|
+
include = ["sam3_mlx", "sam3_mlx.*"]
|
|
55
|
+
exclude = [
|
|
56
|
+
"sam3_mlx.agent",
|
|
57
|
+
"sam3_mlx.agent.*",
|
|
58
|
+
"sam3_mlx.eval",
|
|
59
|
+
"sam3_mlx.eval.*",
|
|
60
|
+
"sam3_mlx.train",
|
|
61
|
+
"sam3_mlx.train.*",
|
|
62
|
+
"sam3_mlx.perflib.triton",
|
|
63
|
+
"sam3_mlx.perflib.triton.*",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[tool.setuptools.package-data]
|
|
67
|
+
sam3_mlx = ["assets/*.txt.gz"]
|
|
68
|
+
|
|
69
|
+
[tool.pytest.ini_options]
|
|
70
|
+
testpaths = ["tests"]
|
|
71
|
+
pythonpath = ["."]
|
|
72
|
+
norecursedirs = [
|
|
73
|
+
".git",
|
|
74
|
+
".venv",
|
|
75
|
+
"third_party",
|
|
76
|
+
]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"Sam3MlxUnsupportedError",
|
|
7
|
+
"build_tracker",
|
|
8
|
+
"build_sam3_image_model",
|
|
9
|
+
"build_sam3_multiplex_video_model",
|
|
10
|
+
"build_sam3_multiplex_video_predictor",
|
|
11
|
+
"build_sam3_predictor",
|
|
12
|
+
"build_sam3_video_model",
|
|
13
|
+
"build_sam3_video_predictor",
|
|
14
|
+
"download_ckpt_from_hf",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def __getattr__(name: str):
|
|
19
|
+
if name == "Sam3MlxUnsupportedError":
|
|
20
|
+
from sam3_mlx._unsupported import Sam3MlxUnsupportedError
|
|
21
|
+
|
|
22
|
+
return Sam3MlxUnsupportedError
|
|
23
|
+
if name == "build_tracker":
|
|
24
|
+
from sam3_mlx.model_builder import build_tracker
|
|
25
|
+
|
|
26
|
+
return build_tracker
|
|
27
|
+
if name == "build_sam3_image_model":
|
|
28
|
+
from sam3_mlx.model_builder import build_sam3_image_model
|
|
29
|
+
|
|
30
|
+
return build_sam3_image_model
|
|
31
|
+
if name == "build_sam3_multiplex_video_model":
|
|
32
|
+
from sam3_mlx.model_builder import build_sam3_multiplex_video_model
|
|
33
|
+
|
|
34
|
+
return build_sam3_multiplex_video_model
|
|
35
|
+
if name == "build_sam3_multiplex_video_predictor":
|
|
36
|
+
from sam3_mlx.model_builder import build_sam3_multiplex_video_predictor
|
|
37
|
+
|
|
38
|
+
return build_sam3_multiplex_video_predictor
|
|
39
|
+
if name == "build_sam3_predictor":
|
|
40
|
+
from sam3_mlx.model_builder import build_sam3_predictor
|
|
41
|
+
|
|
42
|
+
return build_sam3_predictor
|
|
43
|
+
if name == "build_sam3_video_model":
|
|
44
|
+
from sam3_mlx.model_builder import build_sam3_video_model
|
|
45
|
+
|
|
46
|
+
return build_sam3_video_model
|
|
47
|
+
if name == "build_sam3_video_predictor":
|
|
48
|
+
from sam3_mlx.model_builder import build_sam3_video_predictor
|
|
49
|
+
|
|
50
|
+
return build_sam3_video_predictor
|
|
51
|
+
if name == "download_ckpt_from_hf":
|
|
52
|
+
from sam3_mlx.model_builder import download_ckpt_from_hf
|
|
53
|
+
|
|
54
|
+
return download_ckpt_from_hf
|
|
55
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|