Image Segmentation
MLX
English
native-mlx
apple-silicon
medical-imaging
mri
brain-tumor
segmentation
research
Instructions to use MedMLX/segresnet-brats-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use MedMLX/segresnet-brats-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download MedMLX/segresnet-brats-mlx --local-dir segresnet-brats-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Clean model card formatting and usage
Browse files
README.md
CHANGED
|
@@ -2,77 +2,123 @@
|
|
| 2 |
license: apache-2.0
|
| 3 |
library_name: mlx
|
| 4 |
tags:
|
| 5 |
-
-
|
|
|
|
| 6 |
- apple-silicon
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
- research
|
| 8 |
language:
|
| 9 |
- en
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
-
# MONAI brats_mri_segmentation (SegResNet, 4-channel MRI)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
Evaluated revision: `40cbce54523632fbc8cdfc564a9cce48d8df3424`.
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
##
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
```python
|
| 33 |
from segresnet_mlx.medmlx import run
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
"overwrite": True
|
| 45 |
-
}
|
| 46 |
-
result = run(**kwargs)
|
| 47 |
print(result["outputs"])
|
| 48 |
```
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
Native result: **success**. Original-code comparison: **pass**, `minimum_per_label_dice` = `1.0`.
|
| 51 |
|
| 52 |
Native whole-volume output compared with the original MONAI bundle; the October 12 renal operator repair also has a full-case BraTS regression.
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
Converted weights are hosted in this repository.
|
| 60 |
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
- https://huggingface.co/MONAI/brats_mri_segmentation/resolve/370f7f9d062745fbac445e7fe6d6616d35df04ec/models/model.pt
|
| 74 |
-
- https://huggingface.co/MONAI/brats_mri_segmentation/blob/370f7f9d062745fbac445e7fe6d6616d35df04ec/LICENSE
|
| 75 |
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
| 3 |
library_name: mlx
|
| 4 |
tags:
|
| 5 |
+
- mlx
|
| 6 |
+
- native-mlx
|
| 7 |
- apple-silicon
|
| 8 |
+
- medical-imaging
|
| 9 |
+
- mri
|
| 10 |
+
- brain-tumor
|
| 11 |
+
- segmentation
|
| 12 |
- research
|
| 13 |
language:
|
| 14 |
- en
|
| 15 |
+
inference: false
|
| 16 |
+
pipeline_tag: image-segmentation
|
| 17 |
+
base_model: MONAI/brats_mri_segmentation
|
| 18 |
---
|
|
|
|
| 19 |
|
| 20 |
+
# SegResNet Brain Tumor Segmentation
|
|
|
|
| 21 |
|
| 22 |
+
Native MLX port of [MONAI BraTS MRI segmentation](https://huggingface.co/MONAI/brats_mri_segmentation).
|
| 23 |
+
Segment brain tumor regions from four MRI sequences locally on Apple Silicon.
|
| 24 |
|
| 25 |
+
- T1, contrast-enhanced T1, T2 and FLAIR inputs
|
| 26 |
+
- Native whole-volume segmentation with MLX
|
| 27 |
+
- Converted MONAI SegResNet checkpoint included
|
| 28 |
|
| 29 |
+
MLX implementation by [MedMLX](https://github.com/MedMLX).
|
| 30 |
+
[GitHub](https://github.com/MedMLX/segresnet-mlx) · [Usage](https://github.com/MedMLX/segresnet-mlx#quick-start) · [Upstream](https://huggingface.co/MONAI/brats_mri_segmentation)
|
| 31 |
+
|
| 32 |
+
**Requires the companion `segresnet-mlx` runtime.** Follow the quick start below.
|
| 33 |
+
|
| 34 |
+
## Requirements
|
| 35 |
|
| 36 |
+
Apple Silicon Mac with Metal GPU access, Python 3.12 and [uv](https://docs.astral.sh/uv/).
|
| 37 |
+
The weights are included here; checkpoint conversion is not needed.
|
| 38 |
|
| 39 |
+
## Quick start
|
| 40 |
|
| 41 |
+
```bash
|
| 42 |
+
uv venv --python 3.12
|
| 43 |
+
source .venv/bin/activate
|
| 44 |
+
uv pip install "segresnet-mlx @ git+https://github.com/MedMLX/segresnet-mlx.git" huggingface_hub
|
| 45 |
+
|
| 46 |
+
hf download MedMLX/segresnet-brats-mlx --local-dir models
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
Authenticate with `hf auth login` if repository access is required.
|
| 50 |
+
Run this example in the same environment, replacing the input paths with your own:
|
| 51 |
|
| 52 |
```python
|
| 53 |
from segresnet_mlx.medmlx import run
|
| 54 |
|
| 55 |
+
result = run(
|
| 56 |
+
bundle='brats_mri_segmentation',
|
| 57 |
+
weights_path='models/segresnet-brats.safetensors',
|
| 58 |
+
output_dir='outputs',
|
| 59 |
+
t1c_path='T1gd.nii.gz',
|
| 60 |
+
t1_path='T1w.nii.gz',
|
| 61 |
+
t2_path='T2w.nii.gz',
|
| 62 |
+
flair_path='FLAIR.nii.gz',
|
| 63 |
+
)
|
|
|
|
|
|
|
|
|
|
| 64 |
print(result["outputs"])
|
| 65 |
```
|
| 66 |
|
| 67 |
+
## Input and output
|
| 68 |
+
|
| 69 |
+
Input is four 3D NIfTI MRI volumes on the same voxel grid: T1,
|
| 70 |
+
contrast-enhanced T1, T2 and FLAIR. The example names each modality explicitly.
|
| 71 |
+
|
| 72 |
+
Output is `brats_mri_segmentation_mask.nii.gz` on the input grid. Exported
|
| 73 |
+
labels use the bundle’s BraTS convention: 0 background, 1 tumor core,
|
| 74 |
+
2 whole tumor outside the core, 4 enhancing tumor.
|
| 75 |
+
|
| 76 |
+
## Technical details
|
| 77 |
+
|
| 78 |
Native result: **success**. Original-code comparison: **pass**, `minimum_per_label_dice` = `1.0`.
|
| 79 |
|
| 80 |
Native whole-volume output compared with the original MONAI bundle; the October 12 renal operator repair also has a full-case BraTS regression.
|
| 81 |
|
| 82 |
+
These are recorded results for one configuration, not a new benchmark or an
|
| 83 |
+
estimate of clinical accuracy. The [native run](https://huggingface.co/MedMLX/segresnet-brats-mlx/blob/main/native-run.json)
|
| 84 |
+
and [original-code comparison](https://huggingface.co/MedMLX/segresnet-brats-mlx/blob/main/reference-comparison.json)
|
| 85 |
+
retain the commands, precision, geometry and output checks.
|
| 86 |
+
|
| 87 |
+
<details>
|
| 88 |
+
<summary>Checkpoint provenance and recorded configuration</summary>
|
| 89 |
|
| 90 |
+
Recorded configuration: **MONAI brats_mri_segmentation (SegResNet, 4-channel MRI)**.
|
| 91 |
|
| 92 |
+
Evaluated package revision: `40cbce54523632fbc8cdfc564a9cce48d8df3424`.
|
|
|
|
| 93 |
|
| 94 |
+
Recorded input: MSD Task01 BrainTumour (training) / BRATS_001.
|
| 95 |
|
| 96 |
+
Original publisher: MONAI.
|
| 97 |
+
Original implementation: [upstream source](https://huggingface.co/MONAI/brats_mri_segmentation).
|
| 98 |
+
Source revision or version: `370f7f9d062745fbac445e7fe6d6616d35df04ec`.
|
| 99 |
+
Original checkpoint: [pinned checkpoint](https://huggingface.co/MONAI/brats_mri_segmentation/resolve/370f7f9d062745fbac445e7fe6d6616d35df04ec/models/model.pt).
|
| 100 |
|
| 101 |
+
Weights were converted with the companion MLX package, without retraining.
|
| 102 |
+
Conversion changes tensor layout or storage as required by that implementation.
|
| 103 |
|
| 104 |
+
The [replay harness](https://github.com/MedMLX/Med-MLX/blob/main/benchmarks/README.md)
|
| 105 |
+
describes how to reproduce the recorded configuration with local paths.
|
| 106 |
|
| 107 |
+
</details>
|
| 108 |
|
| 109 |
+
## Intended use
|
|
|
|
|
|
|
| 110 |
|
| 111 |
+
Research and education. Outputs require human review and are not intended for
|
| 112 |
+
clinical diagnosis or treatment decisions.
|
| 113 |
|
| 114 |
+
## License
|
| 115 |
+
|
| 116 |
+
Weights: **Apache-2.0** ([license](https://huggingface.co/MedMLX/segresnet-brats-mlx/blob/main/LICENSE)).
|
| 117 |
+
Upstream code: **Apache-2.0**. MLX port code:
|
| 118 |
+
[Apache-2.0](https://github.com/MedMLX/segresnet-mlx/blob/main/LICENSE).
|
| 119 |
+
|
| 120 |
+
Retain the [attribution and notices](https://huggingface.co/MedMLX/segresnet-brats-mlx/blob/main/NOTICE) when redistributing
|
| 121 |
+
the bundle or a conversion:
|
| 122 |
+
|
| 123 |
+
- Retain the applicable license, copyright and attribution notices; identify the upstream checkpoint, authors, and MLX conversion changes.
|
| 124 |
+
- Include Apache-2.0, retain applicable upstream NOTICE content, and mark modifications.
|