Skip to main content

totalsegmentator-mlx

Segment 117 CT structures with TotalSegmentator v2 in native MLX. Includes standard, fast and coarse modes.

PyPI Python License Apple Silicon Hugging Face MedMLX

Model weights · MedMLX

TotalSegmentator standard-mode (1.5 mm) 3D surfaces and axial CT segmentation

Standard mode (1.5 mm): 3D surfaces from autoPET-III and axial CT from AMOS22. Surfaces and contours are smoothed for display.

Input Output
3D CT · NIfTI Multilabel mask on the input grid

Use with MedMLX

The MedMLX MCP server is the lowest-friction way to use this model. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run totalsegmentator for you.

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

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

Install

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

Run

from totalsegmentator_mlx.medmlx import run

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

Omitting weights_path downloads MedMLX/totalsegmentator-mlx into the shared MedMLX cache on first use; interrupted downloads resume and later runs work offline. With MedMLX installed, medmlx setup totalsegmentator downloads it ahead of time. To use your own copy, pass the downloaded bundle folder as weights_path. details.weights_revision records the downloaded commit, or null for a folder without a MedMLX download record.

Inputs and outputs

Argument Meaning
image_path One finite 3D CT in NIfTI-1 or NIfTI-2, in Hounsfield units
output_dir Directory for mask.nii.gz
weights_path Optional root of the model folders below
mode standard (default, five 1.5 mm parts), fast (3 mm model, upstream --fast) or coarse (6 mm model, upstream --fastest)
prompt Structure names to keep after inference; label IDs stay global
roi_subset Locate these structures, crop to them plus 20 mm and drop other labels
robust_crop Locate roi_subset with the 3 mm model instead of the 6 mm one
body_seg Crop to the Dataset300 body model plus 3 mm
overwrite False by default; an existing mask is never replaced

With roi_subset, standard mode runs only the parts that contain those structures. roi_subset cannot be combined with prompt or body_seg, and robust_crop requires roi_subset. Cropped regions are restored by zero filling; an empty localization returns an empty mask. Spatial units must be millimetres or unspecified.

The mask is a uint8 NIfTI-1 with global labels 1–117 (0 background) on the input grid, with the upstream label table as a header extension. run returns {"outputs": {"mask": path}, "details": {...}}, with the weights revision, mode, arithmetic, folds and label table. Invalid inputs raise InvalidInputError; missing or mismatched weights raise AssetNotReadyError.

Model folders

A local weights_path holds one folder per dataset, each with plans.json, dataset.json and fold_0/checkpoint_final/ containing state.json and weights.safetensors. Only the folders the chosen options use are required, and a single model folder can be passed directly when only that dataset is needed.

Folder Model Used by
291/–295/ five 1.5 mm parts standard
297/ 3 mm total model fast; roi_subset with robust_crop
298/ 6 mm total model coarse; roi_subset
300/ 6 mm body model body_seg

Command line

Download the safetensors model bundle, then segment:

python - <<'PY'
from huggingface_hub import snapshot_download

snapshot_download(
    "MedMLX/totalsegmentator-mlx",
    revision="6c03d6f90ccf53f224c3985cbdecf1eaa96555af",
    local_dir="models",
)
PY
totalsegmentator-mlx predict -i ct.nii.gz -o mask.nii.gz --model-dir models

predict takes the runner options as flags (--mode, --organ for prompt, --roi-subset, --robust-crop, --body-seg, --overwrite) and adds three more: --model-part runs one standard part (organs, vertebrae, cardiac, muscles or ribs), --force-split uses upstream's three overlapping slabs, and --probabilities-path probabilities.npz also exports local-label probabilities for one unsplit, uncropped model. totalsegmentator-mlx labels prints the label IDs.

Python API

from totalsegmentator_mlx import segment

labels = segment("ct.nii.gz", model_dir="models", mode="fast")  # nibabel image, uint8

segment takes the command-line options as keyword arguments, plus an optional output_path. It never downloads weights.

Limits

Only the upstream total CT task is included: Dataset291–295, 297 and 298 with 117 labels, plus the Dataset300 body model for cropping, all 3d_fullres, fold 0, without mirroring. DICOM input, DICOM-SEG and RT-STRUCT output, other upstream tasks (including total_mr and licensed tasks), per-class output files, statistics, radiomics, previews, --remove_small_blobs, --higher_order_resampling, --v1_order, test-time augmentation and training are rejected or absent. Inference needs Apple Silicon with Metal and has no CPU or PyTorch fallback.

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 totalsegmentator-mlx 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for totalsegmentator-mlx 0.1.6
File Size Uploaded Provenance Actions
totalsegmentator_mlx-0.1.6.tar.gz 31.1 kB Without provenance Details for totalsegmentator_mlx-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for totalsegmentator-mlx 0.1.6
File Interpreter ABI Platform Actions
totalsegmentator_mlx-0.1.6-py3-none-any.whl Python 3 none any Details for totalsegmentator_mlx-0.1.6-py3-none-any.whl

Total release size: 69.9 kB

Release files / totalsegmentator_mlx-0.1.6.tar.gz

Download URL totalsegmentator_mlx-0.1.6.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
79b0dc1a42cc33247f43a8b3b4e98114bfb7232f8358d7b48e630010f00b8865
BLAKE2b-256 checksum
How to use checksums
2981d67d10789ab5ab30e7ff31bfe13e9ed2cd1dcbbdfb9fd7e0a9e80a5a44ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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 / totalsegmentator_mlx-0.1.6-py3-none-any.whl

Download URL totalsegmentator_mlx-0.1.6-py3-none-any.whl
Size 38.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5ed8d5647d40c4fcd71360df9a2702faa6cb6764e1d940a2798d78502a732c7
BLAKE2b-256 checksum
How to use checksums
f3b3ba04f36f11790ba70aa4d47c5f731cdcd6a7d582459129ccc12616a0bd8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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 totalsegmentator-mlx 0.1.6

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