Instructions to use MedMLX/lesiondiffusion-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use MedMLX/lesiondiffusion-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download MedMLX/lesiondiffusion-mlx --local-dir lesiondiffusion-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Simplify model card with concise usage and MedMLX branding
Browse files- README.md +25 -37
- banner.png +0 -0
- banner.svg +1 -0
README.md
CHANGED
|
@@ -15,30 +15,38 @@ license_link: https://github.com/HengruiTianSJTU/LesionDiffusion
|
|
| 15 |
pipeline_tag: image-to-image
|
| 16 |
---
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
```bash
|
| 29 |
uv venv --python 3.13
|
| 30 |
source .venv/bin/activate
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
uv tool install huggingface-hub
|
|
|
|
| 33 |
hf auth login
|
| 34 |
-
hf download MedMLX/lesiondiffusion-mlx --local-dir
|
| 35 |
```
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
## Public API
|
| 40 |
-
|
| 41 |
-
Provide a CT NIfTI and an aligned binary organ mask (0 background, 1 organ). For a liver example:
|
| 42 |
|
| 43 |
```python
|
| 44 |
from lesiondiffusion_mlx.medmlx import run
|
|
@@ -46,7 +54,7 @@ from lesiondiffusion_mlx.medmlx import run
|
|
| 46 |
result = run(
|
| 47 |
image_path="ct_1mm_ras.nii.gz",
|
| 48 |
organ_mask_path="liver_mask.nii.gz",
|
| 49 |
-
weights_path="
|
| 50 |
output_dir="out",
|
| 51 |
organ="liver",
|
| 52 |
lesion_type="tumor",
|
|
@@ -59,30 +67,10 @@ result = run(
|
|
| 59 |
print(result["outputs"]["synthetic_image"])
|
| 60 |
```
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
The [v0.2.1 input/output contract](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.1/README.md#input-and-output) defines supported geometry, organ labels, placement and optional phenotype controls. Axis-aligned inputs are standardized to an even-dimensioned RAS 1 mm grid; oblique or sheared transforms are refused. Inputs must support the documented 152 × 152 × 64 and 128³ crops. The CT and mask must resolve to the same standardized grid.
|
| 65 |
-
|
| 66 |
-
A successful run returns output paths under `result["outputs"]`: `synthetic_image`, `target_mask` and `organ_mask`. The files are `synthetic_ct.nii.gz`, `lesion_mask.nii.gz` and `organ_mask.nii.gz` on the standardized grid. Existing outputs require explicit `overwrite=True` to replace them. In the default full reconstruction, voxels outside the lesion can also change, and CT intensities are clipped to [-1000, 1000] HU. See the package contract for `output_region="box"`. Synthetic output is not ground truth.
|
| 67 |
-
|
| 68 |
-
## Qualification scope
|
| 69 |
-
|
| 70 |
-
The v0.2.1 release acceptance on October 24, 2026 used the installed wheel with public `medmlx-core==0.2.3`, MLX 0.32.4 and no PyTorch in the inference environment. A complete default conditioned 200-step, seed-23 public-API run finished in 372.0 seconds on one fixed AMOS22 `amos_0008` CT/liver crop (label 6; 160 × 160 × 128, RAS, 1 mm). The generated CT was finite, output masks had the required label types, and output geometry and coded forms matched the prepared input. This is an execution and output-contract check, not an assessment of appearance, lesion fidelity or clinical effectiveness.
|
| 71 |
-
|
| 72 |
-
All 139 current owner tests passed with zero skips, including the independent pinned-source numerical/contract tests. Their reduced-width and source-mode scope is described in the [technical notes](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.1/docs/technical.md). The full conditioned run above is not a paired full-checkpoint source comparison.
|
| 73 |
-
|
| 74 |
-
Before this card update, every tensor in this Hub bundle was compared on CPU against the fresh canonical conversion used for that release acceptance: all 1,141 tensor keys, shapes, dtypes and values across five stages matched exactly, as did the tokenizer bytes. Both `source` and `conditioned` asset admission passed through the installed v0.2.1 public package. The Hub serialization was not given a separate full inference rerun; its tensor-equivalence check does not extend the model qualification.
|
| 75 |
-
|
| 76 |
-
## Source and conversion
|
| 77 |
-
|
| 78 |
-
Original publisher: HengruiTianSJTU. Source: [LesionDiffusion](https://github.com/HengruiTianSJTU/LesionDiffusion), pinned revision `880736e2b8a4d9becdb6594da7f8af6db19d04d1`.
|
| 79 |
-
|
| 80 |
-
The bundle was converted from the released `LMNet.ckpt`, `LINet.ckpt` and `VQ.ckpt` components, with an explicitly supplied BiomedCLIP tokenizer. Conversion uses EMA weights and changes tensor layout/storage without retraining. `conversion.json` records the source revision, layout and precision profile. To repeat conversion from assets obtained from the original publisher, use the [v0.2.1 conversion recipe](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.1/README.md#quick-start) and its optional `conversion` extra. Do not use this card as a grant to obtain or redistribute upstream assets.
|
| 81 |
-
|
| 82 |
-
## Distribution terms and notices
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
|
|
|
| 15 |
pipeline_tag: image-to-image
|
| 16 |
---
|
| 17 |
|
| 18 |
+
<img src="https://huggingface.co/MedMLX/lesiondiffusion-mlx/resolve/main/banner.png" alt="MedMLX — Generate. CT / LESION SYNTHESIS" width="100%">
|
| 19 |
|
| 20 |
+
# LesionDiffusion
|
| 21 |
|
| 22 |
+
Synthesize lesions in CT with native MLX using the released LMNet, LINet and VQ components.
|
| 23 |
|
| 24 |
+
[GitHub](https://github.com/MedMLX/lesiondiffusion-mlx) · [Files](https://huggingface.co/MedMLX/lesiondiffusion-mlx/tree/main) · [Docs](https://github.com/MedMLX/lesiondiffusion-mlx/blob/main/README.md#quick-start)
|
| 25 |
|
| 26 |
+
| Input | Output |
|
| 27 |
+
| :--- | :--- |
|
| 28 |
+
| CT + aligned binary organ mask | Synthetic CT and lesion mask |
|
| 29 |
+
|
| 30 |
+
**Apple Silicon · Metal · Python 3.13 / 3.14**
|
| 31 |
+
|
| 32 |
+
Private weights. Your Hugging Face account needs access.
|
| 33 |
+
|
| 34 |
+
## Quick start
|
| 35 |
|
| 36 |
```bash
|
| 37 |
uv venv --python 3.13
|
| 38 |
source .venv/bin/activate
|
| 39 |
+
|
| 40 |
+
repo="https://github.com/MedMLX/lesiondiffusion-mlx"
|
| 41 |
+
release="$repo/releases/download/v0.2.1"
|
| 42 |
+
uv pip install "$release/lesiondiffusion_mlx-0.2.1-py3-none-any.whl"
|
| 43 |
uv tool install huggingface-hub
|
| 44 |
+
|
| 45 |
hf auth login
|
| 46 |
+
hf download MedMLX/lesiondiffusion-mlx --local-dir models
|
| 47 |
```
|
| 48 |
|
| 49 |
+
Replace the example input paths with your own files.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
```python
|
| 52 |
from lesiondiffusion_mlx.medmlx import run
|
|
|
|
| 54 |
result = run(
|
| 55 |
image_path="ct_1mm_ras.nii.gz",
|
| 56 |
organ_mask_path="liver_mask.nii.gz",
|
| 57 |
+
weights_path="models",
|
| 58 |
output_dir="out",
|
| 59 |
organ="liver",
|
| 60 |
lesion_type="tumor",
|
|
|
|
| 67 |
print(result["outputs"]["synthetic_image"])
|
| 68 |
```
|
| 69 |
|
| 70 |
+
Use an aligned CT and binary organ mask on a RAS 1 mm grid. Synthetic output is not ground truth.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
## Use & license
|
| 73 |
|
| 74 |
+
For research and education. Not validated for clinical use.
|
| 75 |
|
| 76 |
+
Upstream checkpoint and component terms apply; redistribution is not cleared. [Notices](https://huggingface.co/MedMLX/lesiondiffusion-mlx/blob/main/NOTICE).
|
banner.png
ADDED
|
banner.svg
ADDED
|
|