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
source .venv/bin/activate
uv pip install "medsam2-mlx[conversion]" huggingface-hub

Download the MedSAM2 checkpoint and convert it 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.2

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.2
File Size Uploaded Provenance Actions
medsam2_mlx-0.2.2.tar.gz 62.8 kB Without provenance Details for medsam2_mlx-0.2.2.tar.gz

Built distribution (wheel)

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

Total release size: 141.2 kB

Release files / medsam2_mlx-0.2.2.tar.gz

Download URL medsam2_mlx-0.2.2.tar.gz
Size 62.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8e3d3031258443314f68d990357872f2ef515b979fa955c7b103fa0ecd42cb64
BLAKE2b-256 checksum
How to use checksums
ea47cc638ad630c7ffe1a36752869b7b95f28b0c683591f683fba6bf7c9cd581
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.2-py3-none-any.whl

Download URL medsam2_mlx-0.2.2-py3-none-any.whl
Size 78.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93e3179bb833cd5815eae02c09019bdd59e238eb729290cb381cdfa9c3d0ea28
BLAKE2b-256 checksum
How to use checksums
4e3e63baf7f510c4721549c888c33161e07008e34b313a5718a417a4705c9270
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.2

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.2 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