nnunet-mlx 0.5.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.
Potentially problematic release.
This version of nnunet-mlx might be problematic. Click here for more details.
- nnunet_mlx-0.5.1/.gitignore +19 -0
- nnunet_mlx-0.5.1/LICENSE +202 -0
- nnunet_mlx-0.5.1/PKG-INFO +166 -0
- nnunet_mlx-0.5.1/README.md +117 -0
- nnunet_mlx-0.5.1/THIRD_PARTY_NOTICES.md +82 -0
- nnunet_mlx-0.5.1/pyproject.toml +133 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/__init__.py +59 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/cli.py +72 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/commands/__init__.py +1 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/commands/conversion.py +109 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/commands/parsing.py +34 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/commands/prediction.py +379 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/commands/runtime.py +28 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/contracts.py +71 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/conversion.py +517 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/data/__init__.py +1 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/data/cases.py +226 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/data/labels.py +145 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/data/preprocessing.py +300 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/data/resampling.py +388 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/errors.py +5 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/__init__.py +1 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_chunked_conv.py +127 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_fused_ordered_conv.py +393 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_fused_ordered_norm.py +271 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_instance_norm.py +243 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_labels.py +133 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_normalized_labels.py +97 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_numeric.py +26 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_ordered_conv.py +169 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/metal_restore.py +447 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/kernels/types.py +33 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/medmlx.py +309 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/medmlx_types.py +40 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/__init__.py +1 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/factory.py +62 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/folder.py +271 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/metadata.py +81 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/network.py +720 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/residency.py +96 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/source_plans.py +94 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/topology.py +408 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/types.py +24 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/model/weights.py +200 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/plans.py +363 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/__init__.py +1 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/arithmetic.py +415 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/ensembling.py +285 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/export.py +567 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/inference.py +394 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/io.py +168 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/nifti.py +117 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/pipeline.py +856 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/postprocessing.py +326 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/restore.py +233 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/sliding_window.py +505 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/prediction/source.py +250 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/py.typed +0 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/runtime.py +216 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/runtime_types.py +416 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/storage/__init__.py +1 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/storage/checkpoint.py +273 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/storage/conversion.py +114 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/storage/filesystem.py +34 -0
- nnunet_mlx-0.5.1/src/nnunet_mlx/storage/imageio.py +660 -0
nnunet_mlx-0.5.1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: nnunet-mlx
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Summary: MLX-native nnU-Net v2 inference on Apple Silicon
|
|
5
|
+
Project-URL: Repository, https://github.com/MedMLX/nnunet-mlx
|
|
6
|
+
Project-URL: Issues, https://github.com/MedMLX/nnunet-mlx/issues
|
|
7
|
+
Project-URL: Documentation, https://github.com/MedMLX/nnunet-mlx/tree/main/docs
|
|
8
|
+
Author: Joseph Sandoval
|
|
9
|
+
License-Expression: Apache-2.0 AND MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: THIRD_PARTY_NOTICES.md
|
|
12
|
+
Keywords: apple-silicon,image-segmentation,medical-imaging,mlx,nnunet
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
21
|
+
Requires-Python: <3.15,>=3.13
|
|
22
|
+
Requires-Dist: blosc2<5,>=3.3.2
|
|
23
|
+
Requires-Dist: imagecodecs<2027,>=2025
|
|
24
|
+
Requires-Dist: medmlx-core==0.2.3
|
|
25
|
+
Requires-Dist: mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'
|
|
26
|
+
Requires-Dist: nibabel<6,>=5.3
|
|
27
|
+
Requires-Dist: numpy<3,>=2.0
|
|
28
|
+
Requires-Dist: pillow<14,>=13.0.0
|
|
29
|
+
Requires-Dist: safetensors<1,>=0.6
|
|
30
|
+
Requires-Dist: scikit-image==0.26.0
|
|
31
|
+
Requires-Dist: scipy==1.18.1
|
|
32
|
+
Requires-Dist: simpleitk==2.5.6
|
|
33
|
+
Requires-Dist: tifffile<2027,>=2025
|
|
34
|
+
Requires-Dist: typer==0.27.1
|
|
35
|
+
Provides-Extra: conversion
|
|
36
|
+
Requires-Dist: torch==2.13.0; extra == 'conversion'
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: hypothesis<7,>=6; extra == 'dev'
|
|
39
|
+
Requires-Dist: matplotlib<4,>=3.10; extra == 'dev'
|
|
40
|
+
Requires-Dist: pyright==1.1.414; extra == 'dev'
|
|
41
|
+
Requires-Dist: pytest<10,>=8.4; extra == 'dev'
|
|
42
|
+
Requires-Dist: ruff<1,>=0.13; extra == 'dev'
|
|
43
|
+
Provides-Extra: oracle
|
|
44
|
+
Requires-Dist: dynamic-network-architectures==0.4.4; extra == 'oracle'
|
|
45
|
+
Requires-Dist: nnunetv2==2.8.1; extra == 'oracle'
|
|
46
|
+
Requires-Dist: torch==2.13.0; extra == 'oracle'
|
|
47
|
+
Requires-Dist: urllib3<3,>=2.8; extra == 'oracle'
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
|
|
50
|
+
# nnunet-mlx
|
|
51
|
+
|
|
52
|
+
[nnU-Net v2](https://github.com/MIC-DKFZ/nnUNet) inference in native MLX
|
|
53
|
+
for Apple Silicon. Run existing nnU-Net models locally on Mac.
|
|
54
|
+
|
|
55
|
+
- Convert and run pretrained nnU-Net v2 model folders
|
|
56
|
+
- 2D and 3D `PlainConvUNet` and `ResidualEncoderUNet`
|
|
57
|
+
- FP32 using MLX; PyTorch is only needed to convert `.pth` checkpoints
|
|
58
|
+
|
|
59
|
+
Part of [MedMLX](https://github.com/MedMLX).
|
|
60
|
+
[Technical notes](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/technical.md) · [Compatibility](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/compatibility.md)
|
|
61
|
+
|
|
62
|
+
[Quick start](#quick-start) · [Input and output](#input-and-output) · [Technical details](#technical-details) · [License](#license)
|
|
63
|
+
|
|
64
|
+
## Requirements
|
|
65
|
+
|
|
66
|
+
Apple Silicon Mac with Metal, [uv](https://docs.astral.sh/uv/), and conda or mamba
|
|
67
|
+
(setup uses it to build a pinned Python 3.13 environment).
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
Prepare the source checkout:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
git clone https://github.com/MedMLX/nnunet-mlx.git
|
|
75
|
+
cd nnunet-mlx
|
|
76
|
+
make env # creates .venv with MLX on Metal
|
|
77
|
+
uv pip install --python .venv/bin/python -e '.[conversion]' # to convert .pth checkpoints
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Use `.venv/bin/nnunet-mlx`, or activate `.venv`. Every command accepts `--help`.
|
|
81
|
+
|
|
82
|
+
Convert an upstream nnU-Net model folder once:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
nnunet-mlx convert model-folder \
|
|
86
|
+
--source-model-folder /path/to/upstream-model \
|
|
87
|
+
--output-model-folder mlx-model
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Predict one case, passing one `--input` per modality in channel order:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
nnunet-mlx model predict \
|
|
94
|
+
--model-folder mlx-model \
|
|
95
|
+
--input case_0000.nii.gz \
|
|
96
|
+
--output-prefix predictions/case
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Use `nnunet-mlx model predict-folder` for a whole folder. Add `--overwrite` to replace
|
|
100
|
+
existing output, or `--continue-existing` to skip finished cases.
|
|
101
|
+
|
|
102
|
+
Only convert checkpoints you trust: `.pth` files are pickles. See [SECURITY.md](https://github.com/MedMLX/nnunet-mlx/blob/main/SECURITY.md).
|
|
103
|
+
|
|
104
|
+
### Python
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from nnunet_mlx import ModelFolderPredictor, load_model_bundle
|
|
108
|
+
|
|
109
|
+
bundle = load_model_bundle("mlx-model", configuration="3d_fullres")
|
|
110
|
+
predictor = ModelFolderPredictor(bundle)
|
|
111
|
+
result = predictor.predict_case(
|
|
112
|
+
["case_0000.nii.gz"], "predictions/case", save_probabilities=False, overwrite=False,
|
|
113
|
+
)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
For a single-channel 3D class model,
|
|
117
|
+
`predictor.predict_nifti(image)` accepts a NiBabel NIfTI-1 image and returns local
|
|
118
|
+
labels on its original grid without intermediate files. Fold logits stay on Metal
|
|
119
|
+
except where restoration needs the host route (separate-Z or non-linear
|
|
120
|
+
resampling). Cascades and regions use the file APIs above.
|
|
121
|
+
|
|
122
|
+
The model is also discoverable by [medmlx](https://github.com/MedMLX/medmlx)
|
|
123
|
+
as `nnunet`; see [docs/technical.md](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/technical.md) for the runner.
|
|
124
|
+
|
|
125
|
+
## Input and output
|
|
126
|
+
|
|
127
|
+
Supply one NIfTI file per input channel in the model's channel order. Prediction
|
|
128
|
+
commands write segmentation files under the selected output prefix or directory;
|
|
129
|
+
probability export is optional. Supported models and configurations are listed
|
|
130
|
+
below and in the [compatibility notes](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/compatibility.md).
|
|
131
|
+
|
|
132
|
+
| Area | Supported |
|
|
133
|
+
| --- | --- |
|
|
134
|
+
| Networks | 2D and 3D `PlainConvUNet` and `ResidualEncoderUNet` |
|
|
135
|
+
| Configurations | `2d`, `3d_lowres`, `3d_fullres`, cascades |
|
|
136
|
+
| Inference | Gaussian sliding window, mirroring, fold and configuration ensembles, probabilities |
|
|
137
|
+
| Precision | FP32 |
|
|
138
|
+
|
|
139
|
+
Anything else fails with a clear error rather than falling back. Pretrained-model
|
|
140
|
+
support varies; see [Compatibility](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/compatibility.md).
|
|
141
|
+
|
|
142
|
+
## Technical details
|
|
143
|
+
|
|
144
|
+
Targets nnU-Net v2.8.1 and dynamic-network-architectures v0.4.4. Networks, conversion
|
|
145
|
+
and the prediction path are compared against the upstream PyTorch implementation on
|
|
146
|
+
seeded-weight and synthetic inputs and on selected released models (see
|
|
147
|
+
[Compatibility](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/compatibility.md)); agreement on other models or data is not implied.
|
|
148
|
+
Development, parity testing, the PancCTMultiTalentV2 staging recipe and the runner
|
|
149
|
+
contract are in [docs/technical.md](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/technical.md); see also
|
|
150
|
+
[Architecture](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/architecture.md) and [Roadmap](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/roadmap.md).
|
|
151
|
+
|
|
152
|
+
## Intended use
|
|
153
|
+
|
|
154
|
+
Intended for research and education, not clinical diagnosis or treatment decisions.
|
|
155
|
+
Outputs require human review.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
Apache-2.0; see [LICENSE](https://github.com/MedMLX/nnunet-mlx/blob/main/LICENSE) and [THIRD_PARTY_NOTICES.md](https://github.com/MedMLX/nnunet-mlx/blob/main/THIRD_PARTY_NOTICES.md). Kernels derived from MLX keep
|
|
160
|
+
their MIT license. Pretrained nnU-Net weights have their own licenses and are not
|
|
161
|
+
distributed here. Please cite via [CITATION.cff](https://github.com/MedMLX/nnunet-mlx/blob/main/CITATION.cff) and cite
|
|
162
|
+
[nnU-Net](https://github.com/MIC-DKFZ/nnUNet).
|
|
163
|
+
|
|
164
|
+
## Implementation mapping
|
|
165
|
+
|
|
166
|
+
[Central implementation map](https://github.com/MedMLX/Med-MLX/blob/main/implementation-maps/nnunet-mlx.json) records upstream-to-native changes, source references and qualification scope.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# nnunet-mlx
|
|
2
|
+
|
|
3
|
+
[nnU-Net v2](https://github.com/MIC-DKFZ/nnUNet) inference in native MLX
|
|
4
|
+
for Apple Silicon. Run existing nnU-Net models locally on Mac.
|
|
5
|
+
|
|
6
|
+
- Convert and run pretrained nnU-Net v2 model folders
|
|
7
|
+
- 2D and 3D `PlainConvUNet` and `ResidualEncoderUNet`
|
|
8
|
+
- FP32 using MLX; PyTorch is only needed to convert `.pth` checkpoints
|
|
9
|
+
|
|
10
|
+
Part of [MedMLX](https://github.com/MedMLX).
|
|
11
|
+
[Technical notes](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/technical.md) · [Compatibility](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/compatibility.md)
|
|
12
|
+
|
|
13
|
+
[Quick start](#quick-start) · [Input and output](#input-and-output) · [Technical details](#technical-details) · [License](#license)
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
Apple Silicon Mac with Metal, [uv](https://docs.astral.sh/uv/), and conda or mamba
|
|
18
|
+
(setup uses it to build a pinned Python 3.13 environment).
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
Prepare the source checkout:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
git clone https://github.com/MedMLX/nnunet-mlx.git
|
|
26
|
+
cd nnunet-mlx
|
|
27
|
+
make env # creates .venv with MLX on Metal
|
|
28
|
+
uv pip install --python .venv/bin/python -e '.[conversion]' # to convert .pth checkpoints
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Use `.venv/bin/nnunet-mlx`, or activate `.venv`. Every command accepts `--help`.
|
|
32
|
+
|
|
33
|
+
Convert an upstream nnU-Net model folder once:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
nnunet-mlx convert model-folder \
|
|
37
|
+
--source-model-folder /path/to/upstream-model \
|
|
38
|
+
--output-model-folder mlx-model
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Predict one case, passing one `--input` per modality in channel order:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
nnunet-mlx model predict \
|
|
45
|
+
--model-folder mlx-model \
|
|
46
|
+
--input case_0000.nii.gz \
|
|
47
|
+
--output-prefix predictions/case
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Use `nnunet-mlx model predict-folder` for a whole folder. Add `--overwrite` to replace
|
|
51
|
+
existing output, or `--continue-existing` to skip finished cases.
|
|
52
|
+
|
|
53
|
+
Only convert checkpoints you trust: `.pth` files are pickles. See [SECURITY.md](https://github.com/MedMLX/nnunet-mlx/blob/main/SECURITY.md).
|
|
54
|
+
|
|
55
|
+
### Python
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from nnunet_mlx import ModelFolderPredictor, load_model_bundle
|
|
59
|
+
|
|
60
|
+
bundle = load_model_bundle("mlx-model", configuration="3d_fullres")
|
|
61
|
+
predictor = ModelFolderPredictor(bundle)
|
|
62
|
+
result = predictor.predict_case(
|
|
63
|
+
["case_0000.nii.gz"], "predictions/case", save_probabilities=False, overwrite=False,
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
For a single-channel 3D class model,
|
|
68
|
+
`predictor.predict_nifti(image)` accepts a NiBabel NIfTI-1 image and returns local
|
|
69
|
+
labels on its original grid without intermediate files. Fold logits stay on Metal
|
|
70
|
+
except where restoration needs the host route (separate-Z or non-linear
|
|
71
|
+
resampling). Cascades and regions use the file APIs above.
|
|
72
|
+
|
|
73
|
+
The model is also discoverable by [medmlx](https://github.com/MedMLX/medmlx)
|
|
74
|
+
as `nnunet`; see [docs/technical.md](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/technical.md) for the runner.
|
|
75
|
+
|
|
76
|
+
## Input and output
|
|
77
|
+
|
|
78
|
+
Supply one NIfTI file per input channel in the model's channel order. Prediction
|
|
79
|
+
commands write segmentation files under the selected output prefix or directory;
|
|
80
|
+
probability export is optional. Supported models and configurations are listed
|
|
81
|
+
below and in the [compatibility notes](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/compatibility.md).
|
|
82
|
+
|
|
83
|
+
| Area | Supported |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| Networks | 2D and 3D `PlainConvUNet` and `ResidualEncoderUNet` |
|
|
86
|
+
| Configurations | `2d`, `3d_lowres`, `3d_fullres`, cascades |
|
|
87
|
+
| Inference | Gaussian sliding window, mirroring, fold and configuration ensembles, probabilities |
|
|
88
|
+
| Precision | FP32 |
|
|
89
|
+
|
|
90
|
+
Anything else fails with a clear error rather than falling back. Pretrained-model
|
|
91
|
+
support varies; see [Compatibility](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/compatibility.md).
|
|
92
|
+
|
|
93
|
+
## Technical details
|
|
94
|
+
|
|
95
|
+
Targets nnU-Net v2.8.1 and dynamic-network-architectures v0.4.4. Networks, conversion
|
|
96
|
+
and the prediction path are compared against the upstream PyTorch implementation on
|
|
97
|
+
seeded-weight and synthetic inputs and on selected released models (see
|
|
98
|
+
[Compatibility](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/compatibility.md)); agreement on other models or data is not implied.
|
|
99
|
+
Development, parity testing, the PancCTMultiTalentV2 staging recipe and the runner
|
|
100
|
+
contract are in [docs/technical.md](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/technical.md); see also
|
|
101
|
+
[Architecture](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/architecture.md) and [Roadmap](https://github.com/MedMLX/nnunet-mlx/blob/main/docs/roadmap.md).
|
|
102
|
+
|
|
103
|
+
## Intended use
|
|
104
|
+
|
|
105
|
+
Intended for research and education, not clinical diagnosis or treatment decisions.
|
|
106
|
+
Outputs require human review.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
Apache-2.0; see [LICENSE](https://github.com/MedMLX/nnunet-mlx/blob/main/LICENSE) and [THIRD_PARTY_NOTICES.md](https://github.com/MedMLX/nnunet-mlx/blob/main/THIRD_PARTY_NOTICES.md). Kernels derived from MLX keep
|
|
111
|
+
their MIT license. Pretrained nnU-Net weights have their own licenses and are not
|
|
112
|
+
distributed here. Please cite via [CITATION.cff](https://github.com/MedMLX/nnunet-mlx/blob/main/CITATION.cff) and cite
|
|
113
|
+
[nnU-Net](https://github.com/MIC-DKFZ/nnUNet).
|
|
114
|
+
|
|
115
|
+
## Implementation mapping
|
|
116
|
+
|
|
117
|
+
[Central implementation map](https://github.com/MedMLX/Med-MLX/blob/main/implementation-maps/nnunet-mlx.json) records upstream-to-native changes, source references and qualification scope.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
This repository implements compatibility with the following upstream projects.
|
|
4
|
+
Their licenses apply to upstream code and dependencies; the repository's own
|
|
5
|
+
license remains in `LICENSE`.
|
|
6
|
+
|
|
7
|
+
## nnU-Net
|
|
8
|
+
|
|
9
|
+
- Project: MIC-DKFZ nnU-Net
|
|
10
|
+
- Source: <https://github.com/MIC-DKFZ/nnUNet>
|
|
11
|
+
- Compatibility pin: v2.8.1,
|
|
12
|
+
`468cf803df9b267150ae2b6c0c59b8ac84f16227`
|
|
13
|
+
- License: Apache License 2.0
|
|
14
|
+
|
|
15
|
+
Selected later changes are adapted for the MLX project without changing that
|
|
16
|
+
reference pin: foreground sampling store v1 at
|
|
17
|
+
[the September 14 merge](https://github.com/MIC-DKFZ/nnUNet/commit/ded2aa3a4c81a9caae37054224d8ebac2d19a061)
|
|
18
|
+
and [float32 resampling intermediates](https://github.com/MIC-DKFZ/nnUNet/commit/54c7480e2a8dc1798856b6463ca8fe11197d7e36).
|
|
19
|
+
See the [data-update contract](docs/port/nnunet-v2/spec.md#selected-upstream-data-and-io-updates).
|
|
20
|
+
|
|
21
|
+
## dynamic-network-architectures
|
|
22
|
+
|
|
23
|
+
- Project: MIC-DKFZ dynamic-network-architectures
|
|
24
|
+
- Source: <https://github.com/MIC-DKFZ/dynamic-network-architectures>
|
|
25
|
+
- Reference pin: v0.4.4, `d35f85c7b92cbf3e9443b412fdc7c81f8e2e7b12`
|
|
26
|
+
- License: Apache License 2.0
|
|
27
|
+
|
|
28
|
+
## MLX
|
|
29
|
+
|
|
30
|
+
- Project: Apple MLX
|
|
31
|
+
- Source: <https://github.com/ml-explore/mlx>
|
|
32
|
+
- Historical MLX reference recorded for this port: v0.32.3,
|
|
33
|
+
`64ea011cb65f14d9ce2737e60db9a4ae91ed7441`
|
|
34
|
+
- Declared runtime dependency: `mlx==0.32.4` (see `pyproject.toml`).
|
|
35
|
+
This runtime version is separate from the historical source reference above.
|
|
36
|
+
- Derived kernels retain Apple copyright and MIT terms in
|
|
37
|
+
`THIRD_PARTY_NOTICES.md`; per-file source notes also record
|
|
38
|
+
the MLX fork revision for the migrated label-reduction kernel.
|
|
39
|
+
- License: MIT
|
|
40
|
+
|
|
41
|
+
Pretrained nnU-Net weights remain subject to the licenses and terms of their
|
|
42
|
+
training datasets and distributors. This repository does not redistribute
|
|
43
|
+
weights.
|
|
44
|
+
|
|
45
|
+
## Project notice
|
|
46
|
+
|
|
47
|
+
nnU-Net MLX
|
|
48
|
+
|
|
49
|
+
This product includes software developed by Joseph Sandoval and is licensed
|
|
50
|
+
under the Apache License, Version 2.0 (see LICENSE).
|
|
51
|
+
|
|
52
|
+
Kernels in src/nnunet_mlx/kernels/ are derived in part from Apple MLX,
|
|
53
|
+
Copyright 2023 Apple Inc., licensed under the MIT License
|
|
54
|
+
(see THIRD_PARTY_NOTICES.md).
|
|
55
|
+
|
|
56
|
+
See THIRD_PARTY_NOTICES.md for the upstream projects this software is
|
|
57
|
+
compatible with.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Full license: MLX-LICENSE
|
|
61
|
+
|
|
62
|
+
MIT License
|
|
63
|
+
|
|
64
|
+
Copyright © 2023 Apple Inc.
|
|
65
|
+
|
|
66
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
67
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
68
|
+
in the Software without restriction, including without limitation the rights
|
|
69
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
70
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
71
|
+
furnished to do so, subject to the following conditions:
|
|
72
|
+
|
|
73
|
+
The above copyright notice and this permission notice shall be included in all
|
|
74
|
+
copies or substantial portions of the Software.
|
|
75
|
+
|
|
76
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
77
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
78
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
79
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
80
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
81
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
82
|
+
SOFTWARE.
|