Metadata-Version: 2.5
Name: medsam2-mlx
Version: 0.2.3
Summary: Native MLX implementation of MedSAM2
Project-URL: Homepage, https://github.com/MedMLX/medsam2-mlx
Project-URL: Documentation, https://github.com/MedMLX/medsam2-mlx/blob/main/docs/technical.md
Project-URL: Repository, https://github.com/MedMLX/medsam2-mlx
Project-URL: Issues, https://github.com/MedMLX/medsam2-mlx/issues
Author: Joseph Sandoval, Alfredo Sandoval Jr.
License-Expression: Apache-2.0
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
Classifier: Operating System :: MacOS :: MacOS X
Requires-Python: <3.15,>=3.13
Requires-Dist: medmlx-core==0.2.4
Requires-Dist: mlx<0.33,>=0.32.4
Requires-Dist: nibabel<6,>=5.3
Requires-Dist: numpy<3,>=2.0
Requires-Dist: pillow<14,>=13
Requires-Dist: scipy<2,>=1.13
Provides-Extra: conversion
Requires-Dist: torch<3,>=2.6; extra == 'conversion'
Provides-Extra: dev
Requires-Dist: hypothesis<7,>=6.156; extra == 'dev'
Requires-Dist: pyright==1.1.414; extra == 'dev'
Requires-Dist: pytest<10,>=8.4; extra == 'dev'
Requires-Dist: ruff<1,>=0.13; extra == 'dev'
Requires-Dist: simpleitk<3,>=2.5.6; extra == 'dev'
Requires-Dist: torch<3,>=2.6; extra == 'dev'
Provides-Extra: reference
Requires-Dist: hydra-core<2,>=1.3.2; extra == 'reference'
Requires-Dist: iopath<0.2,>=0.1.10; extra == 'reference'
Requires-Dist: opencv-python-headless==5.0.0.93; extra == 'reference'
Requires-Dist: pillow<14,>=13; extra == 'reference'
Requires-Dist: simpleitk<3,>=2.5; extra == 'reference'
Requires-Dist: torch<3,>=2.6; extra == 'reference'
Requires-Dist: tqdm<5,>=4.66; extra == 'reference'
Description-Content-Type: text/markdown

# medsam2-mlx

Segment lesions or organs from a box, point or mask prompt, then track them through a volume with MedSAM2.

[Docs](https://github.com/MedMLX/medsam2-mlx/blob/main/docs/technical.md) · [MedMLX](https://github.com/MedMLX)

![One box prompt → nodule masks propagated across neighboring CT slices.](https://raw.githubusercontent.com/MedMLX/medsam2-mlx/main/docs/showcase.png)

*One box prompt → nodule masks propagated across neighboring CT slices.*

| Input | Output |
| :--- | :--- |
| Scan + slice-level prompt | Tracked masks on the input grid |

**Apple Silicon · Metal · Python 3.13 / 3.14** · [uv](https://docs.astral.sh/uv/)

## Quick start

```bash
uv venv --python 3.13
source .venv/bin/activate
uv pip install medsam2-mlx huggingface-hub
```

Download the converted [MedSAM2 CT lesion weights](https://huggingface.co/MedMLX/medsam2-ct-lesion-mlx), then run:

```python
from huggingface_hub import hf_hub_download
from medsam2_mlx.medmlx import run

weights = hf_hub_download(
    "MedMLX/medsam2-ct-lesion-mlx", "MedSAM2_CTLesion.safetensors",
    revision="22f5e6dc4850a71abf92ef1a8fea0db14c34d460",
)

result = run(
    image_path="ct.nii.gz",
    weights_path=weights,
    output_dir="out",
    box_xyxy=[120, 140, 180, 200],
    frame_idx=40,
    propagation="both",
)
print(result["outputs"])
```

For NIfTI, `frame_idx` uses the third voxel axis. Box and point coordinates use the first two stored voxel axes. Docs cover converting other MedSAM2 checkpoints.

## License

[Apache-2.0](https://github.com/MedMLX/medsam2-mlx/blob/main/LICENSE). See [third-party notices](https://github.com/MedMLX/medsam2-mlx/blob/main/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms; the converted CTLesion bundle is CC-BY-SA-4.0.

For research and education. Outputs require human review.
