Skip to main content

musclemap-mlx

Segment 113 muscle and bone structures in MRI or CT NIfTI images with MuscleMap v1.4, running natively through MLX and Metal on Apple Silicon. Weights download automatically on first use.

Install and segment

Requires an Apple Silicon Mac, Metal and Python 3.13. With uv:

uv venv --python 3.13
source .venv/bin/activate
uv pip install musclemap-mlx

# Real MRI example from TotalSegmentator's official test data.
curl -L https://raw.githubusercontent.com/wasserth/TotalSegmentator/d89e47f73d24f5fba732a715aeb6fdc0ae34526b/tests/reference_files/example_mr_sm.nii.gz -o mri.nii.gz
musclemap-mlx segment --input mri.nii.gz --output-dir out

The command writes out/mask.nii.gz and prints JSON containing the output path, label table, device, memory use and chunking settings. To use the corresponding CT example, replace example_mr_sm.nii.gz with example_ct_sm.nii.gz.

Python

from musclemap_mlx.medmlx import run

result = run(image_path="mri.nii.gz", output_dir="out-python")
print(result["outputs"]["mask"])

MedMLX

uv pip install 'medmlx[segment]>=0.9.1,<0.10'
medmlx describe musclemap
medmlx setup musclemap
medmlx run musclemap --arg image_path=mri.nii.gz output_dir=out-medmlx

Or use its Python interface:

import medmlx

medmlx.setup_model("musclemap")
job = medmlx.run("musclemap", arguments={
    "image_path": "mri.nii.gz",
    "output_dir": "out-medmlx-python",
})
print(job["result"])

The MCP server exposes the same model through list_models, describe_model, model_readiness, prepare_model and run_model; poll get_job for setup and segmentation results. Start it with medmlx serve --root ..

Inputs and outputs

Input is one finite 3D .nii or .nii.gz MRI or CT volume. Millimetre spatial units are supported; an unspecified unit is interpreted as millimetres, matching upstream. Other declared spatial units and 4D images are rejected.

The output is an int16 mask with background 0 and the original 113 anatomical IDs, including 1101 for left levator scapulae and 8222 for right plantaris. Its shape, affine, qform, sform and spatial-unit metadata follow the input. The largest 6-connected component of each label is retained after chunk assembly. The JSON result lists every anatomical ID and name.

Option Meaning Default
--input 3D NIfTI image Required
--output-dir Destination for mask.nii.gz Required
--model-dir Local folder containing model.safetensors Automatic download/cache
--chunk-size Source storage-axis slices per independent pass Eight
--overlap Gaussian window overlap, integer 0–99 percent 90
--overwrite Replace an existing output Off

Each chunk is independently normalized. For integer source images, chunking also reproduces upstream's source-header NIfTI round trip before normalization. Changing chunk size can change the mask. A chunk size at least the source depth uses one whole-volume pass. Inference uses MLX on Metal; there is no CPU or PyTorch network fallback.

Weights and offline use

The approximately 105 MB float32 bundle is hosted at MedMLX/musclemap-mlx, pinned to revision a798b3073e3b2c449987c13aa193626aaacc3092. It includes the publisher configuration, original label metadata and MIT notices.

# Pre-download to the shared cache; subsequent runs can work offline.
musclemap-mlx download

# Export a local bundle, then supply it explicitly.
musclemap-mlx download --model-dir musclemap-weights
musclemap-mlx segment --input mri.nii.gz --model-dir musclemap-weights --output-dir out-local

MedMLX and this package share the MEDMLX_ASSET_CACHE cache setting. Python callers supply a local bundle with weights_path="musclemap-weights".

Qualification and license

The native implementation was compared with the pinned MuscleMap v1.4 reference on real CT and MRI examples. Reproduction commands, acceptance criteria and measurements are in docs/technical.md. These two compact examples establish implementation parity; anatomical accuracy against manual segmentations and coverage of all 113 structures were not measured.

Code and publisher weights are MIT licensed. See publisher license and attribution. The original checkpoint and configuration are published in Zenodo record 21929873.

Metadata

Release files for musclemap-mlx 0.1.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 musclemap-mlx 0.1.1
File Size Uploaded Provenance Actions
musclemap_mlx-0.1.1.tar.gz 27.5 kB Without provenance Details for musclemap_mlx-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for musclemap-mlx 0.1.1
File Interpreter ABI Platform Actions
musclemap_mlx-0.1.1-py3-none-any.whl Python 3 none any Details for musclemap_mlx-0.1.1-py3-none-any.whl

Total release size: 61.0 kB

Release files / musclemap_mlx-0.1.1.tar.gz

Download URL musclemap_mlx-0.1.1.tar.gz
Size 27.5 kB
Tags Source
SHA-256 checksum
How to use checksums
314d1c32df8b4209d8316efe2b208429852dadb7bf1ab1ee6937b18572b2710c
BLAKE2b-256 checksum
How to use checksums
ae244aa5e6368bd43f9221a55ae9f8c513b2282ec2fb94e99c82bd7fd788868e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / musclemap_mlx-0.1.1-py3-none-any.whl

Download URL musclemap_mlx-0.1.1-py3-none-any.whl
Size 33.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49994577cb4f265dbc8bc12fb50ed03e9fc51210763e1088d1004b976b2abb11
BLAKE2b-256 checksum
How to use checksums
1059ab0ae1c733d24f26076c9785a3efeeb53421a721c4f056f46661c06efa08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for musclemap-mlx 0.1.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.

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