segresnet-mlx 0.3.6__tar.gz → 0.4.1__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.1}/PKG-INFO +42 -87
- segresnet_mlx-0.4.1/README.md +134 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/pyproject.toml +4 -6
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/__init__.py +1 -1
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/medmlx.py +52 -397
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/predictor.py +30 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/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.1}/.gitignore +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/LICENSE +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/THIRD_PARTY_NOTICES.md +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/_arrays.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/_nifti.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/_records.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/_runtime.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/_types.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/inference.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/network.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/py.typed +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/telemetry.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/src/segresnet_mlx/topology.py +0 -0
- {segresnet_mlx-0.3.6 → segresnet_mlx-0.4.1}/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.1
|
|
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.1/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,29 @@ 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.1/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
|
-
[
|
|
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
55
|
|
|
56
|
-
<img src="https://raw.githubusercontent.com/MedMLX/segresnet-mlx/main/docs/example.png" alt="
|
|
56
|
+
<img src="https://raw.githubusercontent.com/MedMLX/segresnet-mlx/main/docs/example.png" alt="Venous-phase CT of a left kidney with a renal tumor, the predicted renal labels on that slice, and a 3D view of the predicted kidney, tumor, vessels and collecting system" width="100%">
|
|
57
|
+
|
|
58
|
+
<sub>Three-phase CT from <a href="https://doi.org/10.7937/k9/tcia.2018.oblamn27">CPTAC-CCRCC</a> case C3N-00380 (The Cancer Imaging Archive, CC BY 4.0), segmented on a crop around each kidney. The 3D view smooths surfaces and hides fragments under 0.5 mL and labels more than 20 mm from the kidney.</sub>
|
|
57
59
|
|
|
58
60
|
</div>
|
|
59
61
|
|
|
60
62
|
| Input | Output |
|
|
61
63
|
| :--- | :--- |
|
|
62
|
-
|
|
|
64
|
+
| Arterial, venous and excretory CT · NIfTI | Renal labels on the input grid |
|
|
63
65
|
|
|
64
66
|
| Model | Weights download | Peak MLX memory | Measured on |
|
|
65
67
|
| :--- | ---: | ---: | :--- |
|
|
66
|
-
| `segresnet-brats` | 19 MB | 4.9 GB | 240×240×155 four-sequence brain MRI |
|
|
67
68
|
| `segresnet-renal-cect` | 76 MB | 4.0 GB | 478×277×161 three-phase CT |
|
|
68
69
|
|
|
69
70
|
## Install
|
|
@@ -71,109 +72,63 @@ Segment brain tumors, renal structures and whole-body CT anatomy with MONAI SegR
|
|
|
71
72
|
```bash
|
|
72
73
|
uv venv --python 3.13
|
|
73
74
|
source .venv/bin/activate
|
|
74
|
-
uv pip install "segresnet-mlx>=0.
|
|
75
|
+
uv pip install "segresnet-mlx>=0.4.1"
|
|
75
76
|
```
|
|
76
77
|
|
|
77
78
|
## Run
|
|
78
79
|
|
|
79
80
|
```python
|
|
80
|
-
from segresnet_mlx.medmlx import
|
|
81
|
+
from segresnet_mlx.medmlx import renal_cect
|
|
81
82
|
|
|
82
|
-
result =
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
result = renal_cect(
|
|
84
|
+
arterial_path="arterial.nii.gz",
|
|
85
|
+
venous_path="venous.nii.gz",
|
|
86
|
+
excretory_path="excretory.nii.gz",
|
|
87
|
+
output_dir="out",
|
|
85
88
|
)
|
|
86
89
|
print(result["outputs"]["mask"])
|
|
87
90
|
```
|
|
88
91
|
|
|
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).
|
|
92
|
+
Weights download from [`MedMLX/segresnet-renal-cect-mlx`](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
|
|
93
|
+
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.
|
|
104
96
|
|
|
105
97
|
### Inputs and outputs
|
|
106
98
|
|
|
107
99
|
| Argument | Meaning |
|
|
108
100
|
| --- | --- |
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `output_dir` | Directory for `<bundle>_mask.nii.gz`; created if missing |
|
|
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 |
|
|
112
103
|
| `weights_path` | Optional `.safetensors` file or a folder containing it |
|
|
113
104
|
| `overwrite` | `False` by default; an existing mask is replaced only when `True` |
|
|
114
|
-
| `arithmetic_profile` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48`
|
|
105
|
+
| `arithmetic_profile` | `torch-order-fp32` (default), `compensated-fp32` or `compensated-fp48` |
|
|
106
|
+
| `streaming` | `False` by default; `True` keeps blending intermediates and logits in temporary mapped files |
|
|
107
|
+
| `scratch_dir` | Parent directory for the streaming files; defaults to the system temporary directory |
|
|
115
108
|
|
|
116
109
|
Inputs are finite 3D volumes on one voxel grid, with spatial units in millimetres or
|
|
117
110
|
unspecified. The mask is written on the input grid as the NIfTI reader corrects it.
|
|
118
111
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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.
|
|
115
|
+
|
|
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.
|
|
123
118
|
|
|
124
119
|
| `arithmetic_profile` | Arithmetic |
|
|
125
120
|
| :--- | :--- |
|
|
126
121
|
| `torch-order-fp32` (default) | The default float32 profile |
|
|
127
122
|
| `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
|
|
123
|
+
| `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
|
|
129
124
|
|
|
130
|
-
|
|
125
|
+
The runner returns `{"outputs": {"mask": path}, "details": {...}}`, with run metadata in `details`.
|
|
131
126
|
Invalid inputs raise `InvalidInputError`; missing or mismatched weights raise
|
|
132
127
|
`AssetNotReadyError`; inference failures raise `ModelExecutionError`.
|
|
133
128
|
|
|
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.
|
|
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.
|
|
177
132
|
|
|
178
133
|
### Python API
|
|
179
134
|
|
|
@@ -201,7 +156,7 @@ volume_logits = predict_logits(patch, config, network=network) # stitched slidi
|
|
|
201
156
|
|
|
202
157
|
## Use with MedMLX
|
|
203
158
|
|
|
204
|
-
Use the [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) to run `segresnet-
|
|
159
|
+
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
160
|
|
|
206
161
|
```sh
|
|
207
162
|
uv tool install --python 3.13 "medmlx[segment,mcp]"
|
|
@@ -210,10 +165,10 @@ mkdir -p "$HOME/medmlx-work"
|
|
|
210
165
|
claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"
|
|
211
166
|
```
|
|
212
167
|
|
|
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-
|
|
168
|
+
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
169
|
|
|
215
170
|
> **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
171
|
|
|
217
172
|
## License
|
|
218
173
|
|
|
219
|
-
[Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/v0.
|
|
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.
|
|
@@ -0,0 +1,134 @@
|
|
|
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.1/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
|
+
<img src="https://raw.githubusercontent.com/MedMLX/segresnet-mlx/main/docs/example.png" alt="Venous-phase CT of a left kidney with a renal tumor, the predicted renal labels on that slice, and a 3D view of the predicted kidney, tumor, vessels and collecting system" width="100%">
|
|
17
|
+
|
|
18
|
+
<sub>Three-phase CT from <a href="https://doi.org/10.7937/k9/tcia.2018.oblamn27">CPTAC-CCRCC</a> case C3N-00380 (The Cancer Imaging Archive, CC BY 4.0), segmented on a crop around each kidney. The 3D view smooths surfaces and hides fragments under 0.5 mL and labels more than 20 mm from the kidney.</sub>
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
| Input | Output |
|
|
23
|
+
| :--- | :--- |
|
|
24
|
+
| Arterial, venous and excretory CT · NIfTI | Renal labels on the input grid |
|
|
25
|
+
|
|
26
|
+
| Model | Weights download | Peak MLX memory | Measured on |
|
|
27
|
+
| :--- | ---: | ---: | :--- |
|
|
28
|
+
| `segresnet-renal-cect` | 76 MB | 4.0 GB | 478×277×161 three-phase CT |
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
uv venv --python 3.13
|
|
34
|
+
source .venv/bin/activate
|
|
35
|
+
uv pip install "segresnet-mlx>=0.4.1"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Run
|
|
39
|
+
|
|
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",
|
|
47
|
+
output_dir="out",
|
|
48
|
+
)
|
|
49
|
+
print(result["outputs"]["mask"])
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Weights download from [`MedMLX/segresnet-renal-cect-mlx`](https://huggingface.co/MedMLX/segresnet-renal-cect-mlx)
|
|
53
|
+
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
|
+
|
|
57
|
+
### Inputs and outputs
|
|
58
|
+
|
|
59
|
+
| Argument | Meaning |
|
|
60
|
+
| --- | --- |
|
|
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 |
|
|
64
|
+
| `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
|
+
| `streaming` | `False` by default; `True` keeps blending intermediates and logits in temporary mapped files |
|
|
67
|
+
| `scratch_dir` | Parent directory for the streaming files; defaults to the system temporary directory |
|
|
68
|
+
|
|
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.
|
|
75
|
+
|
|
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 |
|
|
80
|
+
| :--- | :--- |
|
|
81
|
+
| `torch-order-fp32` (default) | The default float32 profile |
|
|
82
|
+
| `compensated-fp32` | Convolution and GroupNorm accumulate in paired Metal floats, with float32 layer outputs |
|
|
83
|
+
| `compensated-fp48` | The pairs carry through the hidden layers and stitching runs in float64 on the host |
|
|
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.
|
|
92
|
+
|
|
93
|
+
### Python API
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from pathlib import Path
|
|
97
|
+
|
|
98
|
+
import numpy as np
|
|
99
|
+
from segresnet_mlx import BUNDLE_CONFIGS, SegResNetSpec, forward_patch, load_model, predict_logits
|
|
100
|
+
|
|
101
|
+
spec = SegResNetSpec(3, 6, 32, upsample_mode="deconv") # renal CECT network
|
|
102
|
+
network = load_model(Path("segresnet-renal-cect.safetensors"), spec=spec)
|
|
103
|
+
patch = np.zeros((1, 3, 32, 32, 32), dtype=np.float32)
|
|
104
|
+
logits = forward_patch(network, patch) # float32 NCDHW -> float32 NumPy logits
|
|
105
|
+
config = BUNDLE_CONFIGS["renalStructures_CECT_segmentation"]
|
|
106
|
+
volume_logits = predict_logits(patch, config, network=network) # stitched sliding windows
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- `forward_patch` needs spatial sizes divisible by `2 ** len(spec.blocks_up)`.
|
|
110
|
+
- `predict_logits` takes preprocessed arrays of any size and stitches the bundle's
|
|
111
|
+
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)`.
|
|
114
|
+
- `WindowTelemetry` and `BundlePredictor` record bounded progress and timing.
|
|
115
|
+
- Inference requires Apple Silicon with Metal.
|
|
116
|
+
|
|
117
|
+
## Use with MedMLX
|
|
118
|
+
|
|
119
|
+
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.
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
uv tool install --python 3.13 "medmlx[segment,mcp]"
|
|
123
|
+
MEDMLX="$(uv tool dir --bin --color never)/medmlx"
|
|
124
|
+
mkdir -p "$HOME/medmlx-work"
|
|
125
|
+
claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
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`.
|
|
129
|
+
|
|
130
|
+
> **For AI agents:** prefer the MedMLX MCP tools (`list_models`, `describe_model`, `model_readiness`, `run_model`, `get_job`) over writing Python against this package.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
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.
|
|
@@ -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.1"
|
|
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.1/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.1"
|
|
23
23
|
|
|
24
24
|
_EXPORTS = {
|
|
25
25
|
"BUNDLE_CONFIGS": "segresnet_mlx.predictor",
|