Instructions to use MedMLX/medsam2-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use MedMLX/medsam2-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download MedMLX/medsam2-mlx --local-dir medsam2-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
File size: 2,281 Bytes
ec043f4 fc3c712 ec043f4 3558996 ec043f4 3558996 ec043f4 3558996 ec043f4 841bcc5 | 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 | ---
license: cc-by-sa-4.0
library_name: mlx
pipeline_tag: image-segmentation
base_model: wanglab/MedSAM2
tags:
- mlx
- medical-imaging
- apple-silicon
- safetensors
- research
---
# MedSAM2 weights for MLX
Five MedSAM2 checkpoints for the `sam2.1_hiera_t512` graph in [medsam2-mlx](https://github.com/MedMLX/medsam2-mlx): `MedSAM2_latest`, `MedSAM2_2411`, `MedSAM2_CTLesion`, `MedSAM2_MRI_LiverLesion`, and `MedSAM2_US_Heart`. Each is a float32 safetensors file.
Converted from [wanglab/MedSAM2](https://huggingface.co/wanglab/MedSAM2) revision `e4a6f35edd7e091619cbc0750f462f1574e23955` without retraining. Original parameter names, shapes, and values are preserved. Credit Jun Ma, Zongxin Yang, Sumin Kim, Bihui Chen, Mohammed Baharoon, Adibvafa Fallahpour, Reza Asakereh, Hongwei Lyu, and Bo Wang for MedSAM2. Cite their [paper](https://arxiv.org/abs/2504.03600).
## Quick start
```bash
uv venv --python 3.13
source .venv/bin/activate
uv pip install "medsam2-mlx>=0.2.8"
uv tool install huggingface-hub
hf download MedMLX/medsam2-mlx --revision 841bcc529f95f33a6bbf11bc87e5be58d485cbc3 --local-dir models
```
Replace the example input paths with your own files.
```python
from medsam2_mlx.medmlx import run
result = run(
image_path='ct.nii.gz',
weights_path='models/MedSAM2_latest.safetensors',
output_dir='outputs',
box_xyxy=[120, 140, 180, 200],
frame_idx=40,
propagation='both',
)
print(result["outputs"])
```
Pass any of the five checkpoint files as `weights_path`. The box and frame are examples; use a box around the target on one slice of your image.
The [upstream model card](https://huggingface.co/wanglab/MedSAM2) identifies the weights as CC BY-SA 4.0 and states that they may only be used for research and education. See the [license terms](https://creativecommons.org/licenses/by-sa/4.0/legalcode.en) and upstream model card. Outputs require human review.
## Citation
If you use MedMLX, please cite the [MedMLX paper](https://doi.org/10.64898/2026.10.28.26366762):
```bibtex
@article{sandoval2026medmlx,
title = {MedMLX: On-Device Medical Imaging AI for Apple Silicon},
author = {Sandoval, A. and Sandoval, J. and Saleem, A.},
journal = {medRxiv},
year = {2026},
doi = {10.64898/2026.10.28.26366762}
}
```
|