segresnet-mlx
Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegResNet models in native MLX.
BraTS weights · Renal weights · MedMLX
| Input | Output |
|---|---|
| MRI sequences or CT volumes | Segmentation on the input grid |
| Model | Weights download | Peak MLX memory | Measured on |
|---|---|---|---|
segresnet-brats |
19 MB | 4.9 GB | 240×240×155 four-sequence brain MRI |
segresnet-renal-cect |
76 MB | 4.0 GB | 478×277×161 three-phase CT |
Install
uv venv --python 3.13
source .venv/bin/activate
uv pip install "segresnet-mlx>=0.3.6"
Run
from segresnet_mlx.medmlx import brats
result = brats(
t1c_path="t1c.nii.gz", t1_path="t1.nii.gz", t2_path="t2.nii.gz",
flair_path="flair.nii.gz", output_dir="out",
)
print(result["outputs"]["mask"])
Models and weights
Each runner selects its bundle internally. Keep each model's input volumes on one voxel grid.
| Model | Runner | Inputs | Weights | Local file |
|---|---|---|---|---|
segresnet-brats |
brats |
t1c_path, t1_path, t2_path, flair_path |
MedMLX/segresnet-brats-mlx |
segresnet-brats.safetensors |
segresnet-renal-cect |
renal_cect |
arterial_path, venous_path, excretory_path |
MedMLX/segresnet-renal-cect-mlx |
segresnet-renal-cect.safetensors |
Weights download on first use; medmlx setup segresnet-brats downloads ahead of time.
For local weights, pass a folder containing the model's local file as weights_path.
The standalone run(bundle=..., weights_path=...) interface remains available for
explicit local checkpoints, including the whole-body CT variants, whose native weights
are published as MedMLX/segresnet-wholebody-mlx.
Inputs and outputs
| Argument | Meaning |
|---|---|
t1c_path, t1_path, t2_path, flair_path |
brats: contrast T1, T1, T2 and FLAIR MRI in NIfTI |
arterial_path, venous_path, excretory_path |
renal_cect: arterial, venous and excretory CT in NIfTI |
output_dir |
Directory for <bundle>_mask.nii.gz; created if missing |
weights_path |
Optional .safetensors file or a folder containing it |
overwrite |
False by default; an existing mask is replaced only when True |
arithmetic_profile |
torch-order-fp32 (default), compensated-fp32 or compensated-fp48 (renal only) |
Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
| Model | Mask dtype | Labels |
|---|---|---|
segresnet-brats |
uint8 | 1 necrotic/non-enhancing tumor core, 2 peritumoral edema, 4 enhancing tumor |
segresnet-renal-cect |
float32 | 1 artery, 2 vein, 3 ureter, 4 neoplasm, 5 parenchyma |
arithmetic_profile |
Arithmetic |
|---|---|
torch-order-fp32 (default) |
The default float32 profile |
compensated-fp32 |
Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
compensated-fp48 |
The pairs carry through the hidden layers and stitching runs in float64 on the host; needs the renal transposed-convolution decoder (renal only) |
run returns {"outputs": {"mask": path}, "details": {...}}, with run metadata in details.
Invalid inputs raise InvalidInputError; missing or mismatched weights raise
AssetNotReadyError; inference failures raise ModelExecutionError.
Whole-body CT and streaming
run takes bundle and a .safetensors file as weights_path:
bundle |
Weights file | Input |
|---|---|---|
brats_mri_segmentation |
segresnet-brats.safetensors |
Four MRI sequences |
renalStructures_CECT_segmentation |
segresnet-renal-cect.safetensors |
Three CT phases |
wholeBody_ct_segmentation (1.5 mm) |
segresnet-wholebody-high.safetensors |
One CT as image_path |
wholeBody_ct_segmentation_lowres (3 mm) |
segresnet-wholebody-low.safetensors |
One CT as image_path |
The whole-body bundles write float32 labels 0–104 from the bundle's channel_def:
| Labels | Structures |
|---|---|
| 1–10 | spleen, kidney_right, kidney_left, gallbladder, liver, stomach, aorta, inferior_vena_cava, portal_vein_and_splenic_vein, pancreas |
| 11–12 | adrenal glands (right, left) |
| 13–17 | lung lobes (upper and lower left, upper, middle and lower right) |
| 18–41 | vertebrae L5–C1 |
| 42–43 | esophagus, trachea |
| 44–49 | heart chambers and pulmonary artery |
| 50 | brain |
| 51–54 | iliac arteries and veins |
| 55 | small bowel |
| 56 | duodenum |
| 57 | colon |
| 58–69 | left ribs 1–12 |
| 70–81 | right ribs 1–12 |
| 82–83 | humerus |
| 84–85 | scapula |
| 86–87 | clavicula |
| 88–89 | femur |
| 90–91 | hip |
| 92–93 | sacrum, face |
| 94–99 | gluteus maximus, medius and minimus |
| 100–101 | autochthon |
| 102–103 | iliopsoas |
| 104 | urinary bladder |
run(..., streaming=True, scratch_dir="scratch") keeps blending intermediates and
logits in temporary mapped files instead of a full in-memory class volume. The files
are removed on success and failure; scratch_dir defaults to the system temporary
directory. The final label volume stays in memory.
Python API
from pathlib import Path
import numpy as np
from segresnet_mlx import BUNDLE_CONFIGS, SegResNetSpec, forward_patch, load_model, predict_logits
spec = SegResNetSpec(3, 6, 32, upsample_mode="deconv") # renal CECT network
network = load_model(Path("segresnet-renal-cect.safetensors"), spec=spec)
patch = np.zeros((1, 3, 32, 32, 32), dtype=np.float32)
logits = forward_patch(network, patch) # float32 NCDHW -> float32 NumPy logits
config = BUNDLE_CONFIGS["renalStructures_CECT_segmentation"]
volume_logits = predict_logits(patch, config, network=network) # stitched sliding windows
forward_patchneeds spatial sizes divisible by2 ** len(spec.blocks_up).predict_logitstakes preprocessed arrays of any size and stitches the bundle's sliding windows. Neither normalizes intensities, applies activations or maps labels.load_modelchecks tensor names, shapes and finite float32 values againstrequired_shapes(spec).WindowTelemetryandBundlePredictorrecord bounded progress and timing.- Inference requires Apple Silicon with Metal.
Use with MedMLX
Use the MedMLX MCP server to run segresnet-brats and segresnet-renal-cect 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 segresnet-brats.
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
Apache-2.0. See third-party notices. Model weights retain their publisher terms.
Metadata
Release files for segresnet-mlx 0.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| segresnet_mlx-0.3.6.tar.gz | 40.3 kB | Without provenance | Details for segresnet_mlx-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| segresnet_mlx-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for segresnet_mlx-0.3.6-py3-none-any.whl |
Total release size: 87.7 kB
Release files / segresnet_mlx-0.3.6.tar.gz
| Download URL | segresnet_mlx-0.3.6.tar.gz |
|---|---|
| Size | 40.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
da101b24476e0ab2a587b851d686998be000cde0aa2ffbe546029b4d3af9e5e1
|
|
BLAKE2b-256 checksum How to use checksums |
00338c89a52bd48b1d3e0de3c4133215cc6bf414802dd4cfbe3bceb922ea7b52
|
| 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 / segresnet_mlx-0.3.6-py3-none-any.whl
| Download URL | segresnet_mlx-0.3.6-py3-none-any.whl |
|---|---|
| Size | 47.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d2c6cf32235c9432a34114c4fed159c2234e086d6c9bfe1833d19c9b21ecf55
|
|
BLAKE2b-256 checksum How to use checksums |
a72dda13e9252bc6248d7a1b06f1e45619fbeef72bd43ed71c3cbc3929a0c606
|
| 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 segresnet-mlx 0.3.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.