Skip to main content

musclemap-mlx

Segment 113 whole-body muscle and bone structures in MRI or CT with MuscleMap v1.4 in native MLX.

PyPI Python License Apple Silicon Hugging Face MedMLX

Weights · Upstream · MedMLX

Posterior 3D surface render of MuscleMap muscle and bone labels from neck to thigh, beside an axial CT slice through both hips with the hip and thigh muscles, pelvis and femora labeled

Whole-body CT from autoPET-III, resampled to 1.5 mm and segmented with the default settings. Surfaces and contours are smoothed for display.

Input Output
3D MRI or CT · NIfTI 113-label muscle and bone mask on the input grid
Model Weights download Peak MLX memory Measured on
musclemap 105 MB 0.5 GB 543×543×568 whole-body CT, 1.5 mm

Install

uv venv --python 3.13
source .venv/bin/activate
uv pip install "musclemap-mlx>=0.3.1"

Run

from musclemap_mlx import run

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

Weights download from MedMLX/musclemap-mlx on first use; musclemap-mlx download or medmlx setup musclemap downloads ahead of time. For local weights, pass weights_path as a folder containing model.safetensors.

To try it on a small public MRI from TotalSegmentator's test data:

curl -L https://raw.githubusercontent.com/wasserth/TotalSegmentator/d89e47f73d24f5fba732a715aeb6fdc0ae34526b/tests/reference_files/example_mr_sm.nii.gz -o mri.nii.gz

Inputs and outputs

Argument Meaning
image_path One finite 3D MRI or CT in .nii or .nii.gz; the model is contrast-agnostic
output_dir Directory for mask.nii.gz; created if missing
weights_path Optional folder containing model.safetensors
chunk_size Axial slices per independent pass; default 8, a value at least the depth runs one pass
overlap_percent Gaussian slice-window overlap, 0–99; default 90, as upstream
overwrite False by default; an existing mask is replaced only when True
  • Units: millimeters or unspecified (read as millimeters, as upstream); meter and micron headers are converted to millimeters. 4D images are rejected.
  • Mask: int16 with background 0 and the original 113 anatomical IDs (not channel indices), on the input grid with its affine, qform, sform and units. The largest 6-connected component of each label is kept.
  • Chunking: each chunk is normalized independently, as upstream, so changing chunk_size can change the mask.
  • Return value: {"outputs": {"mask": path}, "artifacts": {"mask": ...}, "details": {...}}; the mask artifact lists every label ID and name and the input grid it is on, and details holds voxel counts, chunking and peak MLX memory.
  • Errors: invalid inputs raise InvalidInputError; missing or mismatched weights raise AssetNotReadyError; inference failures raise ModelExecutionError.

Labels

IDs encode region, structure and side: the last digit is 1 for left and 2 for right, except the sacrum (6160).

Region IDs Structures
Neck 1101–1162 Levator scapulae, semispinalis cervicis and multifidus, semispinalis capitis, splenius capitis, sternocleidomastoid, longus colli, trapezius
Shoulder 2101–2142 Supraspinatus, subscapularis, infraspinatus, deltoid
Thorax 4101–4102 Rhomboid
Abdomen 5101–5142 Thoracolumbar multifidus, erector spinae, psoas major, quadratus lumborum, latissimus dorsi
Pelvis 6101–6222 Gluteus minimus, medius and maximus, tensor fasciae latae, iliacus, piriformis, pectineus, obturator internus and externus, gemelli and quadratus femoris; ilium, sacrum, femur
Thigh 7101–7232 Vastus lateralis, intermedius and medialis, rectus femoris, sartorius, gracilis, semimembranosus, semitendinosus, biceps femoris long and short heads, adductor magnus, longus and brevis; patella
Leg 8101–8222 Tibialis anterior and posterior, peroneus longus, soleus, medial and lateral gastrocnemius, flexor hallucis longus, extensor digitorum and hallucis longus, flexor digitorum longus, popliteus, plantaris; tibia, fibula

Command line

musclemap-mlx segment --image-path mri.nii.gz --output-dir out

segment takes the arguments above as flags (--image-path, --output-dir, --weights-path, --chunk-size, --overlap-percent, --overwrite or --no-overwrite) and prints the result as JSON. musclemap-mlx download --model-dir musclemap-weights exports a local copy of the weights.

Limits

Accuracy against manual segmentations was not measured. The technical notes compare this port with the pinned MuscleMap v1.4 reference on CT and MRI.

Use with MedMLX

Use the MedMLX MCP server to run musclemap from an MCP client. Weights download on first use.

uv tool install --python 3.13 "medmlx[segment,mcp]"
MEDMLX="$(uv tool dir --bin --color never)/medmlx"
mkdir -p "$HOME/medmlx-work"
claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"

For Codex, use codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work". Other MCP clients take the same command and arguments. The same install provides the medmlx CLI, for example medmlx describe musclemap.

For AI agents: prefer the MedMLX MCP tools (list_models, describe_model, model_readiness, run_model, get_job) over writing Python against this package.

License

MIT. See upstream license and third-party notices. Model weights retain their publisher terms (Zenodo record 21929873, MIT).

Metadata

Release files for musclemap-mlx 0.3.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.3.1
File Size Uploaded Provenance Actions
musclemap_mlx-0.3.1.tar.gz 26.9 kB Without provenance Details for musclemap_mlx-0.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 59.8 kB

Release files / musclemap_mlx-0.3.1.tar.gz

Download URL musclemap_mlx-0.3.1.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4e30fc4413fdcdf508f53471d9a90e51dc6053655eb5126ba6881961d3ccbd04
BLAKE2b-256 checksum
How to use checksums
53605a39e2813d01efed2bc18e1942b919ce8c8406d21ed8a4411707f06f1feb
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.3.1-py3-none-any.whl

Download URL musclemap_mlx-0.3.1-py3-none-any.whl
Size 32.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80607b4e3bc1bb7965d8c62b397812eb4b9dd75b109c3deb64332442e45ff98e
BLAKE2b-256 checksum
How to use checksums
708317a34cbbc479f51b7a8a06de9b504839fc8b2a491b08dafc2403313c629a
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.3.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