segresnet-mlx 0.3.6__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.
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/PKG-INFO +35 -88
- segresnet_mlx-0.4.0/README.md +126 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/pyproject.toml +4 -6
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/__init__.py +1 -1
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/medmlx.py +52 -397
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/predictor.py +30 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/transforms.py +32 -146
- segresnet_mlx-0.3.6/README.md +0 -179
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/.gitignore +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/LICENSE +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/THIRD_PARTY_NOTICES.md +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_arrays.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_nifti.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_records.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_runtime.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/_types.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/inference.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/network.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/py.typed +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/telemetry.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/src/segresnet_mlx/topology.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.0}/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.
|
|
4
|
-
Summary: Segment
|
|
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
5
|
Project-URL: Homepage, https://medmlx.org
|
|
6
|
-
Project-URL: Documentation, https://github.com/MedMLX/segresnet-mlx/blob/v0.
|
|
6
|
+
Project-URL: Documentation, https://github.com/MedMLX/segresnet-mlx/blob/v0.4.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
|
|
@@ -12,7 +12,7 @@ Author: Joseph Sandoval, Alfredo Sandoval Jr.
|
|
|
12
12
|
License-Expression: Apache-2.0
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
License-File: THIRD_PARTY_NOTICES.md
|
|
15
|
-
Keywords: apple-silicon,
|
|
15
|
+
Keywords: apple-silicon,ct,kidney,medical-imaging,metal,mlx,monai,segmentation,segresnet
|
|
16
16
|
Classifier: Development Status :: 4 - Beta
|
|
17
17
|
Classifier: Intended Audience :: Developers
|
|
18
18
|
Classifier: Intended Audience :: Science/Research
|
|
@@ -42,28 +42,25 @@ Description-Content-Type: text/markdown
|
|
|
42
42
|
|
|
43
43
|
# segresnet-mlx
|
|
44
44
|
|
|
45
|
-
Segment
|
|
45
|
+
Segment renal arteries, veins, ureters, tumors and parenchyma in multiphase CT with MONAI SegResNet and native MLX.
|
|
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.
|
|
49
|
+
[](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/LICENSE)
|
|
50
50
|
[](https://github.com/ml-explore/mlx)
|
|
51
|
-
[](https://huggingface.co/MedMLX/segresnet-
|
|
51
|
+
[](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
|
|
52
52
|
[](https://github.com/MedMLX/medmlx)
|
|
53
53
|
|
|
54
|
-
[
|
|
55
|
-
|
|
56
|
-
<img src="https://raw.githubusercontent.com/MedMLX/segresnet-mlx/main/docs/example.png" alt="Brain tumor segmentation in axial, coronal and sagittal MRI" width="100%">
|
|
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)
|
|
57
55
|
|
|
58
56
|
</div>
|
|
59
57
|
|
|
60
58
|
| Input | Output |
|
|
61
59
|
| :--- | :--- |
|
|
62
|
-
|
|
|
60
|
+
| Arterial, venous and excretory CT · NIfTI | Renal labels on the input grid |
|
|
63
61
|
|
|
64
62
|
| Model | Weights download | Peak MLX memory | Measured on |
|
|
65
63
|
| :--- | ---: | ---: | :--- |
|
|
66
|
-
| `segresnet-brats` | 19 MB | 4.9 GB | 240×240×155 four-sequence brain MRI |
|
|
67
64
|
| `segresnet-renal-cect` | 76 MB | 4.0 GB | 478×277×161 three-phase CT |
|
|
68
65
|
|
|
69
66
|
## Install
|
|
@@ -71,109 +68,59 @@ Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegR
|
|
|
71
68
|
```bash
|
|
72
69
|
uv venv --python 3.13
|
|
73
70
|
source .venv/bin/activate
|
|
74
|
-
uv pip install "segresnet-mlx>=0.
|
|
71
|
+
uv pip install "segresnet-mlx>=0.4.0"
|
|
75
72
|
```
|
|
76
73
|
|
|
77
74
|
## Run
|
|
78
75
|
|
|
79
76
|
```python
|
|
80
|
-
from segresnet_mlx.medmlx import
|
|
77
|
+
from segresnet_mlx.medmlx import renal_cect
|
|
81
78
|
|
|
82
|
-
result =
|
|
83
|
-
|
|
84
|
-
|
|
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",
|
|
85
84
|
)
|
|
86
85
|
print(result["outputs"]["mask"])
|
|
87
86
|
```
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
| Model | Runner | Inputs | Weights | Local file |
|
|
95
|
-
| :--- | :--- | :--- | :--- | :--- |
|
|
96
|
-
| `segresnet-brats` | `brats` | `t1c_path`, `t1_path`, `t2_path`, `flair_path` | `MedMLX/segresnet-brats-mlx` | `segresnet-brats.safetensors` |
|
|
97
|
-
| `segresnet-renal-cect` | `renal_cect` | `arterial_path`, `venous_path`, `excretory_path` | [`MedMLX/segresnet-renal-cect-mlx`](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx) | `segresnet-renal-cect.safetensors` |
|
|
98
|
-
|
|
99
|
-
Weights download on first use; `medmlx setup segresnet-brats` downloads ahead of time.
|
|
100
|
-
For local weights, pass a folder containing the model's local file as `weights_path`.
|
|
101
|
-
The standalone `run(bundle=..., weights_path=...)` interface remains available for
|
|
102
|
-
explicit local checkpoints, including the whole-body CT variants, whose native weights
|
|
103
|
-
are published as [`MedMLX/segresnet-wholebody-mlx`](https://huggingface.co/MedMLX/segresnet-wholebody-mlx).
|
|
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.
|
|
104
92
|
|
|
105
93
|
### Inputs and outputs
|
|
106
94
|
|
|
107
95
|
| Argument | Meaning |
|
|
108
96
|
| --- | --- |
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `output_dir` | Directory for `<bundle>_mask.nii.gz`; created if missing |
|
|
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 |
|
|
112
99
|
| `weights_path` | Optional `.safetensors` file or a folder containing it |
|
|
113
100
|
| `overwrite` | `False` by default; an existing mask is replaced only when `True` |
|
|
114
|
-
| `arithmetic_profile` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48`
|
|
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 |
|
|
115
104
|
|
|
116
105
|
Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or
|
|
117
106
|
unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
|
|
118
107
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
| `segresnet-brats` | uint8 | 1 necrotic/non-enhancing tumor core, 2 peritumoral edema, 4 enhancing tumor |
|
|
122
|
-
| `segresnet-renal-cect` | float32 | 1 artery, 2 vein, 3 ureter, 4 neoplasm, 5 parenchyma |
|
|
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.
|
|
123
110
|
|
|
124
111
|
| `arithmetic_profile` | Arithmetic |
|
|
125
112
|
| :--- | :--- |
|
|
126
113
|
| `torch-order-fp32` (default) | The default float32 profile |
|
|
127
114
|
| `compensated-fp32` | Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
|
|
128
|
-
| `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host
|
|
115
|
+
| `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
|
|
129
116
|
|
|
130
|
-
|
|
117
|
+
The runner returns `{"outputs": {"mask": path}, "details": {...}}`, with run metadata in `details`.
|
|
131
118
|
Invalid inputs raise `InvalidInputError`; missing or mismatched weights raise
|
|
132
119
|
`AssetNotReadyError`; inference failures raise `ModelExecutionError`.
|
|
133
120
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
| `bundle` | Weights file | Input |
|
|
139
|
-
| :--- | :--- | :--- |
|
|
140
|
-
| `brats_mri_segmentation` | `segresnet-brats.safetensors` | Four MRI sequences |
|
|
141
|
-
| `renalStructures_CECT_segmentation` | `segresnet-renal-cect.safetensors` | Three CT phases |
|
|
142
|
-
| `wholeBody_ct_segmentation` (1.5 mm) | `segresnet-wholebody-high.safetensors` | One CT as `image_path` |
|
|
143
|
-
| `wholeBody_ct_segmentation_lowres` (3 mm) | `segresnet-wholebody-low.safetensors` | One CT as `image_path` |
|
|
144
|
-
|
|
145
|
-
The whole-body bundles write float32 labels 0–104 from the bundle's `channel_def`:
|
|
146
|
-
|
|
147
|
-
| Labels | Structures |
|
|
148
|
-
| :--- | :--- |
|
|
149
|
-
| 1–10 | spleen, kidney_right, kidney_left, gallbladder, liver, stomach, aorta, inferior_vena_cava, portal_vein_and_splenic_vein, pancreas |
|
|
150
|
-
| 11–12 | adrenal glands (right, left) |
|
|
151
|
-
| 13–17 | lung lobes (upper and lower left, upper, middle and lower right) |
|
|
152
|
-
| 18–41 | vertebrae L5–C1 |
|
|
153
|
-
| 42–43 | esophagus, trachea |
|
|
154
|
-
| 44–49 | heart chambers and pulmonary artery |
|
|
155
|
-
| 50 | brain |
|
|
156
|
-
| 51–54 | iliac arteries and veins |
|
|
157
|
-
| 55 | small bowel |
|
|
158
|
-
| 56 | duodenum |
|
|
159
|
-
| 57 | colon |
|
|
160
|
-
| 58–69 | left ribs 1–12 |
|
|
161
|
-
| 70–81 | right ribs 1–12 |
|
|
162
|
-
| 82–83 | humerus |
|
|
163
|
-
| 84–85 | scapula |
|
|
164
|
-
| 86–87 | clavicula |
|
|
165
|
-
| 88–89 | femur |
|
|
166
|
-
| 90–91 | hip |
|
|
167
|
-
| 92–93 | sacrum, face |
|
|
168
|
-
| 94–99 | gluteus maximus, medius and minimus |
|
|
169
|
-
| 100–101 | autochthon |
|
|
170
|
-
| 102–103 | iliopsoas |
|
|
171
|
-
| 104 | urinary bladder |
|
|
172
|
-
|
|
173
|
-
`run(..., streaming=True, scratch_dir="scratch")` keeps blending intermediates and
|
|
174
|
-
logits in temporary mapped files instead of a full in-memory class volume. The files
|
|
175
|
-
are removed on success and failure; `scratch_dir` defaults to the system temporary
|
|
176
|
-
directory. The final label volume stays in memory.
|
|
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.
|
|
177
124
|
|
|
178
125
|
### Python API
|
|
179
126
|
|
|
@@ -201,7 +148,7 @@ volume_logits = predict_logits(patch, config, network=network) # stitched slidi
|
|
|
201
148
|
|
|
202
149
|
## Use with MedMLX
|
|
203
150
|
|
|
204
|
-
Use the [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) to run `segresnet-
|
|
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.
|
|
205
152
|
|
|
206
153
|
```sh
|
|
207
154
|
uv tool install --python 3.13 "medmlx[segment,mcp]"
|
|
@@ -210,10 +157,10 @@ mkdir -p "$HOME/medmlx-work"
|
|
|
210
157
|
claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"
|
|
211
158
|
```
|
|
212
159
|
|
|
213
|
-
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-
|
|
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`.
|
|
214
161
|
|
|
215
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.
|
|
216
163
|
|
|
217
164
|
## License
|
|
218
165
|
|
|
219
|
-
[Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.
|
|
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
|
+
[](https://pypi.org/project/segresnet-mlx/)
|
|
8
|
+
[](https://pypi.org/project/segresnet-mlx/)
|
|
9
|
+
[](https://github.com/MedMLX/segresnet-mlx/blob/v0.4.0/LICENSE)
|
|
10
|
+
[](https://github.com/ml-explore/mlx)
|
|
11
|
+
[](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
|
|
12
|
+
[](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.
|
|
8
|
-
description = "Segment
|
|
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
|
-
"
|
|
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.
|
|
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.
|
|
22
|
+
__version__ = "0.4.0"
|
|
23
23
|
|
|
24
24
|
_EXPORTS = {
|
|
25
25
|
"BUNDLE_CONFIGS": "segresnet_mlx.predictor",
|