--- 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} } ```