segresnet-mlx 0.5.0__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 (22) hide show
  1. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/PKG-INFO +23 -26
  2. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/README.md +20 -22
  3. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/THIRD_PARTY_NOTICES.md +5 -4
  4. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/pyproject.toml +3 -4
  5. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/__init__.py +1 -1
  6. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/_arrays.py +0 -1
  7. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/_records.py +2 -2
  8. {segresnet_mlx-0.5.0 → 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.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/inference.py +3 -3
  11. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/medmlx.py +59 -105
  12. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/network.py +21 -20
  13. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/predictor.py +11 -17
  14. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/topology.py +2 -2
  15. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/transforms.py +81 -169
  16. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/weights.py +14 -45
  17. segresnet_mlx-0.5.0/src/segresnet_mlx/_nifti.py +0 -121
  18. segresnet_mlx-0.5.0/src/segresnet_mlx/_types.py +0 -56
  19. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/.gitignore +0 -0
  20. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/LICENSE +0 -0
  21. {segresnet_mlx-0.5.0 → segresnet_mlx-0.6.0}/src/segresnet_mlx/py.typed +0 -0
  22. {segresnet_mlx-0.5.0 → 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.5.0
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.5.0/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.4,>=0.3.1
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.5.0/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,7 +71,7 @@ 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.5.0"
74
+ uv pip install "segresnet-mlx>=0.6.0"
76
75
  ```
77
76
 
78
77
  ## Run
@@ -103,32 +102,31 @@ weights, pass `weights_path` as a folder containing `segresnet-renal-cect.safete
103
102
  | `output_dir` | Directory for `mask.nii.gz`; created if missing |
104
103
  | `weights_path` | Optional folder containing `segresnet-renal-cect.safetensors` |
105
104
  | `overwrite` | `False` by default; an existing mask is replaced only when `True` |
106
- | `precision` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48` |
105
+ | `precision` | `source-fp32` (default), `compensated-fp32` or `compensated-fp48` |
107
106
  | `streaming` | `False` by default; `True` keeps blending intermediates and logits in temporary mapped files |
108
107
  | `scratch_dir` | Parent directory for the streaming files; defaults to the system temporary directory |
109
108
 
110
- Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or
111
- unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
112
-
113
- The model was trained on CT cropped to the kidney region. Crop around each kidney,
114
- with a margin of about 15 mm, before running it: on a wider field of view it can label
115
- vertebral bodies or liver as neoplasm.
116
-
117
- The mask is float32 with labels 1 artery, 2 vein, 3 ureter, 4 neoplasm and
118
- 5 parenchyma; where classes overlap, the lower label wins.
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.
119
117
 
120
118
  | `precision` | Arithmetic |
121
119
  | :--- | :--- |
122
- | `torch-order-fp32` (default) | The default float32 profile |
120
+ | `source-fp32` (default) | The default float32 precision |
123
121
  | `compensated-fp32` | Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
124
122
  | `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
125
123
 
126
- `run` returns `{"outputs": {"mask": path}, "artifacts": {"mask": ...}, "details": {...}}`: the `mask` artifact names the labels and the input grid it is on, and `details` holds run metadata.
127
- Invalid inputs raise `InvalidInputError`; missing or mismatched weights raise
128
- `AssetNotReadyError`; inference failures raise `ModelExecutionError`.
129
-
130
- Streaming files are removed on success and failure. The final label volume stays in
131
- memory.
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
 
@@ -150,9 +148,8 @@ volume_logits = predict_logits(patch, config, network=network) # stitched slidi
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
150
  - `load_network` checks tensor names, shapes and finite float32 values against
153
- `required_shapes(spec)`.
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.5.0/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.5.0/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.5.0/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,7 +32,7 @@ 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.5.0"
35
+ uv pip install "segresnet-mlx>=0.6.0"
36
36
  ```
37
37
 
38
38
  ## Run
@@ -63,32 +63,31 @@ weights, pass `weights_path` as a folder containing `segresnet-renal-cect.safete
63
63
  | `output_dir` | Directory for `mask.nii.gz`; created if missing |
64
64
  | `weights_path` | Optional folder containing `segresnet-renal-cect.safetensors` |
65
65
  | `overwrite` | `False` by default; an existing mask is replaced only when `True` |
66
- | `precision` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48` |
66
+ | `precision` | `source-fp32` (default), `compensated-fp32` or `compensated-fp48` |
67
67
  | `streaming` | `False` by default; `True` keeps blending intermediates and logits in temporary mapped files |
68
68
  | `scratch_dir` | Parent directory for the streaming files; defaults to the system temporary directory |
69
69
 
70
- Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or
71
- unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
72
-
73
- The model was trained on CT cropped to the kidney region. Crop around each kidney,
74
- with a margin of about 15 mm, before running it: on a wider field of view it can label
75
- vertebral bodies or liver as neoplasm.
76
-
77
- The mask is float32 with labels 1 artery, 2 vein, 3 ureter, 4 neoplasm and
78
- 5 parenchyma; where classes overlap, the lower label wins.
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.
79
78
 
80
79
  | `precision` | Arithmetic |
81
80
  | :--- | :--- |
82
- | `torch-order-fp32` (default) | The default float32 profile |
81
+ | `source-fp32` (default) | The default float32 precision |
83
82
  | `compensated-fp32` | Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
84
83
  | `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
85
84
 
86
- `run` returns `{"outputs": {"mask": path}, "artifacts": {"mask": ...}, "details": {...}}`: the `mask` artifact names the labels and the input grid it is on, and `details` holds run metadata.
87
- Invalid inputs raise `InvalidInputError`; missing or mismatched weights raise
88
- `AssetNotReadyError`; inference failures raise `ModelExecutionError`.
89
-
90
- Streaming files are removed on success and failure. The final label volume stays in
91
- memory.
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
 
@@ -110,9 +109,8 @@ volume_logits = predict_logits(patch, config, network=network) # stitched slidi
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
111
  - `load_network` checks tensor names, shapes and finite float32 values against
113
- `required_shapes(spec)`.
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.5.0/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.5.0/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.5.0"
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.3.1,<0.4",
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.5.0/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"
@@ -20,7 +20,7 @@ if TYPE_CHECKING:
20
20
  from segresnet_mlx.weights import load_network as load_network
21
21
  from segresnet_mlx.weights import required_shapes as required_shapes
22
22
 
23
- __version__ = "0.5.0"
23
+ __version__ = "0.6.0"
24
24
 
25
25
  _EXPORTS = {
26
26
  "BUNDLE_CONFIGS": "segresnet_mlx.predictor",
@@ -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]]
@@ -7,7 +7,7 @@ from typing import NotRequired, TypedDict
7
7
 
8
8
  from medmlx_core.outputs import RunResult as _RunResult
9
9
 
10
- from segresnet_mlx.topology import ArithmeticProfile
10
+ from segresnet_mlx.topology import Precision
11
11
 
12
12
  type Json = bool | int | float | str | list[Json] | dict[str, Json] | None
13
13
 
@@ -61,7 +61,7 @@ class Details(TypedDict):
61
61
 
62
62
  weights_revision: NotRequired[str | None]
63
63
  bundle: str
64
- precision: ArithmeticProfile
64
+ precision: Precision
65
65
  streaming: NotRequired[bool]
66
66
  labels: dict[str, str]
67
67
  labels_present: list[int]
@@ -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))