Skip to main content

segresnet-mlx

Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT with MONAI SegResNet and native MLX.

PyPI Python License Apple Silicon Hugging Face MedMLX

Weights · Upstream bundle · MedMLX

Input Output
Arterial, venous and excretory CT · NIfTI Renal labels on the input grid
Model Weights download Peak MLX memory Measured on
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.4.0"

Run

from segresnet_mlx.medmlx import renal_cect

result = renal_cect(
    arterial_path="arterial.nii.gz",
    venous_path="venous.nii.gz",
    excretory_path="excretory.nii.gz",
    output_dir="out",
)
print(result["outputs"]["mask"])

Weights download from MedMLX/segresnet-renal-cect-mlx on first use; medmlx setup segresnet-renal-cect downloads ahead of time. For local weights, pass weights_path as a folder containing segresnet-renal-cect.safetensors or as the file itself.

Inputs and outputs

Argument Meaning
arterial_path, venous_path, excretory_path Arterial, venous and excretory CT in NIfTI, on one voxel grid
output_dir Directory for renalStructures_CECT_segmentation_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
streaming False by default; True keeps blending intermediates and logits in temporary mapped files
scratch_dir Parent directory for the streaming files; defaults to the system temporary directory

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.

The mask is float32 with labels 1 artery, 2 vein, 3 ureter, 4 neoplasm and 5 parenchyma; where classes overlap, the lower label wins.

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

The runner returns {"outputs": {"mask": path}, "details": {...}}, with run metadata in details. Invalid inputs raise InvalidInputError; missing or mismatched weights raise AssetNotReadyError; inference failures raise ModelExecutionError.

Streaming files are removed on success and failure. The final label volume stays in memory. run(bundle="renalStructures_CECT_segmentation", weights_path=...) takes the same inputs with an explicit .safetensors file.

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_patch needs spatial sizes divisible by 2 ** len(spec.blocks_up).
  • predict_logits takes preprocessed arrays of any size and stitches the bundle's sliding windows. Neither normalizes intensities, applies activations or maps labels.
  • load_model checks tensor names, shapes and finite float32 values against required_shapes(spec).
  • WindowTelemetry and BundlePredictor record bounded progress and timing.
  • Inference requires Apple Silicon with Metal.

Use with MedMLX

Use the MedMLX MCP server to run 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-renal-cect.

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.4.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 segresnet-mlx 0.4.0
File Size Uploaded Provenance Actions
segresnet_mlx-0.4.0.tar.gz 35.2 kB Without provenance Details for segresnet_mlx-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for segresnet-mlx 0.4.0
File Interpreter ABI Platform Actions
segresnet_mlx-0.4.0-py3-none-any.whl Python 3 none any Details for segresnet_mlx-0.4.0-py3-none-any.whl

Total release size: 77.8 kB

Release files / segresnet_mlx-0.4.0.tar.gz

Download URL segresnet_mlx-0.4.0.tar.gz
Size 35.2 kB
Tags Source
SHA-256 checksum
How to use checksums
04b16328c5696100de4a70d9d224f3d71f46a9a73e9c9f745812753abcfbde72
BLAKE2b-256 checksum
How to use checksums
044221a8a2515164d7e194728b06213a3953df1754bc7897417c53b9ee9a9959
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.4.0-py3-none-any.whl

Download URL segresnet_mlx-0.4.0-py3-none-any.whl
Size 42.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed5a07862598db4eea211ef8605b032b06f3c5b345ec6651fc2c276a09a0f273
BLAKE2b-256 checksum
How to use checksums
0488e0cf0e38ed7489353ae20c046b6f8e200bf48eb2e55be7b8f150a8ed0511
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.4.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