segresnet-mlx 0.3.3__tar.gz → 0.3.4__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.
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/PKG-INFO +9 -7
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/README.md +6 -4
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/pyproject.toml +5 -8
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/__init__.py +1 -1
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/_types.py +1 -18
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/medmlx.py +4 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/network.py +0 -14
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/transforms.py +0 -19
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/.gitignore +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/LICENSE +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/THIRD_PARTY_NOTICES.md +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/_arrays.py +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/_nifti.py +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/_records.py +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/_runtime.py +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/inference.py +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/predictor.py +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/py.typed +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/telemetry.py +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/topology.py +0 -0
- {segresnet_mlx-0.3.3 → segresnet_mlx-0.3.4}/src/segresnet_mlx/weights.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: segresnet-mlx
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegResNet models in native MLX
|
|
5
5
|
Project-URL: Homepage, https://medmlx.org
|
|
6
|
-
Project-URL: Documentation, https://github.com/MedMLX/segresnet-mlx/blob/v0.3.
|
|
6
|
+
Project-URL: Documentation, https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/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,7 +24,7 @@ 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
|
|
27
|
+
Requires-Dist: medmlx-core<0.3,>=0.2.6
|
|
28
28
|
Requires-Dist: mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'
|
|
29
29
|
Requires-Dist: nibabel<6,>=5.3
|
|
30
30
|
Requires-Dist: numpy<3,>=2.0
|
|
@@ -46,14 +46,14 @@ Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegR
|
|
|
46
46
|
|
|
47
47
|
[](https://pypi.org/project/segresnet-mlx/)
|
|
48
48
|
[](https://pypi.org/project/segresnet-mlx/)
|
|
49
|
-
[](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.
|
|
49
|
+
[](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/LICENSE)
|
|
50
50
|
[](https://github.com/ml-explore/mlx)
|
|
51
51
|
[](https://huggingface.co/MedMLX/segresnet-brats-mlx)
|
|
52
52
|
[](https://github.com/MedMLX/medmlx)
|
|
53
53
|
|
|
54
54
|
[BraTS weights](https://huggingface.co/MedMLX/segresnet-brats-mlx) · [Renal weights](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx) · [MedMLX](https://github.com/MedMLX/medmlx)
|
|
55
55
|
|
|
56
|
-
<img src="https://raw.githubusercontent.com/MedMLX/segresnet-mlx/v0.3.
|
|
56
|
+
<img src="https://raw.githubusercontent.com/MedMLX/segresnet-mlx/v0.3.4/docs/example.png" alt="Brain tumor segmentation in axial, coronal and sagittal MRI" width="100%">
|
|
57
57
|
|
|
58
58
|
</div>
|
|
59
59
|
|
|
@@ -61,6 +61,8 @@ Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegR
|
|
|
61
61
|
| :--- | :--- |
|
|
62
62
|
| MRI sequences or CT volumes | Segmentation on the input grid |
|
|
63
63
|
|
|
64
|
+
Weights: 19 MB download for `segresnet-brats`, 76 MB for `segresnet-renal-cect`. Peak MLX memory: 4.9 GB for a 240×240×155 four-sequence brain MRI (`segresnet-brats`) and 4.0 GB for a 478×277×161 three-phase CT (`segresnet-renal-cect`).
|
|
65
|
+
|
|
64
66
|
## Use with MedMLX
|
|
65
67
|
|
|
66
68
|
The [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) is the lowest-friction way to use this package. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run `segresnet-brats` and `segresnet-renal-cect` for you.
|
|
@@ -81,7 +83,7 @@ For Codex, use `codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-wor
|
|
|
81
83
|
```bash
|
|
82
84
|
uv venv --python 3.13
|
|
83
85
|
source .venv/bin/activate
|
|
84
|
-
uv pip install "segresnet-mlx>=0.3.
|
|
86
|
+
uv pip install "segresnet-mlx>=0.3.4"
|
|
85
87
|
```
|
|
86
88
|
|
|
87
89
|
## Run
|
|
@@ -187,6 +189,6 @@ with Metal and has no CPU fallback.
|
|
|
187
189
|
|
|
188
190
|
## License
|
|
189
191
|
|
|
190
|
-
[Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.
|
|
192
|
+
[Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
|
|
191
193
|
|
|
192
194
|
For research and education. Outputs require human review.
|
|
@@ -6,14 +6,14 @@ Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegR
|
|
|
6
6
|
|
|
7
7
|
[](https://pypi.org/project/segresnet-mlx/)
|
|
8
8
|
[](https://pypi.org/project/segresnet-mlx/)
|
|
9
|
-
[](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.
|
|
9
|
+
[](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/LICENSE)
|
|
10
10
|
[](https://github.com/ml-explore/mlx)
|
|
11
11
|
[](https://huggingface.co/MedMLX/segresnet-brats-mlx)
|
|
12
12
|
[](https://github.com/MedMLX/medmlx)
|
|
13
13
|
|
|
14
14
|
[BraTS weights](https://huggingface.co/MedMLX/segresnet-brats-mlx) · [Renal weights](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx) · [MedMLX](https://github.com/MedMLX/medmlx)
|
|
15
15
|
|
|
16
|
-
<img src="https://raw.githubusercontent.com/MedMLX/segresnet-mlx/v0.3.
|
|
16
|
+
<img src="https://raw.githubusercontent.com/MedMLX/segresnet-mlx/v0.3.4/docs/example.png" alt="Brain tumor segmentation in axial, coronal and sagittal MRI" width="100%">
|
|
17
17
|
|
|
18
18
|
</div>
|
|
19
19
|
|
|
@@ -21,6 +21,8 @@ Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegR
|
|
|
21
21
|
| :--- | :--- |
|
|
22
22
|
| MRI sequences or CT volumes | Segmentation on the input grid |
|
|
23
23
|
|
|
24
|
+
Weights: 19 MB download for `segresnet-brats`, 76 MB for `segresnet-renal-cect`. Peak MLX memory: 4.9 GB for a 240×240×155 four-sequence brain MRI (`segresnet-brats`) and 4.0 GB for a 478×277×161 three-phase CT (`segresnet-renal-cect`).
|
|
25
|
+
|
|
24
26
|
## Use with MedMLX
|
|
25
27
|
|
|
26
28
|
The [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) is the lowest-friction way to use this package. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run `segresnet-brats` and `segresnet-renal-cect` for you.
|
|
@@ -41,7 +43,7 @@ For Codex, use `codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-wor
|
|
|
41
43
|
```bash
|
|
42
44
|
uv venv --python 3.13
|
|
43
45
|
source .venv/bin/activate
|
|
44
|
-
uv pip install "segresnet-mlx>=0.3.
|
|
46
|
+
uv pip install "segresnet-mlx>=0.3.4"
|
|
45
47
|
```
|
|
46
48
|
|
|
47
49
|
## Run
|
|
@@ -147,6 +149,6 @@ with Metal and has no CPU fallback.
|
|
|
147
149
|
|
|
148
150
|
## License
|
|
149
151
|
|
|
150
|
-
[Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.
|
|
152
|
+
[Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/LICENSE). See [third-party notices](https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
|
|
151
153
|
|
|
152
154
|
For research and education. Outputs require human review.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "segresnet-mlx"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.4"
|
|
8
8
|
description = "Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegResNet models in native MLX"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.13,<3.14"
|
|
@@ -39,7 +39,7 @@ authors = [
|
|
|
39
39
|
{ name = "Alfredo Sandoval Jr." },
|
|
40
40
|
]
|
|
41
41
|
dependencies = [
|
|
42
|
-
"medmlx-core
|
|
42
|
+
"medmlx-core>=0.2.6,<0.3",
|
|
43
43
|
"mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'",
|
|
44
44
|
"nibabel>=5.3,<6",
|
|
45
45
|
"numpy>=2.0,<3",
|
|
@@ -51,7 +51,7 @@ segresnet-renal-cect = "segresnet_mlx.medmlx:RENAL_CECT_MODEL"
|
|
|
51
51
|
|
|
52
52
|
[project.urls]
|
|
53
53
|
Homepage = "https://medmlx.org"
|
|
54
|
-
Documentation = "https://github.com/MedMLX/segresnet-mlx/blob/v0.3.
|
|
54
|
+
Documentation = "https://github.com/MedMLX/segresnet-mlx/blob/v0.3.4/README.md"
|
|
55
55
|
Repository = "https://github.com/MedMLX/segresnet-mlx"
|
|
56
56
|
Issues = "https://github.com/MedMLX/segresnet-mlx/issues"
|
|
57
57
|
Weights = "https://huggingface.co/models?author=MedMLX&search=segresnet"
|
|
@@ -68,9 +68,6 @@ dev = [
|
|
|
68
68
|
"torch>=2.6,<3",
|
|
69
69
|
]
|
|
70
70
|
|
|
71
|
-
[tool.hatch.metadata]
|
|
72
|
-
allow-direct-references = true
|
|
73
|
-
|
|
74
71
|
[tool.hatch.build.targets.wheel]
|
|
75
72
|
packages = ["src/segresnet_mlx"]
|
|
76
73
|
|
|
@@ -93,8 +90,8 @@ extend-select = ["TID251", "TID252", "ANN401"]
|
|
|
93
90
|
select = ["E", "F", "I", "UP", "B", "SIM", "RUF"]
|
|
94
91
|
|
|
95
92
|
[tool.pyright]
|
|
96
|
-
include = ["
|
|
97
|
-
extraPaths = ["src", "
|
|
93
|
+
include = ["src", "tests"]
|
|
94
|
+
extraPaths = ["src", "tests"]
|
|
98
95
|
pythonVersion = "3.13"
|
|
99
96
|
typeCheckingMode = "strict"
|
|
100
97
|
enableTypeIgnoreComments = false
|
|
@@ -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.
|
|
22
|
+
__version__ = "0.3.4"
|
|
23
23
|
|
|
24
24
|
_EXPORTS = {
|
|
25
25
|
"BUNDLE_CONFIGS": "segresnet_mlx.predictor",
|
|
@@ -12,28 +12,16 @@ if TYPE_CHECKING:
|
|
|
12
12
|
from medmlx_core.typing import MlxRuntime
|
|
13
13
|
from medmlx_core.volume_workspace import VolumeWorkspace
|
|
14
14
|
|
|
15
|
-
from segresnet_mlx._arrays import Float32Array
|
|
15
|
+
from segresnet_mlx._arrays import Float32Array
|
|
16
16
|
|
|
17
17
|
type Array = mx.array
|
|
18
18
|
|
|
19
19
|
class WorkspaceOptions(TypedDict, total=False):
|
|
20
20
|
workspace: VolumeWorkspace
|
|
21
21
|
|
|
22
|
-
type ArrayValue = bool | int | float | complex | list[ArrayValue] | tuple[ArrayValue, ...]
|
|
23
|
-
|
|
24
|
-
class ArrayConstructor(Protocol):
|
|
25
|
-
def __call__(
|
|
26
|
-
self, value: HostArray | Array | ArrayValue, dtype: mx.Dtype | None = None
|
|
27
|
-
) -> Array:
|
|
28
|
-
"""Construct an MLX array with an optional dtype."""
|
|
29
|
-
...
|
|
30
|
-
|
|
31
22
|
class MLX(MlxRuntime, Protocol):
|
|
32
23
|
all = staticmethod(mx.all)
|
|
33
24
|
isfinite = staticmethod(mx.isfinite)
|
|
34
|
-
full = staticmethod(mx.full)
|
|
35
|
-
sum = staticmethod(mx.sum)
|
|
36
|
-
ones = staticmethod(mx.ones)
|
|
37
25
|
synchronize = staticmethod(mx.synchronize)
|
|
38
26
|
clear_cache = staticmethod(mx.clear_cache)
|
|
39
27
|
load = staticmethod(mx.load)
|
|
@@ -63,8 +51,3 @@ if TYPE_CHECKING:
|
|
|
63
51
|
|
|
64
52
|
class CoreSlidingWindow(Protocol):
|
|
65
53
|
sliding_window_inference: SlidingWindowInference
|
|
66
|
-
|
|
67
|
-
class Metal(Protocol):
|
|
68
|
-
def is_available(self) -> bool:
|
|
69
|
-
"""Report whether the Metal backend is available."""
|
|
70
|
-
...
|
|
@@ -225,6 +225,8 @@ BRATS_MODEL = {
|
|
|
225
225
|
"label": "SegResNet BraTS MRI",
|
|
226
226
|
"task": "segmentation",
|
|
227
227
|
"run": "segresnet_mlx.medmlx:brats",
|
|
228
|
+
# Measured MLX peak for a 240x240x155 four-sequence MRI; larger inputs need more.
|
|
229
|
+
"peak_memory_gb": 5.0,
|
|
228
230
|
"summary": "BraTS brain tumor segmentation from co-registered MRI sequences.",
|
|
229
231
|
"labels": {
|
|
230
232
|
str(value): name
|
|
@@ -236,6 +238,8 @@ RENAL_CECT_MODEL = {
|
|
|
236
238
|
"label": "SegResNet renal CECT",
|
|
237
239
|
"task": "segmentation",
|
|
238
240
|
"run": "segresnet_mlx.medmlx:renal_cect",
|
|
241
|
+
# Measured MLX peak for a 478x277x161 three-phase CT; larger inputs need more.
|
|
242
|
+
"peak_memory_gb": 4.1,
|
|
239
243
|
"summary": "Renal structures from arterial, venous and excretory phase CT.",
|
|
240
244
|
"labels": {
|
|
241
245
|
str(value): name
|
|
@@ -17,20 +17,6 @@ from medmlx_core.precision import Float32Operators
|
|
|
17
17
|
from segresnet_mlx.topology import ArithmeticProfile, SegResNetSpec
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def group_mean(values: Array, mx: MLX) -> Array:
|
|
21
|
-
"""Mean over the last axis of ``(N, G, S)`` values, summed in 256-element tiles.
|
|
22
|
-
|
|
23
|
-
Tiling bounds the float32 accumulation depth of a group that spans a whole
|
|
24
|
-
volume. The last dimension must be nonempty. Returns ``(N, G, 1)``. ``SegResNet``
|
|
25
|
-
does not call this (its GroupNorm comes from the ``medmlx_core`` operators); it is
|
|
26
|
-
exercised by ``tests/test_equivalence.py``.
|
|
27
|
-
"""
|
|
28
|
-
size = int(values.shape[-1])
|
|
29
|
-
padded = mx.pad(values, [(0, 0), (0, 0), (0, (-size) % 256)])
|
|
30
|
-
tiles = mx.reshape(padded, (*values.shape[:2], -1, 256))
|
|
31
|
-
return mx.sum(mx.sum(tiles, axis=-1), axis=-1, keepdims=True) / size
|
|
32
|
-
|
|
33
|
-
|
|
34
20
|
class SegResNet:
|
|
35
21
|
"""Raw-logit forward pass for MONAI's 3-D, group-normalized SegResNet.
|
|
36
22
|
|
|
@@ -26,9 +26,6 @@ import numpy.typing as npt
|
|
|
26
26
|
from medmlx_core.geometry import (
|
|
27
27
|
_bmm as _bmm,
|
|
28
28
|
)
|
|
29
|
-
from medmlx_core.geometry import (
|
|
30
|
-
_fma as _fma,
|
|
31
|
-
)
|
|
32
29
|
from medmlx_core.geometry import (
|
|
33
30
|
_linspace_from_neg_one as _linspace_from_neg_one,
|
|
34
31
|
)
|
|
@@ -106,14 +103,6 @@ def correct_nifti_header(image: NiftiImage) -> None:
|
|
|
106
103
|
image.header.set_zooms(affine_to_spacing(image.affine, 3))
|
|
107
104
|
|
|
108
105
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
106
|
def orient(
|
|
118
107
|
data: Float32Array,
|
|
119
108
|
affine: Float64Array,
|
|
@@ -347,10 +336,6 @@ def write_nifti(path: Path, data: HostArray, affine: Float64Array, dtype: npt.DT
|
|
|
347
336
|
nib.save(image, str(path))
|
|
348
337
|
|
|
349
338
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
339
|
def _normalize_transform(shape: Sequence[int]) -> Float64Array:
|
|
355
340
|
"""``monai.networks.utils.normalize_transform`` (``align_corners=False``)."""
|
|
356
341
|
size = np.asarray(shape, dtype=np.float64)
|
|
@@ -362,10 +347,6 @@ def _normalize_transform(shape: Sequence[int]) -> Float64Array:
|
|
|
362
347
|
return result
|
|
363
348
|
|
|
364
349
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
350
|
def _theta(
|
|
370
351
|
xform: Float64Array,
|
|
371
352
|
in_size: Sequence[int],
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|