mlx-segment-ct 0.3.2__tar.gz → 0.3.4__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.

Files changed (25) hide show
  1. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/PKG-INFO +10 -5
  2. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/README.md +8 -4
  3. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/THIRD_PARTY_NOTICES.md +7 -3
  4. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/pyproject.toml +2 -1
  5. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/__init__.py +1 -1
  6. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/bundle_transforms.py +8 -6
  7. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/medmlx.py +34 -9
  8. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/.gitignore +0 -0
  9. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/LICENSE +0 -0
  10. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/_types.py +0 -0
  11. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/activations.py +0 -0
  12. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/correction.py +0 -0
  13. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/correction_inferer.py +0 -0
  14. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/instance_norm.py +0 -0
  15. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/interactive.py +0 -0
  16. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/labels.py +0 -0
  17. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/mlx_network.py +0 -0
  18. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/mlx_point.py +0 -0
  19. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/mlx_point_window.py +0 -0
  20. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/mlx_upsample.py +0 -0
  21. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/mlx_worker.py +0 -0
  22. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/projections.py +0 -0
  23. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/py.typed +0 -0
  24. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/restoration.py +0 -0
  25. {mlx_segment_ct-0.3.2 → mlx_segment_ct-0.3.4}/src/mlx_segment_ct/streaming.py +0 -0
@@ -1,8 +1,9 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mlx-segment-ct
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Native MLX implementation of NV-Segment-CT (VISTA-3D)
5
5
  Project-URL: Homepage, https://huggingface.co/MedMLX/vista3d-ct-mlx
6
+ Project-URL: Repository, https://github.com/MedMLX/mlx-segment-ct
6
7
  Author: Joseph Sandoval, Alfredo Sandoval Jr.
7
8
  License-Expression: Apache-2.0 AND BSD-3-Clause
8
9
  License-File: LICENSE
@@ -29,7 +30,7 @@ Description-Content-Type: text/markdown
29
30
 
30
31
  Segment CT anatomy automatically or with anatomy names and clicks, using NVIDIA VISTA-3D in native MLX.
31
32
 
32
- [CT weights](https://huggingface.co/MedMLX/vista3d-ct-mlx) · [CTMR weights](https://huggingface.co/MedMLX/vista3d-ctmr-mlx)
33
+ [Docs](https://github.com/MedMLX/mlx-segment-ct/blob/main/docs/technical.md) · [CT weights](https://huggingface.co/MedMLX/vista3d-ct-mlx) · [CTMR weights](https://huggingface.co/MedMLX/vista3d-ctmr-mlx) · [MedMLX](https://github.com/MedMLX)
33
34
 
34
35
  | Input | Output |
35
36
  | :--- | :--- |
@@ -37,10 +38,12 @@ Segment CT anatomy automatically or with anatomy names and clicks, using NVIDIA
37
38
 
38
39
  **Apple Silicon · Metal · Python 3.13 / 3.14** · [uv](https://docs.astral.sh/uv/)
39
40
 
40
- ## Quick start
41
+ ## Install
41
42
 
42
43
  ```bash
43
- uv pip install "mlx-segment-ct>=0.3.2"
44
+ uv venv --python 3.13
45
+ source .venv/bin/activate
46
+ uv pip install "mlx-segment-ct>=0.3.4"
44
47
  ```
45
48
 
46
49
  NIfTI files explicitly marked in meters or microns are rejected. Inputs with
@@ -49,6 +52,8 @@ unknown spatial units are assumed to use millimeters.
49
52
  The click coordinates below are examples: replace them with voxels inside your
50
53
  image and its preprocessed foreground crop. `1` includes a point; `0` excludes it.
51
54
 
55
+ ## Run
56
+
52
57
  ```python
53
58
  from mlx_segment_ct.medmlx import run
54
59
 
@@ -79,6 +84,6 @@ weights report `null` unless the folder carries a MedMLX download revision.
79
84
 
80
85
  ## License
81
86
 
82
- Apache-2.0; license and third-party notices are included in the distribution. Model weights retain their publisher terms.
87
+ [Apache-2.0](https://github.com/MedMLX/mlx-segment-ct/blob/main/LICENSE). See [third-party notices](https://github.com/MedMLX/mlx-segment-ct/blob/main/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
83
88
 
84
89
  For research and education. Outputs require human review.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Segment CT anatomy automatically or with anatomy names and clicks, using NVIDIA VISTA-3D in native MLX.
4
4
 
5
- [CT weights](https://huggingface.co/MedMLX/vista3d-ct-mlx) · [CTMR weights](https://huggingface.co/MedMLX/vista3d-ctmr-mlx)
5
+ [Docs](https://github.com/MedMLX/mlx-segment-ct/blob/main/docs/technical.md) · [CT weights](https://huggingface.co/MedMLX/vista3d-ct-mlx) · [CTMR weights](https://huggingface.co/MedMLX/vista3d-ctmr-mlx) · [MedMLX](https://github.com/MedMLX)
6
6
 
7
7
  | Input | Output |
8
8
  | :--- | :--- |
@@ -10,10 +10,12 @@ Segment CT anatomy automatically or with anatomy names and clicks, using NVIDIA
10
10
 
11
11
  **Apple Silicon · Metal · Python 3.13 / 3.14** · [uv](https://docs.astral.sh/uv/)
12
12
 
13
- ## Quick start
13
+ ## Install
14
14
 
15
15
  ```bash
16
- uv pip install "mlx-segment-ct>=0.3.2"
16
+ uv venv --python 3.13
17
+ source .venv/bin/activate
18
+ uv pip install "mlx-segment-ct>=0.3.4"
17
19
  ```
18
20
 
19
21
  NIfTI files explicitly marked in meters or microns are rejected. Inputs with
@@ -22,6 +24,8 @@ unknown spatial units are assumed to use millimeters.
22
24
  The click coordinates below are examples: replace them with voxels inside your
23
25
  image and its preprocessed foreground crop. `1` includes a point; `0` excludes it.
24
26
 
27
+ ## Run
28
+
25
29
  ```python
26
30
  from mlx_segment_ct.medmlx import run
27
31
 
@@ -52,6 +56,6 @@ weights report `null` unless the folder carries a MedMLX download revision.
52
56
 
53
57
  ## License
54
58
 
55
- Apache-2.0; license and third-party notices are included in the distribution. Model weights retain their publisher terms.
59
+ [Apache-2.0](https://github.com/MedMLX/mlx-segment-ct/blob/main/LICENSE). See [third-party notices](https://github.com/MedMLX/mlx-segment-ct/blob/main/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
56
60
 
57
61
  For research and education. Outputs require human review.
@@ -356,6 +356,10 @@ POSSIBILITY OF SUCH DAMAGE.
356
356
 
357
357
  ## Showcase image
358
358
 
359
- The CT images are from [AMOS22](https://doi.org/10.5281/zenodo.7262581),
360
- Ji, Yuanfeng et al., licensed [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
361
- The showcase uses cropped views with model-derived overlays or maps.
359
+ The CT image is from [AMOS22](https://doi.org/10.5281/zenodo.7262581),
360
+ Ji, Yuanfeng et al. (2022). The Zenodo record lists
361
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), while the
362
+ dataset's own metadata lists
363
+ [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).
364
+ The showcase uses a cropped view with model-derived overlays or maps and is
365
+ shared under CC BY-SA 4.0 pending clarification of the source terms.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "mlx-segment-ct"
7
- version = "0.3.2"
7
+ version = "0.3.4"
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"]
@@ -21,6 +21,7 @@ dependencies = [
21
21
 
22
22
  [project.urls]
23
23
  Homepage = "https://huggingface.co/MedMLX/vista3d-ct-mlx"
24
+ Repository = "https://github.com/MedMLX/mlx-segment-ct"
24
25
 
25
26
  [project.entry-points."medmlx.models"]
26
27
  mlx-segment-ct = "mlx_segment_ct.medmlx:MODEL"
@@ -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.2"
28
+ __version__ = "0.3.4"
29
29
 
30
30
  _EXPORTS = {
31
31
  "AutomaticModel": "mlx_segment_ct.mlx_network",
@@ -248,16 +248,18 @@ def preprocess(
248
248
  NV-Segment-CT's fixed range (``"range"``) or NV-Segment-CTMR's percentiles.
249
249
 
250
250
  ``image`` is float32 ``(1, X, Y, Z)`` as ``load_volume`` returns it, and ``affine``
251
- its voxel-to-world matrix (NIfTI RAS, assumed millimeters). Finite values are
252
- scaled to [0, 1] in the usual nondegenerate case (see
253
- ``scale_intensity_percentiles`` for the equal-percentile case); NaNs can
254
- survive preprocessing. The result is on the RAS-oriented 1.5 mm foreground crop.
251
+ its voxel-to-world matrix (NIfTI RAS, assumed millimeters). Voxel values must
252
+ be finite. They are scaled to [0, 1] in the usual nondegenerate case (see
253
+ ``scale_intensity_percentiles`` for the equal-percentile case). The result is
254
+ on the RAS-oriented 1.5 mm foreground crop.
255
255
 
256
256
  Raises:
257
- InvalidInputError: no voxel is above zero after resampling, or an ``extra``
258
- volume does not resample onto the image grid.
257
+ InvalidInputError: image voxels are non-finite, no voxel is above zero after
258
+ resampling, or an ``extra`` volume does not resample onto the image grid.
259
259
  ValueError: unknown ``intensity``.
260
260
  """
261
+ if not np.isfinite(image).all():
262
+ raise InvalidInputError("NV-Segment-CT image contains non-finite voxel intensities")
261
263
  resampled_image, image_affine = _spacing(image, affine, "bilinear")
262
264
  resampled = _Resampled(affine, _shape(image))
263
265
  start, end = _foreground_box(resampled_image)
@@ -125,9 +125,10 @@ def run(
125
125
  interpolates the scores trilinearly at each source voxel and decides its label
126
126
  there, so boundaries follow the source resolution. ``"bundle"`` decides on the
127
127
  1.5 mm grid and restores labels with nearest interpolation, as the NVIDIA bundle does.
128
- Input spatial units must be millimeters or unknown (assumed millimeters);
129
- other declared units require conversion before inference. Output NIfTI headers
130
- are newly constructed and do not retain the source unit code.
128
+ Input voxel intensities must be finite. Spatial units must be millimeters or
129
+ unknown (assumed millimeters); other declared units require conversion before
130
+ inference. Output NIfTI headers are newly constructed and do not retain the
131
+ source unit code.
131
132
 
132
133
  The published ``MedMLX/vista3d-ct-mlx`` bundle supplies ``automatic.safetensors``
133
134
  and ``correction.safetensors`` for ``checkpoint="NV-Segment-CT"``. The
@@ -234,7 +235,7 @@ def run(
234
235
  f"NV-Segment-CT output exists: {destination}; pass overwrite=true to replace it"
235
236
  )
236
237
  weights_root = (
237
- model_weights_dir("vista3d-ct-mlx")
238
+ model_weights_dir("mlx-segment-ct")
238
239
  if weights_path is None else Path(weights_path).expanduser()
239
240
  )
240
241
  weights_dir = _weights_dir(weights_root, correction=point_mode)
@@ -271,13 +272,37 @@ def run_ctmr(
271
272
  """Run the CTMR variant with its own automatic model folder and fixed settings.
272
273
 
273
274
  Omitted weights use ``MedMLX/vista3d-ctmr-mlx``; an explicit folder contains
274
- ``automatic.safetensors`` and, for point inference, ``correction.safetensors``.
275
- Inputs, prompts and output contracts match ``run``. NVIDIA does not support
276
- point segmentation with this checkpoint. CTMR preprocessing and
277
- label rules are fixed internally, so CT weights are never substituted.
275
+ ``automatic.safetensors``. CTMR preprocessing and label rules are fixed
276
+ internally, so CT weights are never substituted. The shared point/correction
277
+ arguments are forwarded to ``run``, but NVIDIA does not support point
278
+ segmentation with this checkpoint. Their presence is not a qualification
279
+ of CTMR point inference.
280
+
281
+ Args:
282
+ image_path: Single-channel CT or MRI NIfTI volume; declared spatial units
283
+ must be millimeters or unknown (assumed millimeters).
284
+ output_dir: Directory for the restored label map.
285
+ weights_path: Optional model folder containing ``automatic.safetensors``;
286
+ omit to reuse the automatic CTMR download.
287
+ segment_all: Request all classes for the selected modality; no prompts also
288
+ selects this mode.
289
+ prompt: Anatomy names instead of numeric class IDs.
290
+ label_prompt: Numeric foreground IDs instead of anatomy names.
291
+ previous_logits_path: Advanced shared correction input; requires point
292
+ prompts, which NVIDIA does not support for CTMR.
293
+ points: Advanced shared source-grid ``(x, y, z)`` point coordinates;
294
+ CTMR point inference is not supported by NVIDIA.
295
+ point_labels: Include/exclude codes paired with ``points``.
296
+ point_start: Index of the first new click for the shared point interface.
297
+ interactive: Require the shared point-prompt mode; see its support limit above.
298
+ overwrite: Replace an existing output; inputs remain protected from aliasing.
299
+ modality: All-classes set: ``CT_BODY``, ``MRI_BODY`` or ``MRI_BRAIN``.
300
+ None selects ``MRI_BODY``. Inapplicable to class or point prompts.
301
+ restoration: ``scores`` interpolates scores before selecting labels;
302
+ ``bundle`` restores labels with the bundle's nearest-neighbor rule.
278
303
  """
279
304
  folder = (
280
- model_weights_dir("vista3d-ctmr-mlx")
305
+ model_weights_dir("mlx-segment-ctmr")
281
306
  if weights_path is None else Path(weights_path).expanduser()
282
307
  )
283
308
  return run(
File without changes