Skip to main content

swin-unetr-mlx

Segment 13 abdominal organs in CT with MONAI SwinUNETR and native MLX.

PyPI Python License Apple Silicon Hugging Face MedMLX

Model weights · MedMLX

Abdominal CT and its native multi-organ segmentation
Input Output
3D abdominal CT · NIfTI Organ 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 swin-unetr 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 swin-unetr.

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 "swin-unetr-mlx>=0.2.6"

Run

from swin_unetr_mlx.medmlx import run

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

Omitting weights_path downloads MedMLX/swin-unetr-mlx into the shared MedMLX cache on first use; interrupted downloads resume and later runs work offline. With MedMLX installed, medmlx setup swin-unetr downloads it ahead of time. To use your own copy, pass a folder containing swinunetr.safetensors as weights_path. Standalone checkpoint-file paths are still accepted. details.weights_revision records the downloaded commit, or null for a folder without a MedMLX download record.

Inputs

Argument Meaning
image_path One 3D abdominal CT in NIfTI, in Hounsfield units
output_dir Output root, created if needed
weights_path Optional .safetensors file or a folder containing it
overwrite False by default; an existing mask is replaced only when True

Voxels must be finite and representable in float32. ITK reads the image: it converts metres and microns to millimetres, assumes millimetres when units are unspecified, and interprets missing or disagreeing qform and sform headers.

Python API

from pathlib import Path

import numpy as np
from swin_unetr_mlx import forward_patch, load_model

network = load_model(Path("swinunetr.safetensors"))
logits = forward_patch(network, np.zeros((1, 1, 96, 96, 96), dtype=np.float32))

forward_patch takes finite float32 Bx1x96x96x96 windows and returns raw Bx14x96x96x96 logits, without file IO, intensity scaling, resampling, softmax or stitching. SwinUNETR(weights, mx=mx) runs on MLX arrays directly. Both default to merging_profile="monai-1.4", the released bundle's repeated patch-merging phases; pass merging_profile="monai-1.6" to compare with MONAI 1.6. load_model checks names, shapes, dtypes, finite values and position-index ranges, not checkpoint identity. Inference needs Apple Silicon with Metal and has no CPU fallback.

Outputs

Following the bundle's SaveImaged layout, ct.nii.gz produces out/ct/ct_trans.nii.gz, with the input shape and the ITK reader's affine. It holds float32 label indices from the bundled BTCV label map:

Index Name
0 background
1 spleen
2 right kidney
3 left kidney
4 gallbladder
5 esophagus
6 liver
7 stomach
8 aorta
9 inferior vena cava
10 portal and splenic veins
11 pancreas
12 right adrenal gland
13 left adrenal gland

run returns {"outputs": {"mask": path}, "details": {...}}, with the labels present, shapes, sliding-window settings, MLX device, peak memory and timings. Invalid inputs raise InvalidInputError; missing or mismatched weights raise AssetNotReadyError; inference failures raise ModelExecutionError; an unsupported host or unavailable Metal raises MissingDependencyError.

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 swin-unetr-mlx 0.2.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 swin-unetr-mlx 0.2.6
File Size Uploaded Provenance Actions
swin_unetr_mlx-0.2.6.tar.gz 30.1 kB Without provenance Details for swin_unetr_mlx-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swin-unetr-mlx 0.2.6
File Interpreter ABI Platform Actions
swin_unetr_mlx-0.2.6-py3-none-any.whl Python 3 none any Details for swin_unetr_mlx-0.2.6-py3-none-any.whl

Total release size: 70.1 kB

Release files / swin_unetr_mlx-0.2.6.tar.gz

Download URL swin_unetr_mlx-0.2.6.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
87f4bad6bd142acf36e40cc7ea63ec7ada71a2ef21184223c0fcb271bcffccfc
BLAKE2b-256 checksum
How to use checksums
e3cb5a01a094998541e24297e0e5477ca9f976958295391fe20db931b7f7a3c5
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 / swin_unetr_mlx-0.2.6-py3-none-any.whl

Download URL swin_unetr_mlx-0.2.6-py3-none-any.whl
Size 40.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
001664f520db2b263fd74a022a220f99003bc1e40f3b53fc3552c38ac6241903
BLAKE2b-256 checksum
How to use checksums
2684b3924a9a66d50b61b0eca33bb1946e3a123c1095755ab93c9ad75e4a5bbf
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 swin-unetr-mlx 0.2.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.

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