segresnet-mlx 0.3.4__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. segresnet_mlx-0.4.0/PKG-INFO +166 -0
  2. segresnet_mlx-0.4.0/README.md +126 -0
  3. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/pyproject.toml +4 -6
  4. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/__init__.py +1 -1
  5. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/medmlx.py +87 -398
  6. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/predictor.py +31 -1
  7. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/transforms.py +32 -129
  8. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/weights.py +10 -4
  9. segresnet_mlx-0.3.4/PKG-INFO +0 -194
  10. segresnet_mlx-0.3.4/README.md +0 -154
  11. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/.gitignore +0 -0
  12. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/LICENSE +0 -0
  13. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/THIRD_PARTY_NOTICES.md +0 -0
  14. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_arrays.py +0 -0
  15. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_nifti.py +0 -0
  16. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_records.py +0 -0
  17. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_runtime.py +0 -0
  18. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_types.py +0 -0
  19. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/inference.py +0 -0
  20. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/network.py +0 -0
  21. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/py.typed +0 -0
  22. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/telemetry.py +0 -0
  23. {segresnet_mlx-0.3.4 → segresnet_mlx-0.4.0}/src/segresnet_mlx/topology.py +0 -0
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.5
2
+ Name: segresnet-mlx
3
+ Version: 0.4.0
4
+ Summary: Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT with MONAI SegResNet in native MLX
5
+ Project-URL: Homepage, https://medmlx.org
6
+ Project-URL: Documentation, https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/README.md
7
+ Project-URL: Repository, https://github.com/MedMLX/segresnet-mlx
8
+ Project-URL: Issues, https://github.com/MedMLX/segresnet-mlx/issues
9
+ Project-URL: Weights, https://huggingface.co/models?author=MedMLX&search=segresnet
10
+ Project-URL: MedMLX, https://github.com/MedMLX/medmlx
11
+ Author: Joseph Sandoval, Alfredo Sandoval Jr.
12
+ License-Expression: Apache-2.0
13
+ License-File: LICENSE
14
+ License-File: THIRD_PARTY_NOTICES.md
15
+ Keywords: apple-silicon,ct,kidney,medical-imaging,metal,mlx,monai,segmentation,segresnet
16
+ Classifier: Development Status :: 4 - Beta
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: Science/Research
19
+ Classifier: Operating System :: MacOS :: MacOS X
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3 :: Only
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
25
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
26
+ Requires-Python: <3.14,>=3.13
27
+ Requires-Dist: medmlx-core<0.3,>=0.2.6
28
+ Requires-Dist: mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'
29
+ Requires-Dist: nibabel<6,>=5.3
30
+ Requires-Dist: numpy<3,>=2.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: hypothesis<7,>=6; extra == 'dev'
33
+ Requires-Dist: monai==1.6.1; extra == 'dev'
34
+ Requires-Dist: pyright==1.1.414; extra == 'dev'
35
+ Requires-Dist: pytest<10,>=8.4; extra == 'dev'
36
+ Requires-Dist: pytorch-ignite<0.6,>=0.4.11; extra == 'dev'
37
+ Requires-Dist: ruff<1,>=0.13; extra == 'dev'
38
+ Requires-Dist: torch<3,>=2.6; extra == 'dev'
39
+ Description-Content-Type: text/markdown
40
+
41
+ <div align="center">
42
+
43
+ # segresnet-mlx
44
+
45
+ Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT with MONAI SegResNet and native MLX.
46
+
47
+ [![PyPI](https://img.shields.io/pypi/v/segresnet-mlx)](https://pypi.org/project/segresnet-mlx/)
48
+ [![Python](https://img.shields.io/pypi/pyversions/segresnet-mlx)](https://pypi.org/project/segresnet-mlx/)
49
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/LICENSE)
50
+ [![Apple Silicon](https://img.shields.io/badge/Apple_Silicon-MLX-black?logo=apple)](https://github.com/ml-explore/mlx)
51
+ [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97_Hugging_Face-weights-yellow)](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
52
+ [![MedMLX](https://img.shields.io/badge/MedMLX-runtime-A51C30)](https://github.com/MedMLX/medmlx)
53
+
54
+ [Weights](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx) · [Upstream bundle](https://github.com/Project-MONAI/model-zoo/tree/dev/models/renalStructures_CECT_segmentation) · [MedMLX](https://github.com/MedMLX/medmlx)
55
+
56
+ </div>
57
+
58
+ | Input | Output |
59
+ | :--- | :--- |
60
+ | Arterial, venous and excretory CT · NIfTI | Renal labels on the input grid |
61
+
62
+ | Model | Weights download | Peak MLX memory | Measured on |
63
+ | :--- | ---: | ---: | :--- |
64
+ | `segresnet-renal-cect` | 76 MB | 4.0 GB | 478×277×161 three-phase CT |
65
+
66
+ ## Install
67
+
68
+ ```bash
69
+ uv venv --python 3.13
70
+ source .venv/bin/activate
71
+ uv pip install "segresnet-mlx>=0.4.0"
72
+ ```
73
+
74
+ ## Run
75
+
76
+ ```python
77
+ from segresnet_mlx.medmlx import renal_cect
78
+
79
+ result = renal_cect(
80
+ arterial_path="arterial.nii.gz",
81
+ venous_path="venous.nii.gz",
82
+ excretory_path="excretory.nii.gz",
83
+ output_dir="out",
84
+ )
85
+ print(result["outputs"]["mask"])
86
+ ```
87
+
88
+ Weights download from [`MedMLX/segresnet-renal-cect-mlx`](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
89
+ on first use; `medmlx setup segresnet-renal-cect` downloads ahead of time. For local
90
+ weights, pass `weights_path` as a folder containing `segresnet-renal-cect.safetensors`
91
+ or as the file itself.
92
+
93
+ ### Inputs and outputs
94
+
95
+ | Argument | Meaning |
96
+ | --- | --- |
97
+ | `arterial_path`, `venous_path`, `excretory_path` | Arterial, venous and excretory CT in NIfTI, on one voxel grid |
98
+ | `output_dir` | Directory for `renalStructures_CECT_segmentation_mask.nii.gz`; created if missing |
99
+ | `weights_path` | Optional `.safetensors` file or a folder containing it |
100
+ | `overwrite` | `False` by default; an existing mask is replaced only when `True` |
101
+ | `arithmetic_profile` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48` |
102
+ | `streaming` | `False` by default; `True` keeps blending intermediates and logits in temporary mapped files |
103
+ | `scratch_dir` | Parent directory for the streaming files; defaults to the system temporary directory |
104
+
105
+ Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or
106
+ unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
107
+
108
+ The mask is float32 with labels 1 artery, 2 vein, 3 ureter, 4 neoplasm and
109
+ 5 parenchyma; where classes overlap, the lower label wins.
110
+
111
+ | `arithmetic_profile` | Arithmetic |
112
+ | :--- | :--- |
113
+ | `torch-order-fp32` (default) | The default float32 profile |
114
+ | `compensated-fp32` | Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
115
+ | `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
116
+
117
+ The runner returns `{"outputs": {"mask": path}, "details": {...}}`, with run metadata in `details`.
118
+ Invalid inputs raise `InvalidInputError`; missing or mismatched weights raise
119
+ `AssetNotReadyError`; inference failures raise `ModelExecutionError`.
120
+
121
+ Streaming files are removed on success and failure. The final label volume stays in
122
+ memory. `run(bundle="renalStructures_CECT_segmentation", weights_path=...)` takes the
123
+ same inputs with an explicit `.safetensors` file.
124
+
125
+ ### Python API
126
+
127
+ ```python
128
+ from pathlib import Path
129
+
130
+ import numpy as np
131
+ from segresnet_mlx import BUNDLE_CONFIGS, SegResNetSpec, forward_patch, load_model, predict_logits
132
+
133
+ spec = SegResNetSpec(3, 6, 32, upsample_mode="deconv") # renal CECT network
134
+ network = load_model(Path("segresnet-renal-cect.safetensors"), spec=spec)
135
+ patch = np.zeros((1, 3, 32, 32, 32), dtype=np.float32)
136
+ logits = forward_patch(network, patch) # float32 NCDHW -> float32 NumPy logits
137
+ config = BUNDLE_CONFIGS["renalStructures_CECT_segmentation"]
138
+ volume_logits = predict_logits(patch, config, network=network) # stitched sliding windows
139
+ ```
140
+
141
+ - `forward_patch` needs spatial sizes divisible by `2 ** len(spec.blocks_up)`.
142
+ - `predict_logits` takes preprocessed arrays of any size and stitches the bundle's
143
+ sliding windows. Neither normalizes intensities, applies activations or maps labels.
144
+ - `load_model` checks tensor names, shapes and finite float32 values against
145
+ `required_shapes(spec)`.
146
+ - `WindowTelemetry` and `BundlePredictor` record bounded progress and timing.
147
+ - Inference requires Apple Silicon with Metal.
148
+
149
+ ## Use with MedMLX
150
+
151
+ Use the [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) to run `segresnet-renal-cect` from an MCP client. Weights download on first use.
152
+
153
+ ```sh
154
+ uv tool install --python 3.13 "medmlx[segment,mcp]"
155
+ MEDMLX="$(uv tool dir --bin --color never)/medmlx"
156
+ mkdir -p "$HOME/medmlx-work"
157
+ claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"
158
+ ```
159
+
160
+ 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`.
161
+
162
+ > **For AI agents:** prefer the MedMLX MCP tools (`list_models`, `describe_model`, `model_readiness`, `run_model`, `get_job`) over writing Python against this package.
163
+
164
+ ## License
165
+
166
+ [Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
@@ -0,0 +1,126 @@
1
+ <div align="center">
2
+
3
+ # segresnet-mlx
4
+
5
+ Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT with MONAI SegResNet and native MLX.
6
+
7
+ [![PyPI](https://img.shields.io/pypi/v/segresnet-mlx)](https://pypi.org/project/segresnet-mlx/)
8
+ [![Python](https://img.shields.io/pypi/pyversions/segresnet-mlx)](https://pypi.org/project/segresnet-mlx/)
9
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/LICENSE)
10
+ [![Apple Silicon](https://img.shields.io/badge/Apple_Silicon-MLX-black?logo=apple)](https://github.com/ml-explore/mlx)
11
+ [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97_Hugging_Face-weights-yellow)](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
12
+ [![MedMLX](https://img.shields.io/badge/MedMLX-runtime-A51C30)](https://github.com/MedMLX/medmlx)
13
+
14
+ [Weights](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx) · [Upstream bundle](https://github.com/Project-MONAI/model-zoo/tree/dev/models/renalStructures_CECT_segmentation) · [MedMLX](https://github.com/MedMLX/medmlx)
15
+
16
+ </div>
17
+
18
+ | Input | Output |
19
+ | :--- | :--- |
20
+ | Arterial, venous and excretory CT · NIfTI | Renal labels on the input grid |
21
+
22
+ | Model | Weights download | Peak MLX memory | Measured on |
23
+ | :--- | ---: | ---: | :--- |
24
+ | `segresnet-renal-cect` | 76 MB | 4.0 GB | 478×277×161 three-phase CT |
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ uv venv --python 3.13
30
+ source .venv/bin/activate
31
+ uv pip install "segresnet-mlx>=0.4.0"
32
+ ```
33
+
34
+ ## Run
35
+
36
+ ```python
37
+ from segresnet_mlx.medmlx import renal_cect
38
+
39
+ result = renal_cect(
40
+ arterial_path="arterial.nii.gz",
41
+ venous_path="venous.nii.gz",
42
+ excretory_path="excretory.nii.gz",
43
+ output_dir="out",
44
+ )
45
+ print(result["outputs"]["mask"])
46
+ ```
47
+
48
+ Weights download from [`MedMLX/segresnet-renal-cect-mlx`](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
49
+ on first use; `medmlx setup segresnet-renal-cect` downloads ahead of time. For local
50
+ weights, pass `weights_path` as a folder containing `segresnet-renal-cect.safetensors`
51
+ or as the file itself.
52
+
53
+ ### Inputs and outputs
54
+
55
+ | Argument | Meaning |
56
+ | --- | --- |
57
+ | `arterial_path`, `venous_path`, `excretory_path` | Arterial, venous and excretory CT in NIfTI, on one voxel grid |
58
+ | `output_dir` | Directory for `renalStructures_CECT_segmentation_mask.nii.gz`; created if missing |
59
+ | `weights_path` | Optional `.safetensors` file or a folder containing it |
60
+ | `overwrite` | `False` by default; an existing mask is replaced only when `True` |
61
+ | `arithmetic_profile` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48` |
62
+ | `streaming` | `False` by default; `True` keeps blending intermediates and logits in temporary mapped files |
63
+ | `scratch_dir` | Parent directory for the streaming files; defaults to the system temporary directory |
64
+
65
+ Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or
66
+ unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
67
+
68
+ The mask is float32 with labels 1 artery, 2 vein, 3 ureter, 4 neoplasm and
69
+ 5 parenchyma; where classes overlap, the lower label wins.
70
+
71
+ | `arithmetic_profile` | Arithmetic |
72
+ | :--- | :--- |
73
+ | `torch-order-fp32` (default) | The default float32 profile |
74
+ | `compensated-fp32` | Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
75
+ | `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
76
+
77
+ The runner returns `{"outputs": {"mask": path}, "details": {...}}`, with run metadata in `details`.
78
+ Invalid inputs raise `InvalidInputError`; missing or mismatched weights raise
79
+ `AssetNotReadyError`; inference failures raise `ModelExecutionError`.
80
+
81
+ Streaming files are removed on success and failure. The final label volume stays in
82
+ memory. `run(bundle="renalStructures_CECT_segmentation", weights_path=...)` takes the
83
+ same inputs with an explicit `.safetensors` file.
84
+
85
+ ### Python API
86
+
87
+ ```python
88
+ from pathlib import Path
89
+
90
+ import numpy as np
91
+ from segresnet_mlx import BUNDLE_CONFIGS, SegResNetSpec, forward_patch, load_model, predict_logits
92
+
93
+ spec = SegResNetSpec(3, 6, 32, upsample_mode="deconv") # renal CECT network
94
+ network = load_model(Path("segresnet-renal-cect.safetensors"), spec=spec)
95
+ patch = np.zeros((1, 3, 32, 32, 32), dtype=np.float32)
96
+ logits = forward_patch(network, patch) # float32 NCDHW -> float32 NumPy logits
97
+ config = BUNDLE_CONFIGS["renalStructures_CECT_segmentation"]
98
+ volume_logits = predict_logits(patch, config, network=network) # stitched sliding windows
99
+ ```
100
+
101
+ - `forward_patch` needs spatial sizes divisible by `2 ** len(spec.blocks_up)`.
102
+ - `predict_logits` takes preprocessed arrays of any size and stitches the bundle's
103
+ sliding windows. Neither normalizes intensities, applies activations or maps labels.
104
+ - `load_model` checks tensor names, shapes and finite float32 values against
105
+ `required_shapes(spec)`.
106
+ - `WindowTelemetry` and `BundlePredictor` record bounded progress and timing.
107
+ - Inference requires Apple Silicon with Metal.
108
+
109
+ ## Use with MedMLX
110
+
111
+ Use the [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) to run `segresnet-renal-cect` from an MCP client. Weights download on first use.
112
+
113
+ ```sh
114
+ uv tool install --python 3.13 "medmlx[segment,mcp]"
115
+ MEDMLX="$(uv tool dir --bin --color never)/medmlx"
116
+ mkdir -p "$HOME/medmlx-work"
117
+ claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"
118
+ ```
119
+
120
+ 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`.
121
+
122
+ > **For AI agents:** prefer the MedMLX MCP tools (`list_models`, `describe_model`, `model_readiness`, `run_model`, `get_job`) over writing Python against this package.
123
+
124
+ ## License
125
+
126
+ [Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
@@ -4,8 +4,8 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "segresnet-mlx"
7
- version = "0.3.4"
8
- description = "Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegResNet models in native MLX"
7
+ version = "0.4.0"
8
+ description = "Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT with MONAI SegResNet in native MLX"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.13,<3.14"
11
11
  classifiers = [
@@ -28,9 +28,8 @@ keywords = [
28
28
  "segresnet",
29
29
  "monai",
30
30
  "segmentation",
31
- "brats",
32
31
  "ct",
33
- "mri",
32
+ "kidney",
34
33
  ]
35
34
  license = "Apache-2.0"
36
35
  license-files = ["LICENSE", "THIRD_PARTY_NOTICES.md"]
@@ -46,12 +45,11 @@ dependencies = [
46
45
  ]
47
46
 
48
47
  [project.entry-points."medmlx.models"]
49
- segresnet-brats = "segresnet_mlx.medmlx:BRATS_MODEL"
50
48
  segresnet-renal-cect = "segresnet_mlx.medmlx:RENAL_CECT_MODEL"
51
49
 
52
50
  [project.urls]
53
51
  Homepage = "https://medmlx.org"
54
- Documentation = "https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/README.md"
52
+ Documentation = "https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/README.md"
55
53
  Repository = "https://github.com/MedMLX/segresnet-mlx"
56
54
  Issues = "https://github.com/MedMLX/segresnet-mlx/issues"
57
55
  Weights = "https://huggingface.co/models?author=MedMLX&search=segresnet"
@@ -19,7 +19,7 @@ if TYPE_CHECKING:
19
19
  from segresnet_mlx.weights import load_model as load_model
20
20
  from segresnet_mlx.weights import required_shapes as required_shapes
21
21
 
22
- __version__ = "0.3.4"
22
+ __version__ = "0.4.0"
23
23
 
24
24
  _EXPORTS = {
25
25
  "BUNDLE_CONFIGS": "segresnet_mlx.predictor",