segresnet-mlx 0.4.1__tar.gz → 0.6.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.1 → segresnet_mlx-0.6.0}/PKG-INFO +39 -42
  2. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/README.md +36 -38
  3. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/THIRD_PARTY_NOTICES.md +5 -4
  4. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/pyproject.toml +3 -4
  5. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/__init__.py +7 -4
  6. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/_arrays.py +0 -1
  7. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/_records.py +8 -7
  8. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/_runtime.py +3 -3
  9. segresnet_mlx-0.6.0/src/segresnet_mlx/_types.py +19 -0
  10. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/inference.py +3 -3
  11. segresnet_mlx-0.6.0/src/segresnet_mlx/medmlx.py +469 -0
  12. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/network.py +21 -20
  13. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/predictor.py +92 -44
  14. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/topology.py +2 -2
  15. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/transforms.py +110 -177
  16. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/weights.py +15 -46
  17. segresnet_mlx-0.4.1/src/segresnet_mlx/_nifti.py +0 -121
  18. segresnet_mlx-0.4.1/src/segresnet_mlx/_types.py +0 -53
  19. segresnet_mlx-0.4.1/src/segresnet_mlx/medmlx.py +0 -611
  20. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/.gitignore +0 -0
  21. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/LICENSE +0 -0
  22. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/py.typed +0 -0
  23. {segresnet_mlx-0.4.1 → segresnet_mlx-0.6.0}/src/segresnet_mlx/telemetry.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: segresnet-mlx
3
- Version: 0.4.1
3
+ Version: 0.6.0
4
4
  Summary: Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT with MONAI SegResNet in native MLX
5
5
  Project-URL: Homepage, https://medmlx.org
6
- Project-URL: Documentation, https://github.com/MedMLX/segresnet-mlx/blob/v0.4.1/README.md
6
+ Project-URL: Documentation, https://github.com/MedMLX/segresnet-mlx/blob/v0.6.0/README.md
7
7
  Project-URL: Repository, https://github.com/MedMLX/segresnet-mlx
8
8
  Project-URL: Issues, https://github.com/MedMLX/segresnet-mlx/issues
9
9
  Project-URL: Weights, https://huggingface.co/models?author=MedMLX&search=segresnet
@@ -24,9 +24,8 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
24
  Classifier: Topic :: Scientific/Engineering :: Image Processing
25
25
  Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
26
26
  Requires-Python: <3.14,>=3.13
27
- Requires-Dist: medmlx-core<0.3,>=0.2.6
27
+ Requires-Dist: medmlx-core[nifti]<0.4,>=0.3.2
28
28
  Requires-Dist: mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'
29
- Requires-Dist: nibabel<6,>=5.3
30
29
  Requires-Dist: numpy<3,>=2.0
31
30
  Provides-Extra: dev
32
31
  Requires-Dist: hypothesis<7,>=6; extra == 'dev'
@@ -46,7 +45,7 @@ Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT w
46
45
 
47
46
  [![PyPI](https://img.shields.io/pypi/v/segresnet-mlx)](https://pypi.org/project/segresnet-mlx/)
48
47
  [![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.1/LICENSE)
48
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/MedMLX/segresnet-mlx/blob/v0.6.0/LICENSE)
50
49
  [![Apple Silicon](https://img.shields.io/badge/Apple_Silicon-MLX-black?logo=apple)](https://github.com/ml-explore/mlx)
51
50
  [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97_Hugging_Face-weights-yellow)](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
52
51
  [![MedMLX](https://img.shields.io/badge/MedMLX-runtime-A51C30)](https://github.com/MedMLX/medmlx)
@@ -72,18 +71,20 @@ Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT w
72
71
  ```bash
73
72
  uv venv --python 3.13
74
73
  source .venv/bin/activate
75
- uv pip install "segresnet-mlx>=0.4.1"
74
+ uv pip install "segresnet-mlx>=0.6.0"
76
75
  ```
77
76
 
78
77
  ## Run
79
78
 
80
79
  ```python
81
- from segresnet_mlx.medmlx import renal_cect
82
-
83
- result = renal_cect(
84
- arterial_path="arterial.nii.gz",
85
- venous_path="venous.nii.gz",
86
- excretory_path="excretory.nii.gz",
80
+ from segresnet_mlx import run
81
+
82
+ result = run(
83
+ image_paths={
84
+ "arterial": "arterial.nii.gz",
85
+ "venous": "venous.nii.gz",
86
+ "excretory": "excretory.nii.gz",
87
+ },
87
88
  output_dir="out",
88
89
  )
89
90
  print(result["outputs"]["mask"])
@@ -91,44 +92,41 @@ print(result["outputs"]["mask"])
91
92
 
92
93
  Weights download from [`MedMLX/segresnet-renal-cect-mlx`](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
93
94
  on first use; `medmlx setup segresnet-renal-cect` downloads ahead of time. For local
94
- weights, pass `weights_path` as a folder containing `segresnet-renal-cect.safetensors`
95
- or as the file itself.
95
+ weights, pass `weights_path` as a folder containing `segresnet-renal-cect.safetensors`.
96
96
 
97
97
  ### Inputs and outputs
98
98
 
99
99
  | Argument | Meaning |
100
100
  | --- | --- |
101
- | `arterial_path`, `venous_path`, `excretory_path` | Arterial, venous and excretory CT in NIfTI, on one voxel grid |
102
- | `output_dir` | Directory for `renalStructures_CECT_segmentation_mask.nii.gz`; created if missing |
103
- | `weights_path` | Optional `.safetensors` file or a folder containing it |
101
+ | `image_paths` | `{"arterial": ..., "venous": ..., "excretory": ...}`: CT phases in NIfTI, on one voxel grid |
102
+ | `output_dir` | Directory for `mask.nii.gz`; created if missing |
103
+ | `weights_path` | Optional folder containing `segresnet-renal-cect.safetensors` |
104
104
  | `overwrite` | `False` by default; an existing mask is replaced only when `True` |
105
- | `arithmetic_profile` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48` |
105
+ | `precision` | `source-fp32` (default), `compensated-fp32` or `compensated-fp48` |
106
106
  | `streaming` | `False` by default; `True` keeps blending intermediates and logits in temporary mapped files |
107
107
  | `scratch_dir` | Parent directory for the streaming files; defaults to the system temporary directory |
108
108
 
109
- Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or
110
- unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
111
-
112
- The model was trained on CT cropped to the kidney region. Crop around each kidney,
113
- with a margin of about 15 mm, before running it: on a wider field of view it can label
114
- vertebral bodies or liver as neoplasm.
109
+ - **Field of view:** the model was trained on CT cropped to the kidney region. Crop
110
+ around each kidney with a margin of about 15 mm; on a wider field of view it can
111
+ label vertebral bodies or liver as neoplasm.
112
+ - **Input:** finite 3D volumes on one voxel grid. Meter and micron headers are converted
113
+ to millimeters, and an unspecified unit is taken as millimeters.
114
+ - **Mask:** float32 on the input grid as the reader interprets its header, with labels
115
+ 1 artery, 2 vein, 3 ureter, 4 neoplasm and 5 parenchyma. Where classes overlap, the
116
+ lower label wins.
115
117
 
116
- The mask is float32 with labels 1 artery, 2 vein, 3 ureter, 4 neoplasm and
117
- 5 parenchyma; where classes overlap, the lower label wins.
118
-
119
- | `arithmetic_profile` | Arithmetic |
118
+ | `precision` | Arithmetic |
120
119
  | :--- | :--- |
121
- | `torch-order-fp32` (default) | The default float32 profile |
120
+ | `source-fp32` (default) | The default float32 precision |
122
121
  | `compensated-fp32` | Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
123
122
  | `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
124
123
 
125
- The runner returns `{"outputs": {"mask": path}, "details": {...}}`, with run metadata in `details`.
126
- Invalid inputs raise `InvalidInputError`; missing or mismatched weights raise
127
- `AssetNotReadyError`; inference failures raise `ModelExecutionError`.
128
-
129
- Streaming files are removed on success and failure. The final label volume stays in
130
- memory. `run(bundle="renalStructures_CECT_segmentation", weights_path=...)` takes the
131
- same inputs with an explicit `.safetensors` file.
124
+ - **Return value:** `{"outputs": {"mask": path}, "artifacts": {"mask": ...}, "details": {...}}`.
125
+ The `mask` artifact names the labels and the input grid; `details` holds run metadata.
126
+ - **Errors:** invalid inputs raise `InvalidInputError`; missing or mismatched weights
127
+ raise `AssetNotReadyError`; inference failures raise `ModelExecutionError`.
128
+ - **Streaming:** temporary files are removed on success and failure. The final label
129
+ volume stays in memory.
132
130
 
133
131
  ### Python API
134
132
 
@@ -136,10 +134,10 @@ same inputs with an explicit `.safetensors` file.
136
134
  from pathlib import Path
137
135
 
138
136
  import numpy as np
139
- from segresnet_mlx import BUNDLE_CONFIGS, SegResNetSpec, forward_patch, load_model, predict_logits
137
+ from segresnet_mlx import BUNDLE_CONFIGS, SegResNetSpec, forward_patch, load_network, predict_logits
140
138
 
141
139
  spec = SegResNetSpec(3, 6, 32, upsample_mode="deconv") # renal CECT network
142
- network = load_model(Path("segresnet-renal-cect.safetensors"), spec=spec)
140
+ network = load_network(Path("segresnet-renal-cect.safetensors"), spec=spec)
143
141
  patch = np.zeros((1, 3, 32, 32, 32), dtype=np.float32)
144
142
  logits = forward_patch(network, patch) # float32 NCDHW -> float32 NumPy logits
145
143
  config = BUNDLE_CONFIGS["renalStructures_CECT_segmentation"]
@@ -149,10 +147,9 @@ volume_logits = predict_logits(patch, config, network=network) # stitched slidi
149
147
  - `forward_patch` needs spatial sizes divisible by `2 ** len(spec.blocks_up)`.
150
148
  - `predict_logits` takes preprocessed arrays of any size and stitches the bundle's
151
149
  sliding windows. Neither normalizes intensities, applies activations or maps labels.
152
- - `load_model` checks tensor names, shapes and finite float32 values against
153
- `required_shapes(spec)`.
150
+ - `load_network` checks tensor names, shapes and finite float32 values against
151
+ `required_shapes(spec)` and raises `AssetNotReadyError` on a mismatch.
154
152
  - `WindowTelemetry` and `BundlePredictor` record bounded progress and timing.
155
- - Inference requires Apple Silicon with Metal.
156
153
 
157
154
  ## Use with MedMLX
158
155
 
@@ -171,4 +168,4 @@ For Codex, use `codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-wor
171
168
 
172
169
  ## License
173
170
 
174
- [Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.1/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.1/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
171
+ [Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.6.0/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.6.0/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
@@ -6,7 +6,7 @@ Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT w
6
6
 
7
7
  [![PyPI](https://img.shields.io/pypi/v/segresnet-mlx)](https://pypi.org/project/segresnet-mlx/)
8
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.1/LICENSE)
9
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/MedMLX/segresnet-mlx/blob/v0.6.0/LICENSE)
10
10
  [![Apple Silicon](https://img.shields.io/badge/Apple_Silicon-MLX-black?logo=apple)](https://github.com/ml-explore/mlx)
11
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
12
  [![MedMLX](https://img.shields.io/badge/MedMLX-runtime-A51C30)](https://github.com/MedMLX/medmlx)
@@ -32,18 +32,20 @@ Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT w
32
32
  ```bash
33
33
  uv venv --python 3.13
34
34
  source .venv/bin/activate
35
- uv pip install "segresnet-mlx>=0.4.1"
35
+ uv pip install "segresnet-mlx>=0.6.0"
36
36
  ```
37
37
 
38
38
  ## Run
39
39
 
40
40
  ```python
41
- from segresnet_mlx.medmlx import renal_cect
42
-
43
- result = renal_cect(
44
- arterial_path="arterial.nii.gz",
45
- venous_path="venous.nii.gz",
46
- excretory_path="excretory.nii.gz",
41
+ from segresnet_mlx import run
42
+
43
+ result = run(
44
+ image_paths={
45
+ "arterial": "arterial.nii.gz",
46
+ "venous": "venous.nii.gz",
47
+ "excretory": "excretory.nii.gz",
48
+ },
47
49
  output_dir="out",
48
50
  )
49
51
  print(result["outputs"]["mask"])
@@ -51,44 +53,41 @@ print(result["outputs"]["mask"])
51
53
 
52
54
  Weights download from [`MedMLX/segresnet-renal-cect-mlx`](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
53
55
  on first use; `medmlx setup segresnet-renal-cect` downloads ahead of time. For local
54
- weights, pass `weights_path` as a folder containing `segresnet-renal-cect.safetensors`
55
- or as the file itself.
56
+ weights, pass `weights_path` as a folder containing `segresnet-renal-cect.safetensors`.
56
57
 
57
58
  ### Inputs and outputs
58
59
 
59
60
  | Argument | Meaning |
60
61
  | --- | --- |
61
- | `arterial_path`, `venous_path`, `excretory_path` | Arterial, venous and excretory CT in NIfTI, on one voxel grid |
62
- | `output_dir` | Directory for `renalStructures_CECT_segmentation_mask.nii.gz`; created if missing |
63
- | `weights_path` | Optional `.safetensors` file or a folder containing it |
62
+ | `image_paths` | `{"arterial": ..., "venous": ..., "excretory": ...}`: CT phases in NIfTI, on one voxel grid |
63
+ | `output_dir` | Directory for `mask.nii.gz`; created if missing |
64
+ | `weights_path` | Optional folder containing `segresnet-renal-cect.safetensors` |
64
65
  | `overwrite` | `False` by default; an existing mask is replaced only when `True` |
65
- | `arithmetic_profile` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48` |
66
+ | `precision` | `source-fp32` (default), `compensated-fp32` or `compensated-fp48` |
66
67
  | `streaming` | `False` by default; `True` keeps blending intermediates and logits in temporary mapped files |
67
68
  | `scratch_dir` | Parent directory for the streaming files; defaults to the system temporary directory |
68
69
 
69
- Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or
70
- unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
71
-
72
- The model was trained on CT cropped to the kidney region. Crop around each kidney,
73
- with a margin of about 15 mm, before running it: on a wider field of view it can label
74
- vertebral bodies or liver as neoplasm.
70
+ - **Field of view:** the model was trained on CT cropped to the kidney region. Crop
71
+ around each kidney with a margin of about 15 mm; on a wider field of view it can
72
+ label vertebral bodies or liver as neoplasm.
73
+ - **Input:** finite 3D volumes on one voxel grid. Meter and micron headers are converted
74
+ to millimeters, and an unspecified unit is taken as millimeters.
75
+ - **Mask:** float32 on the input grid as the reader interprets its header, with labels
76
+ 1 artery, 2 vein, 3 ureter, 4 neoplasm and 5 parenchyma. Where classes overlap, the
77
+ lower label wins.
75
78
 
76
- The mask is float32 with labels 1 artery, 2 vein, 3 ureter, 4 neoplasm and
77
- 5 parenchyma; where classes overlap, the lower label wins.
78
-
79
- | `arithmetic_profile` | Arithmetic |
79
+ | `precision` | Arithmetic |
80
80
  | :--- | :--- |
81
- | `torch-order-fp32` (default) | The default float32 profile |
81
+ | `source-fp32` (default) | The default float32 precision |
82
82
  | `compensated-fp32` | Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
83
83
  | `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
84
84
 
85
- The runner returns `{"outputs": {"mask": path}, "details": {...}}`, with run metadata in `details`.
86
- Invalid inputs raise `InvalidInputError`; missing or mismatched weights raise
87
- `AssetNotReadyError`; inference failures raise `ModelExecutionError`.
88
-
89
- Streaming files are removed on success and failure. The final label volume stays in
90
- memory. `run(bundle="renalStructures_CECT_segmentation", weights_path=...)` takes the
91
- same inputs with an explicit `.safetensors` file.
85
+ - **Return value:** `{"outputs": {"mask": path}, "artifacts": {"mask": ...}, "details": {...}}`.
86
+ The `mask` artifact names the labels and the input grid; `details` holds run metadata.
87
+ - **Errors:** invalid inputs raise `InvalidInputError`; missing or mismatched weights
88
+ raise `AssetNotReadyError`; inference failures raise `ModelExecutionError`.
89
+ - **Streaming:** temporary files are removed on success and failure. The final label
90
+ volume stays in memory.
92
91
 
93
92
  ### Python API
94
93
 
@@ -96,10 +95,10 @@ same inputs with an explicit `.safetensors` file.
96
95
  from pathlib import Path
97
96
 
98
97
  import numpy as np
99
- from segresnet_mlx import BUNDLE_CONFIGS, SegResNetSpec, forward_patch, load_model, predict_logits
98
+ from segresnet_mlx import BUNDLE_CONFIGS, SegResNetSpec, forward_patch, load_network, predict_logits
100
99
 
101
100
  spec = SegResNetSpec(3, 6, 32, upsample_mode="deconv") # renal CECT network
102
- network = load_model(Path("segresnet-renal-cect.safetensors"), spec=spec)
101
+ network = load_network(Path("segresnet-renal-cect.safetensors"), spec=spec)
103
102
  patch = np.zeros((1, 3, 32, 32, 32), dtype=np.float32)
104
103
  logits = forward_patch(network, patch) # float32 NCDHW -> float32 NumPy logits
105
104
  config = BUNDLE_CONFIGS["renalStructures_CECT_segmentation"]
@@ -109,10 +108,9 @@ volume_logits = predict_logits(patch, config, network=network) # stitched slidi
109
108
  - `forward_patch` needs spatial sizes divisible by `2 ** len(spec.blocks_up)`.
110
109
  - `predict_logits` takes preprocessed arrays of any size and stitches the bundle's
111
110
  sliding windows. Neither normalizes intensities, applies activations or maps labels.
112
- - `load_model` checks tensor names, shapes and finite float32 values against
113
- `required_shapes(spec)`.
111
+ - `load_network` checks tensor names, shapes and finite float32 values against
112
+ `required_shapes(spec)` and raises `AssetNotReadyError` on a mismatch.
114
113
  - `WindowTelemetry` and `BundlePredictor` record bounded progress and timing.
115
- - Inference requires Apple Silicon with Metal.
116
114
 
117
115
  ## Use with MedMLX
118
116
 
@@ -131,4 +129,4 @@ For Codex, use `codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-wor
131
129
 
132
130
  ## License
133
131
 
134
- [Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.1/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.1/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
132
+ [Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.6.0/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.6.0/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
@@ -22,7 +22,8 @@ licenses independently of the package source license.
22
22
 
23
23
  ## Example image
24
24
 
25
- `docs/example.png` shows model outputs over a brain MRI from the
26
- [Medical Segmentation Decathlon](http://medicaldecathlon.com/). The source image
27
- is shared under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/);
28
- the repository's Apache-2.0 license does not relicense it.
25
+ `docs/example.png` shows model outputs over three-phase CT of case C3N-00380 from
26
+ [CPTAC-CCRCC](https://doi.org/10.7937/k9/tcia.2018.oblamn27) (The Cancer Imaging
27
+ Archive). The source images are shared under
28
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/); the repository's
29
+ Apache-2.0 license does not relicense them.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "segresnet-mlx"
7
- version = "0.4.1"
7
+ version = "0.6.0"
8
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"
@@ -38,9 +38,8 @@ authors = [
38
38
  { name = "Alfredo Sandoval Jr." },
39
39
  ]
40
40
  dependencies = [
41
- "medmlx-core>=0.2.6,<0.3",
41
+ "medmlx-core[nifti]>=0.3.2,<0.4",
42
42
  "mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'",
43
- "nibabel>=5.3,<6",
44
43
  "numpy>=2.0,<3",
45
44
  ]
46
45
 
@@ -49,7 +48,7 @@ segresnet-renal-cect = "segresnet_mlx.medmlx:RENAL_CECT_MODEL"
49
48
 
50
49
  [project.urls]
51
50
  Homepage = "https://medmlx.org"
52
- Documentation = "https://github.com/MedMLX/segresnet-mlx/blob/v0.4.1/README.md"
51
+ Documentation = "https://github.com/MedMLX/segresnet-mlx/blob/v0.6.0/README.md"
53
52
  Repository = "https://github.com/MedMLX/segresnet-mlx"
54
53
  Issues = "https://github.com/MedMLX/segresnet-mlx/issues"
55
54
  Weights = "https://huggingface.co/models?author=MedMLX&search=segresnet"
@@ -9,6 +9,7 @@ from typing import TYPE_CHECKING
9
9
 
10
10
  if TYPE_CHECKING:
11
11
  from segresnet_mlx.inference import forward_patch as forward_patch
12
+ from segresnet_mlx.medmlx import run as run
12
13
  from segresnet_mlx.network import SegResNet as SegResNet
13
14
  from segresnet_mlx.predictor import BUNDLE_CONFIGS as BUNDLE_CONFIGS
14
15
  from segresnet_mlx.predictor import BundlePredictor as BundlePredictor
@@ -16,10 +17,10 @@ if TYPE_CHECKING:
16
17
  from segresnet_mlx.predictor import predict_logits as predict_logits
17
18
  from segresnet_mlx.telemetry import WindowTelemetry as WindowTelemetry
18
19
  from segresnet_mlx.topology import SegResNetSpec as SegResNetSpec
19
- from segresnet_mlx.weights import load_model as load_model
20
+ from segresnet_mlx.weights import load_network as load_network
20
21
  from segresnet_mlx.weights import required_shapes as required_shapes
21
22
 
22
- __version__ = "0.4.1"
23
+ __version__ = "0.6.0"
23
24
 
24
25
  _EXPORTS = {
25
26
  "BUNDLE_CONFIGS": "segresnet_mlx.predictor",
@@ -29,9 +30,10 @@ _EXPORTS = {
29
30
  "SlidingWindowConfig": "segresnet_mlx.predictor",
30
31
  "WindowTelemetry": "segresnet_mlx.telemetry",
31
32
  "forward_patch": "segresnet_mlx.inference",
32
- "load_model": "segresnet_mlx.weights",
33
+ "load_network": "segresnet_mlx.weights",
33
34
  "predict_logits": "segresnet_mlx.predictor",
34
35
  "required_shapes": "segresnet_mlx.weights",
36
+ "run": "segresnet_mlx.medmlx",
35
37
  }
36
38
 
37
39
  __all__ = [
@@ -42,9 +44,10 @@ __all__ = [
42
44
  "SlidingWindowConfig",
43
45
  "WindowTelemetry",
44
46
  "forward_patch",
45
- "load_model",
47
+ "load_network",
46
48
  "predict_logits",
47
49
  "required_shapes",
50
+ "run",
48
51
  ]
49
52
 
50
53
 
@@ -10,7 +10,6 @@ import numpy as np
10
10
  if TYPE_CHECKING:
11
11
  from segresnet_mlx._types import Array
12
12
 
13
- type HostArray = np.ndarray[tuple[int, ...], np.dtype[np.generic]]
14
13
  type Float32Array = np.ndarray[tuple[int, ...], np.dtype[np.float32]]
15
14
  type Float64Array = np.ndarray[tuple[int, ...], np.dtype[np.float64]]
16
15
  type Int64Array = np.ndarray[tuple[int, ...], np.dtype[np.int64]]
@@ -5,7 +5,9 @@ from __future__ import annotations
5
5
  from collections.abc import Sequence
6
6
  from typing import NotRequired, TypedDict
7
7
 
8
- from segresnet_mlx.topology import ArithmeticProfile
8
+ from medmlx_core.outputs import RunResult as _RunResult
9
+
10
+ from segresnet_mlx.topology import Precision
9
11
 
10
12
  type Json = bool | int | float | str | list[Json] | dict[str, Json] | None
11
13
 
@@ -59,7 +61,7 @@ class Details(TypedDict):
59
61
 
60
62
  weights_revision: NotRequired[str | None]
61
63
  bundle: str
62
- arithmetic_profile: ArithmeticProfile
64
+ precision: Precision
63
65
  streaming: NotRequired[bool]
64
66
  labels: dict[str, str]
65
67
  labels_present: list[int]
@@ -73,8 +75,7 @@ class Details(TypedDict):
73
75
  requires_human_review: bool
74
76
 
75
77
 
76
- class RunResult(TypedDict):
77
- """Result of ``segresnet_mlx.medmlx.run``: ``outputs["mask"]`` is the mask path."""
78
-
79
- outputs: dict[str, str]
80
- details: Details
78
+ # Result of ``segresnet_mlx.run``: ``outputs["mask"]`` is the mask path.
79
+ #
80
+ # ``artifacts["mask"]`` describes the mask file (label map, labels, source grid).
81
+ type RunResult = _RunResult[Details]
@@ -7,10 +7,10 @@ from typing import TYPE_CHECKING, cast
7
7
  from medmlx_core.runtime import import_mlx as _import_mlx
8
8
 
9
9
  if TYPE_CHECKING:
10
- from segresnet_mlx._types import MLX
10
+ from medmlx_core.typing import MlxRuntime
11
11
 
12
12
 
13
- def import_mlx() -> MLX:
13
+ def import_mlx() -> MlxRuntime:
14
14
  """Return ``mlx.core`` with the Metal GPU as the default device.
15
15
 
16
16
  The host checks and device selection are done by ``medmlx_core``; on an
@@ -19,4 +19,4 @@ def import_mlx() -> MLX:
19
19
  _import_mlx()
20
20
  import mlx.core as mx
21
21
 
22
- return cast("MLX", mx)
22
+ return cast("MlxRuntime", mx)
@@ -0,0 +1,19 @@
1
+ """Static native MLX contracts; runtime imports remain lazy."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ if TYPE_CHECKING:
8
+ from typing import Literal, TypedDict
9
+
10
+ import mlx.core as mx
11
+ from medmlx_core.volume_workspace import VolumeWorkspace
12
+
13
+ type Array = mx.array
14
+
15
+ class WorkspaceOptions(TypedDict, total=False):
16
+ workspace: VolumeWorkspace
17
+
18
+ class AccumulationOptions(TypedDict, total=False):
19
+ accumulation: Literal["mlx"]
@@ -6,9 +6,9 @@ from typing import cast
6
6
 
7
7
  import numpy as np
8
8
  from medmlx_core.errors import InvalidInputError
9
- from medmlx_core.typing import ArrayFactory
9
+ from medmlx_core.typing import HostArray
10
10
 
11
- from segresnet_mlx._arrays import Float32Array, HostArray
11
+ from segresnet_mlx._arrays import Float32Array
12
12
  from segresnet_mlx._runtime import import_mlx
13
13
  from segresnet_mlx.network import SegResNet
14
14
 
@@ -28,7 +28,7 @@ def forward_patch(network: SegResNet, values: HostArray) -> Float32Array:
28
28
  raise InvalidInputError("SegResNet input must be finite float32")
29
29
  mx = import_mlx()
30
30
  mx.synchronize()
31
- result = network(cast(ArrayFactory, mx.array)(host))
31
+ result = network(mx.array(host))
32
32
  mx.eval(result)
33
33
  mx.synchronize()
34
34
  output = cast(Float32Array, np.array(result))