flexray-mlx 0.2.6__tar.gz → 0.2.7__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.
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/PKG-INFO +9 -7
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/README.md +6 -4
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/pyproject.toml +5 -8
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/src/flexray_mlx/__init__.py +1 -1
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/src/flexray_mlx/_types.py +0 -1
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/src/flexray_mlx/medmlx.py +10 -31
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/.gitignore +0 -0
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/LICENSE +0 -0
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/THIRD_PARTY_NOTICES.md +0 -0
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/src/flexray_mlx/_kernels.py +0 -0
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/src/flexray_mlx/_random.py +0 -0
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/src/flexray_mlx/mlx_model.py +0 -0
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/src/flexray_mlx/py.typed +0 -0
- {flexray_mlx-0.2.6 → flexray_mlx-0.2.7}/src/flexray_mlx/tta.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: flexray-mlx
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Segment anatomical structures in radiographs with FleXray and native MLX
|
|
5
5
|
Project-URL: Homepage, https://medmlx.org
|
|
6
|
-
Project-URL: Documentation, https://github.com/MedMLX/flexray-mlx/blob/v0.2.
|
|
6
|
+
Project-URL: Documentation, https://github.com/MedMLX/flexray-mlx/blob/v0.2.7/README.md
|
|
7
7
|
Project-URL: Repository, https://github.com/MedMLX/flexray-mlx
|
|
8
8
|
Project-URL: Issues, https://github.com/MedMLX/flexray-mlx/issues
|
|
9
9
|
Project-URL: Weights, https://huggingface.co/MedMLX/flexray-mlx
|
|
@@ -24,7 +24,7 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
|
24
24
|
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
25
25
|
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
26
26
|
Requires-Python: <3.14,>=3.13
|
|
27
|
-
Requires-Dist: medmlx-core
|
|
27
|
+
Requires-Dist: medmlx-core<0.3,>=0.2.6
|
|
28
28
|
Requires-Dist: mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'
|
|
29
29
|
Requires-Dist: numpy<3,>=2.0
|
|
30
30
|
Requires-Dist: pillow<14,>=13
|
|
@@ -45,14 +45,14 @@ Segment anatomical structures in radiographs with FleXray and native MLX.
|
|
|
45
45
|
|
|
46
46
|
[](https://pypi.org/project/flexray-mlx/)
|
|
47
47
|
[](https://pypi.org/project/flexray-mlx/)
|
|
48
|
-
[](https://github.com/MedMLX/flexray-mlx/blob/v0.2.
|
|
48
|
+
[](https://github.com/MedMLX/flexray-mlx/blob/v0.2.7/LICENSE)
|
|
49
49
|
[](https://github.com/ml-explore/mlx)
|
|
50
50
|
[](https://huggingface.co/MedMLX/flexray-mlx)
|
|
51
51
|
[](https://github.com/MedMLX/medmlx)
|
|
52
52
|
|
|
53
53
|
[Model weights](https://huggingface.co/MedMLX/flexray-mlx) · [MedMLX](https://github.com/MedMLX/medmlx)
|
|
54
54
|
|
|
55
|
-
<img src="https://raw.githubusercontent.com/MedMLX/flexray-mlx/v0.2.
|
|
55
|
+
<img src="https://raw.githubusercontent.com/MedMLX/flexray-mlx/v0.2.7/docs/showcase.png" alt="Chest radiograph with lung, heart and individual rib segmentations" width="100%">
|
|
56
56
|
|
|
57
57
|
</div>
|
|
58
58
|
|
|
@@ -60,6 +60,8 @@ Segment anatomical structures in radiographs with FleXray and native MLX.
|
|
|
60
60
|
| :--- | :--- |
|
|
61
61
|
| Raster image or single-frame DICOM | Structure masks and probabilities |
|
|
62
62
|
|
|
63
|
+
Weights: 2.0 GB download, all five ensemble members. Peak MLX memory: 1.2 GB for a 1929×2207 chest radiograph with the default single model.
|
|
64
|
+
|
|
63
65
|
## Use with MedMLX
|
|
64
66
|
|
|
65
67
|
The [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) is the lowest-friction way to use this model. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run `flexray` for you.
|
|
@@ -80,7 +82,7 @@ For Codex, use `codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-wor
|
|
|
80
82
|
```bash
|
|
81
83
|
uv venv --python 3.13
|
|
82
84
|
source .venv/bin/activate
|
|
83
|
-
uv pip install "flexray-mlx>=0.2.
|
|
85
|
+
uv pip install "flexray-mlx>=0.2.7"
|
|
84
86
|
```
|
|
85
87
|
|
|
86
88
|
## Run
|
|
@@ -173,6 +175,6 @@ to follow the bundle. Inference needs Apple Silicon with Metal and has no CPU fa
|
|
|
173
175
|
|
|
174
176
|
## License
|
|
175
177
|
|
|
176
|
-
[Apache-2.0](https://github.com/MedMLX/flexray-mlx/blob/v0.2.
|
|
178
|
+
[Apache-2.0](https://github.com/MedMLX/flexray-mlx/blob/v0.2.7/LICENSE). See [third-party notices](https://github.com/MedMLX/flexray-mlx/blob/v0.2.7/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms. FleXray weights are noncommercial (CC-BY-NC-4.0).
|
|
177
179
|
|
|
178
180
|
For research and education. Outputs require human review.
|
|
@@ -6,14 +6,14 @@ Segment anatomical structures in radiographs with FleXray and native MLX.
|
|
|
6
6
|
|
|
7
7
|
[](https://pypi.org/project/flexray-mlx/)
|
|
8
8
|
[](https://pypi.org/project/flexray-mlx/)
|
|
9
|
-
[](https://github.com/MedMLX/flexray-mlx/blob/v0.2.
|
|
9
|
+
[](https://github.com/MedMLX/flexray-mlx/blob/v0.2.7/LICENSE)
|
|
10
10
|
[](https://github.com/ml-explore/mlx)
|
|
11
11
|
[](https://huggingface.co/MedMLX/flexray-mlx)
|
|
12
12
|
[](https://github.com/MedMLX/medmlx)
|
|
13
13
|
|
|
14
14
|
[Model weights](https://huggingface.co/MedMLX/flexray-mlx) · [MedMLX](https://github.com/MedMLX/medmlx)
|
|
15
15
|
|
|
16
|
-
<img src="https://raw.githubusercontent.com/MedMLX/flexray-mlx/v0.2.
|
|
16
|
+
<img src="https://raw.githubusercontent.com/MedMLX/flexray-mlx/v0.2.7/docs/showcase.png" alt="Chest radiograph with lung, heart and individual rib segmentations" width="100%">
|
|
17
17
|
|
|
18
18
|
</div>
|
|
19
19
|
|
|
@@ -21,6 +21,8 @@ Segment anatomical structures in radiographs with FleXray and native MLX.
|
|
|
21
21
|
| :--- | :--- |
|
|
22
22
|
| Raster image or single-frame DICOM | Structure masks and probabilities |
|
|
23
23
|
|
|
24
|
+
Weights: 2.0 GB download, all five ensemble members. Peak MLX memory: 1.2 GB for a 1929×2207 chest radiograph with the default single model.
|
|
25
|
+
|
|
24
26
|
## Use with MedMLX
|
|
25
27
|
|
|
26
28
|
The [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) is the lowest-friction way to use this model. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run `flexray` for you.
|
|
@@ -41,7 +43,7 @@ For Codex, use `codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-wor
|
|
|
41
43
|
```bash
|
|
42
44
|
uv venv --python 3.13
|
|
43
45
|
source .venv/bin/activate
|
|
44
|
-
uv pip install "flexray-mlx>=0.2.
|
|
46
|
+
uv pip install "flexray-mlx>=0.2.7"
|
|
45
47
|
```
|
|
46
48
|
|
|
47
49
|
## Run
|
|
@@ -134,6 +136,6 @@ to follow the bundle. Inference needs Apple Silicon with Metal and has no CPU fa
|
|
|
134
136
|
|
|
135
137
|
## License
|
|
136
138
|
|
|
137
|
-
[Apache-2.0](https://github.com/MedMLX/flexray-mlx/blob/v0.2.
|
|
139
|
+
[Apache-2.0](https://github.com/MedMLX/flexray-mlx/blob/v0.2.7/LICENSE). See [third-party notices](https://github.com/MedMLX/flexray-mlx/blob/v0.2.7/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms. FleXray weights are noncommercial (CC-BY-NC-4.0).
|
|
138
140
|
|
|
139
141
|
For research and education. Outputs require human review.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "flexray-mlx"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.7"
|
|
8
8
|
description = "Segment anatomical structures in radiographs with FleXray and native MLX"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.13,<3.14"
|
|
@@ -37,7 +37,7 @@ authors = [
|
|
|
37
37
|
{ name = "Alfredo Sandoval Jr." },
|
|
38
38
|
]
|
|
39
39
|
dependencies = [
|
|
40
|
-
"medmlx-core
|
|
40
|
+
"medmlx-core>=0.2.6,<0.3",
|
|
41
41
|
"mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'",
|
|
42
42
|
"numpy>=2.0,<3",
|
|
43
43
|
"pillow>=13,<14",
|
|
@@ -48,7 +48,7 @@ dependencies = [
|
|
|
48
48
|
|
|
49
49
|
[project.urls]
|
|
50
50
|
Homepage = "https://medmlx.org"
|
|
51
|
-
Documentation = "https://github.com/MedMLX/flexray-mlx/blob/v0.2.
|
|
51
|
+
Documentation = "https://github.com/MedMLX/flexray-mlx/blob/v0.2.7/README.md"
|
|
52
52
|
Repository = "https://github.com/MedMLX/flexray-mlx"
|
|
53
53
|
Issues = "https://github.com/MedMLX/flexray-mlx/issues"
|
|
54
54
|
Weights = "https://huggingface.co/MedMLX/flexray-mlx"
|
|
@@ -64,9 +64,6 @@ dev = [
|
|
|
64
64
|
"ruff>=0.13,<1",
|
|
65
65
|
]
|
|
66
66
|
|
|
67
|
-
[tool.hatch.metadata]
|
|
68
|
-
allow-direct-references = true
|
|
69
|
-
|
|
70
67
|
[tool.hatch.build.targets.wheel]
|
|
71
68
|
packages = ["src/flexray_mlx"]
|
|
72
69
|
|
|
@@ -88,8 +85,8 @@ extend-select = ["TID251", "TID252", "ANN401"]
|
|
|
88
85
|
select = ["E", "F", "I", "UP", "B", "SIM", "RUF"]
|
|
89
86
|
|
|
90
87
|
[tool.pyright]
|
|
91
|
-
include = ["
|
|
92
|
-
extraPaths = ["src", "tests"
|
|
88
|
+
include = ["src", "tests"]
|
|
89
|
+
extraPaths = ["src", "tests"]
|
|
93
90
|
pythonVersion = "3.13"
|
|
94
91
|
typeCheckingMode = "strict"
|
|
95
92
|
enableTypeIgnoreComments = false
|
|
@@ -20,7 +20,6 @@ type BoolArray = NDArray[np.bool_]
|
|
|
20
20
|
type IntArray = NDArray[np.int64]
|
|
21
21
|
type UIntArray = NDArray[np.uint32]
|
|
22
22
|
type JsonValue = bool | int | float | str | list[JsonValue] | dict[str, JsonValue] | None
|
|
23
|
-
type JsonObject = dict[str, JsonValue]
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
class NativeRuntime(MlxRuntime, Protocol):
|
|
@@ -17,6 +17,7 @@ from collections.abc import Mapping, Sequence
|
|
|
17
17
|
from dataclasses import dataclass, replace
|
|
18
18
|
from itertools import combinations
|
|
19
19
|
from pathlib import Path
|
|
20
|
+
from tempfile import TemporaryDirectory
|
|
20
21
|
from typing import TYPE_CHECKING, SupportsFloat, SupportsIndex, SupportsInt, cast
|
|
21
22
|
|
|
22
23
|
import numpy as np
|
|
@@ -40,6 +41,8 @@ MODEL = {
|
|
|
40
41
|
"label": "FleXray",
|
|
41
42
|
"task": "segmentation",
|
|
42
43
|
"run": "flexray_mlx.medmlx:run",
|
|
44
|
+
# Measured MLX peak for a 1929x2207 chest radiograph, single model; larger inputs need more.
|
|
45
|
+
"peak_memory_gb": 1.2,
|
|
43
46
|
"summary": (
|
|
44
47
|
"Anatomy segmentation of one 2D radiograph: 61 independent sigmoid "
|
|
45
48
|
"channels, one selected mask restored to the source pixel grid."
|
|
@@ -873,28 +876,6 @@ def multilabel_probabilities(logits: FloatArray) -> FloatArray:
|
|
|
873
876
|
return probabilities
|
|
874
877
|
|
|
875
878
|
|
|
876
|
-
def ensemble_probabilities(member_logits: Sequence[FloatArray]) -> FloatArray:
|
|
877
|
-
"""Upstream ``_predict_with_tta`` with one pass: member probabilities, then their mean.
|
|
878
|
-
|
|
879
|
-
``member_logits`` holds one float32 array per member, all the same shape
|
|
880
|
-
(here ``(1, 61, 256, 256)``). Returns the float32 mean of the per-member
|
|
881
|
-
sigmoid probabilities, in the same shape.
|
|
882
|
-
|
|
883
|
-
Raises:
|
|
884
|
-
ValueError: ``member_logits`` is empty.
|
|
885
|
-
"""
|
|
886
|
-
|
|
887
|
-
if not member_logits:
|
|
888
|
-
raise ValueError("FleXray requires at least one ensemble member")
|
|
889
|
-
probabilities = multilabel_probabilities(member_logits[0])
|
|
890
|
-
if len(member_logits) == 1:
|
|
891
|
-
return probabilities
|
|
892
|
-
probability_sum = probabilities
|
|
893
|
-
for logits in member_logits[1:]:
|
|
894
|
-
probability_sum = probability_sum + multilabel_probabilities(logits)
|
|
895
|
-
return (probability_sum / np.float32(len(member_logits))).astype(np.float32)
|
|
896
|
-
|
|
897
|
-
|
|
898
879
|
# --- Source-grid mask export --------------------------------------------------------
|
|
899
880
|
|
|
900
881
|
|
|
@@ -944,13 +925,15 @@ def _load_models(bundles: Sequence[Path]) -> tuple[Forward, ...]:
|
|
|
944
925
|
for bundle in bundles:
|
|
945
926
|
try:
|
|
946
927
|
model = FleXrayMlxModel(bundle)
|
|
928
|
+
# Unreadable or malformed bundle files only; a config that is not a mapping
|
|
929
|
+
# surfaces as KeyError, TypeError or AttributeError. MLX/Metal RuntimeErrors
|
|
930
|
+
# propagate unchanged instead of being reported as incompatible weights.
|
|
947
931
|
except (
|
|
948
932
|
OSError,
|
|
949
933
|
KeyError,
|
|
950
934
|
TypeError,
|
|
951
935
|
AttributeError,
|
|
952
936
|
ValueError,
|
|
953
|
-
RuntimeError,
|
|
954
937
|
SafetensorError,
|
|
955
938
|
YAMLError,
|
|
956
939
|
) as error:
|
|
@@ -1148,7 +1131,7 @@ def run(
|
|
|
1148
1131
|
for first, second in combinations(destinations, 2)
|
|
1149
1132
|
):
|
|
1150
1133
|
raise InvalidInputError("FleXray outputs must not refer to the same file")
|
|
1151
|
-
existing = [path.as_posix() for path in destinations if path.exists()]
|
|
1134
|
+
existing = [path.as_posix() for path in destinations if path.exists() or path.is_symlink()]
|
|
1152
1135
|
if existing and not overwrite:
|
|
1153
1136
|
raise InvalidInputError(
|
|
1154
1137
|
f"FleXray outputs already exist: {', '.join(existing)}; "
|
|
@@ -1246,19 +1229,15 @@ def run(
|
|
|
1246
1229
|
"probability_mode": "multilabel",
|
|
1247
1230
|
"overlay_is_source_grid": True,
|
|
1248
1231
|
}
|
|
1249
|
-
#
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
try:
|
|
1232
|
+
# Private staging keeps predictable top-level symlinks away from the writers.
|
|
1233
|
+
with TemporaryDirectory(prefix=".flexray-mlx-", dir=output) as staging:
|
|
1234
|
+
partial = {name: Path(staging) / name for name in names}
|
|
1253
1235
|
source.save(partial[DISPLAY_NAME])
|
|
1254
1236
|
mask.save(partial[MASK_NAME])
|
|
1255
1237
|
np.save(partial[PROBABILITIES_NAME], probabilities, allow_pickle=False)
|
|
1256
1238
|
partial[PREDICTION_NAME].write_text(json.dumps(record, indent=2) + "\n", encoding="utf-8")
|
|
1257
1239
|
for name, temporary in partial.items():
|
|
1258
1240
|
os.replace(temporary, output / name)
|
|
1259
|
-
finally:
|
|
1260
|
-
for temporary in partial.values():
|
|
1261
|
-
temporary.unlink(missing_ok=True)
|
|
1262
1241
|
return {
|
|
1263
1242
|
"outputs": {
|
|
1264
1243
|
"mask": mask_path.as_posix(),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|