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|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: apache-2.0
|
| 4 |
+
license_link: https://huggingface.co/facebook/sam3/blob/main/LICENSE
|
| 5 |
+
base_model:
|
| 6 |
+
- facebook/sam3
|
| 7 |
+
library_name: mlx
|
| 8 |
+
tags:
|
| 9 |
+
- mlx
|
| 10 |
+
- apple-silicon
|
| 11 |
+
- segmentation
|
| 12 |
+
- sam3
|
| 13 |
+
- image-segmentation
|
| 14 |
+
- vision
|
| 15 |
+
language:
|
| 16 |
+
- en
|
| 17 |
+
pipeline_tag: image-segmentation
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# 🎯 MLX SAM3
|
| 21 |
+
|
| 22 |
+
**Segment Anything Model 3 — Native Apple Silicon Implementation**
|
| 23 |
+
|
| 24 |
+
<p align="center">
|
| 25 |
+
<a href="https://github.com/ml-explore/mlx"><img src="https://img.shields.io/badge/MLX-Framework-blue" alt="MLX"></a>
|
| 26 |
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/Python-3.13+-green" alt="Python 3.13+"></a>
|
| 27 |
+
<a href="https://github.com/Deekshith-Dade/mlx_sam3"><img src="https://img.shields.io/badge/GitHub-Repository-black" alt="GitHub"></a>
|
| 28 |
+
</p>
|
| 29 |
+
|
| 30 |
+
This is an **MLX port** of [Meta's SAM3](https://huggingface.co/facebook/sam3) model, optimized for native execution on Apple Silicon (M1/M2/M3/M4) Macs.
|
| 31 |
+
|
| 32 |
+
> 📖 **Learn more**: Check out the [accompanying blog post](https://deekshith.me/blog/mlx-sam3) explaining the SAM3 architecture and this implementation.
|
| 33 |
+
|
| 34 |
+
## Model Description
|
| 35 |
+
|
| 36 |
+
SAM3 (Segment Anything Model 3) is a powerful image segmentation model that can segment objects in images using:
|
| 37 |
+
- **Text prompts** — Describe what you want to segment ("car", "person", "dog")
|
| 38 |
+
- **Box prompts** — Draw bounding boxes to include or exclude regions
|
| 39 |
+
|
| 40 |
+
This MLX port provides native Apple Silicon performance, leveraging Apple's MLX framework for optimized inference on Mac.
|
| 41 |
+
|
| 42 |
+
## Intended Uses
|
| 43 |
+
|
| 44 |
+
- **Interactive image segmentation** on Apple Silicon Macs
|
| 45 |
+
- **Object detection and masking** with text descriptions
|
| 46 |
+
- **Region-based segmentation** using bounding box prompts
|
| 47 |
+
- **Rapid prototyping** of segmentation workflows on Mac
|
| 48 |
+
|
| 49 |
+
## How to Use
|
| 50 |
+
|
| 51 |
+
### Installation
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
# Clone the repository
|
| 55 |
+
git clone https://github.com/Deekshith-Dade/mlx_sam3.git
|
| 56 |
+
cd mlx-sam3
|
| 57 |
+
|
| 58 |
+
# Install with uv (recommended)
|
| 59 |
+
uv sync
|
| 60 |
+
|
| 61 |
+
# Or with pip
|
| 62 |
+
pip install -e .
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
### Python API
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
from PIL import Image
|
| 69 |
+
from sam3 import build_sam3_image_model
|
| 70 |
+
from sam3.model.sam3_image_processor import Sam3Processor
|
| 71 |
+
|
| 72 |
+
# Load model (auto-downloads weights on first run)
|
| 73 |
+
model = build_sam3_image_model()
|
| 74 |
+
processor = Sam3Processor(model, confidence_threshold=0.5)
|
| 75 |
+
|
| 76 |
+
# Load and process an image
|
| 77 |
+
image = Image.open("your_image.jpg")
|
| 78 |
+
state = processor.set_image(image)
|
| 79 |
+
|
| 80 |
+
# Segment with text prompt
|
| 81 |
+
state = processor.set_text_prompt("person", state)
|
| 82 |
+
|
| 83 |
+
# Access results
|
| 84 |
+
masks = state["masks"] # Binary segmentation masks
|
| 85 |
+
boxes = state["boxes"] # Bounding boxes [x0, y0, x1, y1]
|
| 86 |
+
scores = state["scores"] # Confidence scores
|
| 87 |
+
|
| 88 |
+
print(f"Found {len(scores)} objects")
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
### Web Interface
|
| 92 |
+
|
| 93 |
+
Launch the interactive web application:
|
| 94 |
+
|
| 95 |
+
```bash
|
| 96 |
+
cd app && ./run.sh
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
- **Frontend**: http://localhost:3000
|
| 100 |
+
- **API**: http://localhost:8000
|
| 101 |
+
- **API Docs**: http://localhost:8000/docs
|
| 102 |
+
|
| 103 |
+
## Requirements
|
| 104 |
+
|
| 105 |
+
| Requirement | Version | Notes |
|
| 106 |
+
|-------------|---------|-------|
|
| 107 |
+
| **macOS** | 13.0+ | Apple Silicon required (M1/M2/M3/M4) |
|
| 108 |
+
| **Python** | 3.13+ | Required for MLX compatibility |
|
| 109 |
+
| **Node.js** | 18+ | For the web interface (optional) |
|
| 110 |
+
|
| 111 |
+
> ⚠️ **Apple Silicon Only**: This implementation uses MLX, which is optimized exclusively for Apple Silicon.
|
| 112 |
+
|
| 113 |
+
## Model Details
|
| 114 |
+
|
| 115 |
+
- **Architecture**: SAM3 with ViTDet backbone
|
| 116 |
+
- **Framework**: MLX (Apple's machine learning framework)
|
| 117 |
+
- **Weights**: Converted from original PyTorch weights
|
| 118 |
+
- **Model Size**: ~3.5GB
|
| 119 |
+
|
| 120 |
+
## Limitations
|
| 121 |
+
|
| 122 |
+
- Runs **only on Apple Silicon** Macs (M1/M2/M3/M4)
|
| 123 |
+
- Requires macOS 13.0 or later
|
| 124 |
+
- Python 3.13+ required for MLX compatibility
|
| 125 |
+
|
| 126 |
+
## Citation
|
| 127 |
+
|
| 128 |
+
If you use this model, please cite the original SAM3 paper and this MLX implementation:
|
| 129 |
+
|
| 130 |
+
```bibtex
|
| 131 |
+
@misc{mlx-sam3,
|
| 132 |
+
author = {Deekshith Dade},
|
| 133 |
+
title = {MLX SAM3: Native Apple Silicon Implementation},
|
| 134 |
+
year = {2024},
|
| 135 |
+
url = {https://github.com/Deekshith-Dade/mlx_sam3}
|
| 136 |
+
}
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
## Links
|
| 140 |
+
|
| 141 |
+
- **GitHub Repository**: [https://github.com/Deekshith-Dade/mlx_sam3](https://github.com/Deekshith-Dade/mlx_sam3)
|
| 142 |
+
- **Blog Post**: [https://deekshith.me/blog/mlx-sam3](https://deekshith.me/blog/mlx-sam3)
|
| 143 |
+
- **Original SAM3**: [https://huggingface.co/facebook/sam3](https://huggingface.co/facebook/sam3)
|
| 144 |
+
|
| 145 |
+
## Acknowledgments
|
| 146 |
+
|
| 147 |
+
- [Meta AI](https://ai.meta.com/) for the original SAM3 model
|
| 148 |
+
- [Apple MLX Team](https://github.com/ml-explore/mlx) for the MLX framework
|
| 149 |
+
- The open-source community for continuous inspiration
|
| 150 |
+
|
| 151 |
+
---
|
| 152 |
+
|
| 153 |
+
**Built with ❤️ for Apple Silicon**
|
| 154 |
+
|