File size: 2,047 Bytes
1b7b988
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
language:
- en
pipeline_tag: image-segmentation
tags:
- sam2
- segment-anything
- mlx
- apple-silicon
- video-segmentation
- object-tracking
license: apache-2.0
---

# SAM2.1 MLX Weights

MLX-format weights for [SAM2.1 (Segment Anything Model 2.1)](https://github.com/facebookresearch/sam2) ported to Apple MLX.

## Quick Start

**1. Clone the code:**
```bash
git clone https://github.com/eisneim/sam2.1_mlx.git
cd sam2.1_mlx
pip install mlx opencv-python safetensors numpy
```

**2. Download weights from this repo:**

```bash
# Base Plus (recommended, best quality/speed balance)
huggingface-cli download eisneim/sam2.1_mlx_weights sam2.1_hiera_base_plus.safetensors --local-dir weights/

# Small (faster, slightly lower quality)
huggingface-cli download eisneim/sam2.1_mlx_weights sam2.1_hiera_small.safetensors --local-dir weights/
```

Or manually download the `.safetensors` files and place them in `weights/`.

**3. Run:**

```bash
# Video tracking — click on an object in the first frame
python inference_video.py -i your_video.mp4

# Image segmentation — click on an object
python inference_image.py -i your_image.jpg

# Use the small model
python inference_video.py -i your_video.mp4 --model small
```

## Available Models

| Model | File | Size | Quality | Speed |
|-------|------|------|---------|-------|
| base_plus | `sam2.1_hiera_base_plus.safetensors` | ~300MB | Best | ~130 fps |
| small | `sam2.1_hiera_small.safetensors` | ~150MB | Good | ~200 fps |

## Converting Weights Yourself

If you prefer to convert from the original PyTorch checkpoints:

```bash
# Download PyTorch weights from Meta
wget https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt -P weights/

# Convert to MLX safetensors
python -m src.sam2.convert --src weights/sam2.1_hiera_base_plus.pt --dst weights/sam2.1_hiera_base_plus.safetensors
```

## Links

- **Code:** https://github.com/eisneim/sam2.1_mlx
- **Original SAM2:** https://github.com/facebookresearch/sam2

## License

Apache 2.0 (same as the original SAM2).