mlx-segment-ct 0.3.0__tar.gz → 0.3.2__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 mlx-segment-ct might be problematic. Click here for more details.
- mlx_segment_ct-0.3.2/PKG-INFO +84 -0
- mlx_segment_ct-0.3.2/README.md +57 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/pyproject.toml +7 -7
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/__init__.py +3 -1
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/_types.py +158 -51
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/activations.py +1 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/bundle_transforms.py +40 -7
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/correction_inferer.py +2 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/instance_norm.py +2 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/interactive.py +4 -3
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/labels.py +11 -5
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/medmlx.py +134 -29
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/mlx_network.py +9 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/mlx_point.py +7 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/mlx_point_window.py +2 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/mlx_upsample.py +3 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/projections.py +1 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/restoration.py +4 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/streaming.py +4 -0
- mlx_segment_ct-0.3.0/PKG-INFO +0 -99
- mlx_segment_ct-0.3.0/README.md +0 -71
- mlx_segment_ct-0.3.0/src/mlx_segment_ct/checkpoint_sources.py +0 -48
- mlx_segment_ct-0.3.0/src/mlx_segment_ct/mlx_correction_weights.py +0 -58
- mlx_segment_ct-0.3.0/src/mlx_segment_ct/mlx_weights.py +0 -74
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/.gitignore +0 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/LICENSE +0 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/THIRD_PARTY_NOTICES.md +0 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/correction.py +0 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/mlx_worker.py +0 -0
- {mlx_segment_ct-0.3.0 → mlx_segment_ct-0.3.2}/src/mlx_segment_ct/py.typed +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mlx-segment-ct
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: Native MLX implementation of NV-Segment-CT (VISTA-3D)
|
|
5
|
+
Project-URL: Homepage, https://huggingface.co/MedMLX/vista3d-ct-mlx
|
|
6
|
+
Author: Joseph Sandoval, Alfredo Sandoval Jr.
|
|
7
|
+
License-Expression: Apache-2.0 AND BSD-3-Clause
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: THIRD_PARTY_NOTICES.md
|
|
10
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
11
|
+
Requires-Python: <3.15,>=3.13
|
|
12
|
+
Requires-Dist: medmlx-core==0.2.5
|
|
13
|
+
Requires-Dist: nibabel<6,>=5.3
|
|
14
|
+
Requires-Dist: numpy<3,>=2.0
|
|
15
|
+
Requires-Dist: scipy<2,>=1.14
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: einops<1,>=0.8; extra == 'dev'
|
|
18
|
+
Requires-Dist: hypothesis<7,>=6.140; extra == 'dev'
|
|
19
|
+
Requires-Dist: monai==1.6.1; extra == 'dev'
|
|
20
|
+
Requires-Dist: pyright==1.1.414; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest<10,>=8.4; extra == 'dev'
|
|
22
|
+
Requires-Dist: ruff<1,>=0.13; extra == 'dev'
|
|
23
|
+
Requires-Dist: scikit-image<1,>=0.25; extra == 'dev'
|
|
24
|
+
Requires-Dist: scipy-stubs==1.18.1.1; extra == 'dev'
|
|
25
|
+
Requires-Dist: torch<3,>=2.13; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# mlx-segment-ct
|
|
29
|
+
|
|
30
|
+
Segment CT anatomy automatically or with anatomy names and clicks, using NVIDIA VISTA-3D in native MLX.
|
|
31
|
+
|
|
32
|
+
[CT weights](https://huggingface.co/MedMLX/vista3d-ct-mlx) · [CTMR weights](https://huggingface.co/MedMLX/vista3d-ctmr-mlx)
|
|
33
|
+
|
|
34
|
+
| Input | Output |
|
|
35
|
+
| :--- | :--- |
|
|
36
|
+
| 3D CT · NIfTI | Anatomical labels on the input grid |
|
|
37
|
+
|
|
38
|
+
**Apple Silicon · Metal · Python 3.13 / 3.14** · [uv](https://docs.astral.sh/uv/)
|
|
39
|
+
|
|
40
|
+
## Quick start
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
uv pip install "mlx-segment-ct>=0.3.2"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
NIfTI files explicitly marked in meters or microns are rejected. Inputs with
|
|
47
|
+
unknown spatial units are assumed to use millimeters.
|
|
48
|
+
|
|
49
|
+
The click coordinates below are examples: replace them with voxels inside your
|
|
50
|
+
image and its preprocessed foreground crop. `1` includes a point; `0` excludes it.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from mlx_segment_ct.medmlx import run
|
|
54
|
+
|
|
55
|
+
run(image_path="ct.nii.gz", output_dir="all")
|
|
56
|
+
run(image_path="ct.nii.gz", output_dir="organs", prompt="liver, spleen")
|
|
57
|
+
run(
|
|
58
|
+
image_path="ct.nii.gz", output_dir="points",
|
|
59
|
+
points=[[40, 50, 30], [44, 51, 30]], point_labels=[1, 0],
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Omitting `weights_path` downloads `MedMLX/vista3d-ct-mlx` once and reuses its local
|
|
64
|
+
cache. An explicit model folder contains `automatic.safetensors` and
|
|
65
|
+
`correction.safetensors`. Point coordinates are `(x, y, z)` voxels.
|
|
66
|
+
|
|
67
|
+
The registered `mlx-segment-ctmr` model uses `mlx_segment_ct.medmlx.run_ctmr` and its
|
|
68
|
+
own `MedMLX/vista3d-ctmr-mlx` folder, with CTMR preprocessing and labels selected
|
|
69
|
+
internally. The advanced `run(checkpoint="NV-Segment-CTMR", ...)`
|
|
70
|
+
interface still accepts an explicitly supplied matching folder. It never substitutes
|
|
71
|
+
CT weights for CTMR.
|
|
72
|
+
|
|
73
|
+
The published [NV-Segment-CTMR weights](https://huggingface.co/MedMLX/vista3d-ctmr-mlx)
|
|
74
|
+
cover CT and MRI under noncommercial terms. NVIDIA does not support interactive
|
|
75
|
+
point segmentation with that checkpoint.
|
|
76
|
+
|
|
77
|
+
Downloaded commits are returned in `details.weights_revision`; explicit local
|
|
78
|
+
weights report `null` unless the folder carries a MedMLX download revision.
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
Apache-2.0; license and third-party notices are included in the distribution. Model weights retain their publisher terms.
|
|
83
|
+
|
|
84
|
+
For research and education. Outputs require human review.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# mlx-segment-ct
|
|
2
|
+
|
|
3
|
+
Segment CT anatomy automatically or with anatomy names and clicks, using NVIDIA VISTA-3D in native MLX.
|
|
4
|
+
|
|
5
|
+
[CT weights](https://huggingface.co/MedMLX/vista3d-ct-mlx) · [CTMR weights](https://huggingface.co/MedMLX/vista3d-ctmr-mlx)
|
|
6
|
+
|
|
7
|
+
| Input | Output |
|
|
8
|
+
| :--- | :--- |
|
|
9
|
+
| 3D CT · NIfTI | Anatomical labels on the input grid |
|
|
10
|
+
|
|
11
|
+
**Apple Silicon · Metal · Python 3.13 / 3.14** · [uv](https://docs.astral.sh/uv/)
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
uv pip install "mlx-segment-ct>=0.3.2"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
NIfTI files explicitly marked in meters or microns are rejected. Inputs with
|
|
20
|
+
unknown spatial units are assumed to use millimeters.
|
|
21
|
+
|
|
22
|
+
The click coordinates below are examples: replace them with voxels inside your
|
|
23
|
+
image and its preprocessed foreground crop. `1` includes a point; `0` excludes it.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from mlx_segment_ct.medmlx import run
|
|
27
|
+
|
|
28
|
+
run(image_path="ct.nii.gz", output_dir="all")
|
|
29
|
+
run(image_path="ct.nii.gz", output_dir="organs", prompt="liver, spleen")
|
|
30
|
+
run(
|
|
31
|
+
image_path="ct.nii.gz", output_dir="points",
|
|
32
|
+
points=[[40, 50, 30], [44, 51, 30]], point_labels=[1, 0],
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Omitting `weights_path` downloads `MedMLX/vista3d-ct-mlx` once and reuses its local
|
|
37
|
+
cache. An explicit model folder contains `automatic.safetensors` and
|
|
38
|
+
`correction.safetensors`. Point coordinates are `(x, y, z)` voxels.
|
|
39
|
+
|
|
40
|
+
The registered `mlx-segment-ctmr` model uses `mlx_segment_ct.medmlx.run_ctmr` and its
|
|
41
|
+
own `MedMLX/vista3d-ctmr-mlx` folder, with CTMR preprocessing and labels selected
|
|
42
|
+
internally. The advanced `run(checkpoint="NV-Segment-CTMR", ...)`
|
|
43
|
+
interface still accepts an explicitly supplied matching folder. It never substitutes
|
|
44
|
+
CT weights for CTMR.
|
|
45
|
+
|
|
46
|
+
The published [NV-Segment-CTMR weights](https://huggingface.co/MedMLX/vista3d-ctmr-mlx)
|
|
47
|
+
cover CT and MRI under noncommercial terms. NVIDIA does not support interactive
|
|
48
|
+
point segmentation with that checkpoint.
|
|
49
|
+
|
|
50
|
+
Downloaded commits are returned in `details.weights_revision`; explicit local
|
|
51
|
+
weights report `null` unless the folder carries a MedMLX download revision.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
Apache-2.0; license and third-party notices are included in the distribution. Model weights retain their publisher terms.
|
|
56
|
+
|
|
57
|
+
For research and education. Outputs require human review.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mlx-segment-ct"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.2"
|
|
8
8
|
description = "Native MLX implementation of NV-Segment-CT (VISTA-3D)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
classifiers = ["Operating System :: MacOS :: MacOS X"]
|
|
@@ -13,17 +13,20 @@ license = "Apache-2.0 AND BSD-3-Clause"
|
|
|
13
13
|
license-files = ["LICENSE", "THIRD_PARTY_NOTICES.md"]
|
|
14
14
|
authors = [{ name = "Joseph Sandoval" }, { name = "Alfredo Sandoval Jr." }]
|
|
15
15
|
dependencies = [
|
|
16
|
-
"medmlx-core==0.2.
|
|
16
|
+
"medmlx-core==0.2.5",
|
|
17
17
|
"nibabel>=5.3,<6",
|
|
18
18
|
"numpy>=2.0,<3",
|
|
19
19
|
"scipy>=1.14,<2",
|
|
20
20
|
]
|
|
21
21
|
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://huggingface.co/MedMLX/vista3d-ct-mlx"
|
|
24
|
+
|
|
22
25
|
[project.entry-points."medmlx.models"]
|
|
23
26
|
mlx-segment-ct = "mlx_segment_ct.medmlx:MODEL"
|
|
27
|
+
mlx-segment-ctmr = "mlx_segment_ct.medmlx:CTMR_MODEL"
|
|
24
28
|
|
|
25
29
|
[project.optional-dependencies]
|
|
26
|
-
conversion = ["torch>=2.13,<3"]
|
|
27
30
|
dev = [
|
|
28
31
|
"pyright==1.1.414",
|
|
29
32
|
"monai==1.6.1",
|
|
@@ -56,7 +59,7 @@ select = ["E", "F", "I", "UP", "B", "SIM", "RUF"]
|
|
|
56
59
|
|
|
57
60
|
[tool.pyright]
|
|
58
61
|
include = ["scripts","src","tests"]
|
|
59
|
-
extraPaths = ["src"]
|
|
62
|
+
extraPaths = ["src", "scripts"]
|
|
60
63
|
pythonVersion = "3.13"
|
|
61
64
|
typeCheckingMode = "strict"
|
|
62
65
|
enableTypeIgnoreComments = false
|
|
@@ -72,9 +75,6 @@ ban-relative-imports = "all"
|
|
|
72
75
|
[tool.uv]
|
|
73
76
|
constraint-dependencies = ["setuptools>=84.1.0", "filelock>=4.2.1", "Pillow>=13,<14"]
|
|
74
77
|
|
|
75
|
-
[tool.uv.sources]
|
|
76
|
-
medmlx-core = { git = "https://github.com/MedMLX/medmlx.git", rev = "f98e0924f50228e2b9509474947b9672054b3217", subdirectory = "packages/core" }
|
|
77
|
-
|
|
78
78
|
[tool.hatch.build.targets.sdist]
|
|
79
79
|
only-include = [
|
|
80
80
|
"src/mlx_segment_ct",
|
|
@@ -25,7 +25,7 @@ if TYPE_CHECKING:
|
|
|
25
25
|
from mlx_segment_ct.mlx_worker import automatic_logits
|
|
26
26
|
from mlx_segment_ct.streaming import LabelReducer, bounded_labels, rolling_logits
|
|
27
27
|
|
|
28
|
-
__version__ = "0.3.
|
|
28
|
+
__version__ = "0.3.2"
|
|
29
29
|
|
|
30
30
|
_EXPORTS = {
|
|
31
31
|
"AutomaticModel": "mlx_segment_ct.mlx_network",
|
|
@@ -71,6 +71,7 @@ __all__ = [
|
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
def __getattr__(name: str) -> object:
|
|
74
|
+
"""Load a public export from its module on first access."""
|
|
74
75
|
module = _EXPORTS.get(name)
|
|
75
76
|
if module is None:
|
|
76
77
|
raise AttributeError(f"module 'mlx_segment_ct' has no attribute {name!r}")
|
|
@@ -80,4 +81,5 @@ def __getattr__(name: str) -> object:
|
|
|
80
81
|
|
|
81
82
|
|
|
82
83
|
def __dir__() -> list[str]:
|
|
84
|
+
"""List eager and lazy package exports."""
|
|
83
85
|
return sorted({*globals(), *_EXPORTS})
|
|
@@ -46,44 +46,82 @@ type PatchCoordinates = Sequence[Sequence[slice]]
|
|
|
46
46
|
|
|
47
47
|
class ArrayBoundary[ArrayT](Protocol):
|
|
48
48
|
@property
|
|
49
|
-
def array(self) -> Callable[..., ArrayT]:
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
def array(self) -> Callable[..., ArrayT]:
|
|
50
|
+
"""Return the array constructor for the injected runtime."""
|
|
51
|
+
...
|
|
52
|
+
def eval(self, *args: ArrayT | Sequence[ArrayT] | Mapping[str, ArrayT]) -> None:
|
|
53
|
+
"""Evaluate arrays and collections on the injected runtime."""
|
|
54
|
+
...
|
|
55
|
+
def synchronize(self) -> None:
|
|
56
|
+
"""Wait for outstanding work on the injected runtime."""
|
|
57
|
+
...
|
|
52
58
|
|
|
53
59
|
|
|
54
60
|
class CoreRuntime(MlxRuntime, Protocol):
|
|
55
|
-
def eval(self, *args: array | Mapping[str, array] | Sequence[array]) -> None:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def
|
|
61
|
+
def eval(self, *args: array | Mapping[str, array] | Sequence[array]) -> None:
|
|
62
|
+
"""Evaluate native arrays and their containers."""
|
|
63
|
+
...
|
|
64
|
+
def synchronize(self) -> None:
|
|
65
|
+
"""Wait for outstanding native work to complete."""
|
|
66
|
+
...
|
|
67
|
+
def async_eval(self, *args: ArrayTree) -> None:
|
|
68
|
+
"""Schedule evaluation of native array trees."""
|
|
69
|
+
...
|
|
70
|
+
def ones(self, shape: Sequence[int], dtype: Dtype | None = None) -> array:
|
|
71
|
+
"""Create a native array filled with ones."""
|
|
72
|
+
...
|
|
73
|
+
def sin(self, a: array) -> array:
|
|
74
|
+
"""Compute elementwise sine on a native array."""
|
|
75
|
+
...
|
|
76
|
+
def cos(self, a: array) -> array:
|
|
77
|
+
"""Compute elementwise cosine on a native array."""
|
|
78
|
+
...
|
|
79
|
+
def abs(self, a: array) -> array:
|
|
80
|
+
"""Compute elementwise absolute values."""
|
|
81
|
+
...
|
|
62
82
|
def sum(
|
|
63
83
|
self, a: array, axis: int | Sequence[int] | None = None, keepdims: bool = False
|
|
64
|
-
) -> array:
|
|
84
|
+
) -> array:
|
|
85
|
+
"""Sum array elements over selected axes."""
|
|
86
|
+
...
|
|
65
87
|
def softmax(
|
|
66
88
|
self, a: array, axis: int | Sequence[int] | None = None, *, precise: bool = False
|
|
67
|
-
) -> array:
|
|
89
|
+
) -> array:
|
|
90
|
+
"""Normalize scores along the selected axis."""
|
|
91
|
+
...
|
|
68
92
|
def addmm(
|
|
69
93
|
self, c: array, a: array, b: array, alpha: float = 1.0, beta: float = 1.0
|
|
70
|
-
) -> array:
|
|
94
|
+
) -> array:
|
|
95
|
+
"""Multiply matrices and add the supplied bias."""
|
|
96
|
+
...
|
|
71
97
|
def meshgrid(
|
|
72
98
|
self, *arrays: array, indexing: Literal["xy", "ij"] = "xy", sparse: bool = False
|
|
73
|
-
) -> tuple[array, ...]:
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
) -> tuple[array, ...]:
|
|
100
|
+
"""Create coordinate grids from native axes."""
|
|
101
|
+
...
|
|
102
|
+
def contiguous(self, a: array, /, *, allow_col_major: bool = False) -> array:
|
|
103
|
+
"""Return a contiguous array in an accepted layout."""
|
|
104
|
+
...
|
|
105
|
+
def load(self, file: str, /, format: str | None = None) -> array | dict[str, array]:
|
|
106
|
+
"""Load an array or named tensor mapping from a file."""
|
|
107
|
+
...
|
|
76
108
|
def save_safetensors(
|
|
77
109
|
self, file: str, arrays: Mapping[str, array], metadata: Mapping[str, str] | None = None
|
|
78
|
-
) -> None:
|
|
110
|
+
) -> None:
|
|
111
|
+
"""Write named native arrays to a safetensors file."""
|
|
112
|
+
...
|
|
79
113
|
|
|
80
114
|
|
|
81
115
|
class PointPredictor[ArrayT](Protocol):
|
|
82
|
-
def __call__(self, image: ArrayT, positions: ArrayT, codes: ArrayT, target: int) -> ArrayT:
|
|
116
|
+
def __call__(self, image: ArrayT, positions: ArrayT, codes: ArrayT, target: int) -> ArrayT:
|
|
117
|
+
"""Run point-conditioned prediction for an image and target class."""
|
|
118
|
+
...
|
|
83
119
|
|
|
84
120
|
|
|
85
121
|
class CoordinatePredictor[ArrayT](Protocol):
|
|
86
|
-
def __call__(self, image: ArrayT, coordinates: PatchCoordinates, /) -> ArrayT:
|
|
122
|
+
def __call__(self, image: ArrayT, coordinates: PatchCoordinates, /) -> ArrayT:
|
|
123
|
+
"""Predict a window using its coordinates in the full image."""
|
|
124
|
+
...
|
|
87
125
|
|
|
88
126
|
|
|
89
127
|
class PointOptions(TypedDict, total=False):
|
|
@@ -109,7 +147,9 @@ class PointWindowCall[ArrayT](Protocol):
|
|
|
109
147
|
prev_mask: HostArray | None,
|
|
110
148
|
transpose: bool,
|
|
111
149
|
**kwargs: object,
|
|
112
|
-
) -> HostArray:
|
|
150
|
+
) -> HostArray:
|
|
151
|
+
"""Run point-conditioned window inference and return host scores."""
|
|
152
|
+
...
|
|
113
153
|
|
|
114
154
|
|
|
115
155
|
class Metrics(TypedDict):
|
|
@@ -140,6 +180,7 @@ class InteractiveParameters(TypedDict):
|
|
|
140
180
|
|
|
141
181
|
|
|
142
182
|
class Details(TypedDict, total=False):
|
|
183
|
+
weights_revision: str | None
|
|
143
184
|
mode: Required[str]
|
|
144
185
|
label_prompt: list[int]
|
|
145
186
|
label_names: list[str]
|
|
@@ -180,6 +221,7 @@ class Details(TypedDict, total=False):
|
|
|
180
221
|
|
|
181
222
|
|
|
182
223
|
class PublishedDetails(TypedDict, total=False):
|
|
224
|
+
weights_revision: str | None
|
|
183
225
|
mode: Required[str]
|
|
184
226
|
label_prompt: list[int]
|
|
185
227
|
label_names: list[str]
|
|
@@ -248,53 +290,106 @@ class RunArguments(TypedDict, total=False):
|
|
|
248
290
|
|
|
249
291
|
class NiftiHeader(Protocol):
|
|
250
292
|
@property
|
|
251
|
-
def binaryblock(self) -> bytes:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
def
|
|
255
|
-
|
|
256
|
-
|
|
293
|
+
def binaryblock(self) -> bytes:
|
|
294
|
+
"""Return the binary image header."""
|
|
295
|
+
...
|
|
296
|
+
def __getitem__(self, key: str) -> HostArray:
|
|
297
|
+
"""Read a named image header field."""
|
|
298
|
+
...
|
|
299
|
+
def get(self, key: str) -> HostArray | None:
|
|
300
|
+
"""Return a named header field if present."""
|
|
301
|
+
...
|
|
302
|
+
def get_zooms(self) -> tuple[float, ...]:
|
|
303
|
+
"""Return voxel spacing from the image header."""
|
|
304
|
+
...
|
|
305
|
+
def set_zooms(self, zooms: Sequence[float] | HostArray) -> None:
|
|
306
|
+
"""Set voxel spacing in the image header."""
|
|
307
|
+
...
|
|
308
|
+
def get_xyzt_units(self) -> tuple[str, str]:
|
|
309
|
+
"""Return the declared spatial and temporal units."""
|
|
310
|
+
...
|
|
311
|
+
def as_byteswapped(self, endianness: str | None = None) -> NiftiHeader:
|
|
312
|
+
"""Return a header with the requested byte order."""
|
|
313
|
+
...
|
|
257
314
|
|
|
258
315
|
|
|
259
316
|
class NiftiArrayProxy(Protocol):
|
|
260
317
|
"""File-backed NIfTI data supports conversion without ndarray methods."""
|
|
261
318
|
|
|
262
|
-
def __array__(self, dtype: DTypeLike | None = None) -> NDArray[np.generic]:
|
|
319
|
+
def __array__(self, dtype: DTypeLike | None = None) -> NDArray[np.generic]:
|
|
320
|
+
"""Convert the lazy image data proxy to a host array."""
|
|
321
|
+
...
|
|
263
322
|
|
|
264
323
|
|
|
265
324
|
class NiftiImage(Protocol):
|
|
266
325
|
@property
|
|
267
|
-
def shape(self) -> tuple[int, ...]:
|
|
268
|
-
|
|
326
|
+
def shape(self) -> tuple[int, ...]:
|
|
327
|
+
"""Return the image dimensions."""
|
|
328
|
+
...
|
|
329
|
+
def get_data_dtype(self) -> np.dtype[NumericScalar]:
|
|
330
|
+
"""Return the stored image data dtype."""
|
|
331
|
+
...
|
|
269
332
|
@property
|
|
270
|
-
def header(self) -> NiftiHeader:
|
|
333
|
+
def header(self) -> NiftiHeader:
|
|
334
|
+
"""Return the image header."""
|
|
335
|
+
...
|
|
271
336
|
@property
|
|
272
|
-
def affine(self) -> DoubleArray:
|
|
337
|
+
def affine(self) -> DoubleArray:
|
|
338
|
+
"""Return the voxel-to-world affine."""
|
|
339
|
+
...
|
|
273
340
|
@property
|
|
274
|
-
def dataobj(self) -> HostArray | NiftiArrayProxy:
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
def
|
|
278
|
-
|
|
341
|
+
def dataobj(self) -> HostArray | NiftiArrayProxy:
|
|
342
|
+
"""Return the image array or lazy data proxy."""
|
|
343
|
+
...
|
|
344
|
+
def get_sform(self) -> DoubleArray:
|
|
345
|
+
"""Return the stored sform affine."""
|
|
346
|
+
...
|
|
347
|
+
def get_qform(self) -> DoubleArray:
|
|
348
|
+
"""Return the stored qform affine."""
|
|
349
|
+
...
|
|
350
|
+
def set_sform(self, affine: HostArray, code: int | None = None) -> None:
|
|
351
|
+
"""Set the sform affine and optional code."""
|
|
352
|
+
...
|
|
353
|
+
def set_qform(self, affine: HostArray, code: int | None = None) -> None:
|
|
354
|
+
"""Set the qform affine and optional code."""
|
|
355
|
+
...
|
|
279
356
|
|
|
280
357
|
|
|
281
358
|
class NiftiConstructor(Protocol):
|
|
282
|
-
def __call__(self, dataobj: HostArray, affine: HostArray) -> NiftiImage:
|
|
359
|
+
def __call__(self, dataobj: HostArray, affine: HostArray) -> NiftiImage:
|
|
360
|
+
"""Construct a NIfTI image from data and affine."""
|
|
361
|
+
...
|
|
283
362
|
|
|
284
363
|
|
|
285
364
|
class NiftiRuntime(Protocol):
|
|
286
365
|
@property
|
|
287
|
-
def Nifti1Image(self) -> NiftiConstructor:
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
def
|
|
291
|
-
|
|
366
|
+
def Nifti1Image(self) -> NiftiConstructor:
|
|
367
|
+
"""Return the NIfTI-1 image constructor."""
|
|
368
|
+
...
|
|
369
|
+
def load(self, filename: str) -> object:
|
|
370
|
+
"""Load an image from a path."""
|
|
371
|
+
...
|
|
372
|
+
def save(self, img: NiftiImage, filename: str) -> None:
|
|
373
|
+
"""Write an image to a path."""
|
|
374
|
+
...
|
|
375
|
+
def aff2axcodes(self, aff: HostArray) -> tuple[str | None, ...]:
|
|
376
|
+
"""Determine spatial axis codes from an affine."""
|
|
377
|
+
...
|
|
378
|
+
def io_orientation(self, affine: HostArray) -> DoubleArray:
|
|
379
|
+
"""Determine voxel-axis orientation from an affine."""
|
|
380
|
+
...
|
|
292
381
|
|
|
293
382
|
|
|
294
383
|
class OrientationRuntime(Protocol):
|
|
295
|
-
def axcodes2ornt(self, axcodes: tuple[str | None, ...], labels: None = None) -> DoubleArray:
|
|
296
|
-
|
|
297
|
-
|
|
384
|
+
def axcodes2ornt(self, axcodes: tuple[str | None, ...], labels: None = None) -> DoubleArray:
|
|
385
|
+
"""Convert axis codes to an orientation transform."""
|
|
386
|
+
...
|
|
387
|
+
def ornt_transform(self, start_ornt: DoubleArray, end_ornt: DoubleArray) -> DoubleArray:
|
|
388
|
+
"""Compute the transform between orientations."""
|
|
389
|
+
...
|
|
390
|
+
def inv_ornt_aff(self, ornt: DoubleArray, shape: Sequence[int]) -> DoubleArray:
|
|
391
|
+
"""Return the inverse voxel affine for an orientation and shape."""
|
|
392
|
+
...
|
|
298
393
|
|
|
299
394
|
|
|
300
395
|
class RollingMetrics(TypedDict):
|
|
@@ -323,25 +418,35 @@ class SlidingWindowCall(Protocol):
|
|
|
323
418
|
roi_weight_map: ArrayValue | None,
|
|
324
419
|
with_coord: bool,
|
|
325
420
|
**kwargs: object,
|
|
326
|
-
) -> HostArray:
|
|
421
|
+
) -> HostArray:
|
|
422
|
+
"""Run overlapping window inference and return combined host scores."""
|
|
423
|
+
...
|
|
327
424
|
|
|
328
425
|
|
|
329
426
|
class SlidingWindowNamespace(Protocol):
|
|
330
427
|
@property
|
|
331
|
-
def sliding_window_inference(self) -> SlidingWindowCall:
|
|
428
|
+
def sliding_window_inference(self) -> SlidingWindowCall:
|
|
429
|
+
"""Return the sliding-window inference callable."""
|
|
430
|
+
...
|
|
332
431
|
|
|
333
432
|
|
|
334
433
|
class StandInRuntime[ArrayT, DtypeT](ArrayBoundary[ArrayT], Protocol):
|
|
335
434
|
@property
|
|
336
|
-
def float32(self) -> DtypeT:
|
|
337
|
-
|
|
435
|
+
def float32(self) -> DtypeT:
|
|
436
|
+
"""Return the injected runtime float32 dtype."""
|
|
437
|
+
...
|
|
438
|
+
def sum(self, a: ArrayT) -> ArrayT | NumericScalar:
|
|
439
|
+
"""Sum the supplied array values."""
|
|
440
|
+
...
|
|
338
441
|
|
|
339
442
|
|
|
340
443
|
type Float32Dtype = Dtype | type[np.float32]
|
|
341
444
|
|
|
342
445
|
|
|
343
446
|
class Float32Cast[ArrayT, DtypeT](Protocol):
|
|
344
|
-
def astype(self, dtype: DtypeT) -> ArrayT:
|
|
447
|
+
def astype(self, dtype: DtypeT) -> ArrayT:
|
|
448
|
+
"""Convert the array to the requested dtype."""
|
|
449
|
+
...
|
|
345
450
|
|
|
346
451
|
|
|
347
452
|
class RollingMetricsBuilder(TypedDict):
|
|
@@ -375,4 +480,6 @@ class NumericArrayArithmetic[ArrayT](Protocol):
|
|
|
375
480
|
fixtures; its bundled array operator declaration omits those scalar types.
|
|
376
481
|
"""
|
|
377
482
|
|
|
378
|
-
def __add__(self, other: ArrayValue | NumericScalar | float, /) -> ArrayT:
|
|
483
|
+
def __add__(self, other: ArrayValue | NumericScalar | float, /) -> ArrayT:
|
|
484
|
+
"""Add an array or scalar to the native values."""
|
|
485
|
+
...
|