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

Coronal whole-body CT and axial slices through the pelvis and both thighs, with MuscleMap labels for the back, gluteal, hip and thigh muscles and the pelvic and femoral bones

Whole-body CT from autoPET-III, resampled to 1.5 mm and segmented with the default settings. 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.2.0"

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: spatial units must be millimetres or unspecified (read as millimetres, as upstream). 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 --input mri.nii.gz --output-dir out

segment takes the runner options as flags (--model-dir for weights_path, --chunk-size, --overlap, --overwrite) and prints the result as JSON. musclemap-mlx download --model-dir musclemap-weights exports a local copy of the weights.

Limits

  • Parity with the pinned MuscleMap v1.4 reference was established on real CT and MRI examples; see technical notes. Accuracy against manual segmentations was not measured here.
  • Inference requires Apple Silicon with Metal.

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

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.2.0
File Size Uploaded Provenance Actions
musclemap_mlx-0.2.0.tar.gz 28.8 kB Without provenance Details for musclemap_mlx-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 63.5 kB

Release files / musclemap_mlx-0.2.0.tar.gz

Download URL musclemap_mlx-0.2.0.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fbfd39e1ff8f5b68ad9cd4aa2ac697e8ab066d42bbf4a60d605adfcfb8b776fe
BLAKE2b-256 checksum
How to use checksums
113775f07d7ba2b0ed9c1f6f070e4828dbec8a709d6c35c6720d5b213e5d0f40
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.2.0-py3-none-any.whl

Download URL musclemap_mlx-0.2.0-py3-none-any.whl
Size 34.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efaa99b9bea01df198ddb98d16abe6f6eac3efc95b1cf08601a935bce22533c1
BLAKE2b-256 checksum
How to use checksums
81ee73ed21001756f2d98235b148fcb41f7ff6397443bae43dd12222161421ec
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.2.0

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