Skip to main content

medsam2-mlx

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

Docs · MedMLX

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

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

Quick start

uv venv --python 3.13 --seed
source .venv/bin/activate
python -m pip install "medsam2-mlx[conversion]==0.2.1" huggingface-hub

The tagged GitHub release is an alternative installation route:

repo="https://github.com/MedMLX/medsam2-mlx.git@v0.2.1"
python -m pip install "medsam2-mlx[conversion] @ git+$repo" huggingface-hub

The package contains code only. Obtain the original checkpoint from wanglab/MedSAM2 under its publisher terms and convert it locally. The MedMLX converted CTLesion bundle remains private because its weight-card terms conflict; no converted weights are distributed here. Download and convert once, then run:

from pathlib import Path

from huggingface_hub import hf_hub_download
from medmlx_core import import_mlx
from medsam2_mlx.conversion import convert_weights

mx = import_mlx()
weights = convert_weights(Path(hf_hub_download("wanglab/MedSAM2", "MedSAM2_CTLesion.pt")))
mx.save_safetensors(
    "MedSAM2_CTLesion.safetensors", {name: mx.array(value) for name, value in weights.items()}
)
from medsam2_mlx.medmlx import run

result = run(
    image_path="ct.nii.gz",
    weights_path="MedSAM2_CTLesion.safetensors",
    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.

License

Apache-2.0. See third-party notices. Model weights retain their publisher terms.

For research and education. Outputs require human review.

Metadata

Release files for medsam2-mlx 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for medsam2-mlx 0.2.1
File Size Uploaded Provenance Actions
medsam2_mlx-0.2.1.tar.gz 62.2 kB Without provenance Details for medsam2_mlx-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for medsam2-mlx 0.2.1
File Interpreter ABI Platform Actions
medsam2_mlx-0.2.1-py3-none-any.whl Python 3 none any Details for medsam2_mlx-0.2.1-py3-none-any.whl

Total release size: 139.9 kB

Release files / medsam2_mlx-0.2.1.tar.gz

Download URL medsam2_mlx-0.2.1.tar.gz
Size 62.2 kB
Tags Source
SHA-256 checksum
How to use checksums
484014d788e7626f824afd30688e0564c2f5ea96e4eeb42a117e4c29d4069ac0
BLAKE2b-256 checksum
How to use checksums
d5e7b2a4056d7fbbc98e8f6dffa636af98953ea1735b64694a864735f4d7c1d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / medsam2_mlx-0.2.1-py3-none-any.whl

Download URL medsam2_mlx-0.2.1-py3-none-any.whl
Size 77.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9ba99252ccd30d7894ae1c9205e4beb885c98f34a832e571632034c9a494d6a
BLAKE2b-256 checksum
How to use checksums
ae836591c855e734e01b3b71c6cf1ca45186897dc6b18120f772330850d685f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for medsam2-mlx 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page