danesed commited on
Commit
c4384ad
·
verified ·
1 Parent(s): 82d2607

Add model card

Browse files
Files changed (1) hide show
  1. README.md +187 -0
README.md ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: pytorch
4
+ pipeline_tag: unconditional-image-generation
5
+ tags:
6
+ - medical-imaging
7
+ - mri
8
+ - brain
9
+ - neuroimaging
10
+ - 3d
11
+ - flow-matching
12
+ - wavelets
13
+ - generative
14
+ - rectified-flow
15
+ arxiv: 2601.05212
16
+ ---
17
+
18
+ # FlowLet: Conditional 3D Brain MRI Synthesis using Wavelet Flow Matching
19
+
20
+ FlowLet is a conditional generative framework that synthesizes age-conditioned 3D brain MRI
21
+ volumes. It performs flow matching directly in an invertible 3D Haar wavelet domain, which gives
22
+ multi-scale generation without any learned latent compression and avoids the reconstruction
23
+ artifacts that latent diffusion models can introduce. Sampling is a deterministic Euler ODE, so
24
+ high-fidelity volumes are produced in few steps. Age is injected through two complementary
25
+ mechanisms (FiLM in the residual blocks for global modulation, and spatial cross-attention in the
26
+ transformer blocks for spatially adaptive control). A motivating application is Brain Age
27
+ Prediction (BAP): training BAP models with FlowLet-generated data improves performance for
28
+ under-represented age groups, while region-based analysis confirms preservation of anatomical
29
+ structure.
30
+
31
+ > Status: the four checkpoints listed below are currently in training.
32
+
33
+ ![FlowLet architecture](assets/FlowLet_Architecture.png)
34
+
35
+
36
+ ## Links
37
+
38
+ - Hugging Face paper page: https://huggingface.co/papers/2601.05212
39
+ - arXiv: https://arxiv.org/abs/2601.05212
40
+ - Code (GitHub): https://github.com/sisinflab/FlowLet
41
+ - Project page: https://danesed.github.io/flowlet-page/
42
+ - Model repository (this page): https://huggingface.co/danesed/FlowLet
43
+
44
+ ## Model description
45
+
46
+ | Component | Value |
47
+ | --- | --- |
48
+ | Representation | Single-level 3D Haar DWT, producing 8 wavelet subbands (1 LLL approximation plus 7 detail), each at half spatial resolution |
49
+ | Network I/O | Conditional 3D U-Net, 8 input and 8 output channels (one per subband), 3D convolutions throughout |
50
+ | Backbone | 3D U-Net with `model_channels=128`, `num_res_blocks=2`, GroupNorm-32, and `SpatialTransformerConditional` attention blocks. Two configurations are released (see [Models](#models)). |
51
+ | Conditioning | Age (a single scalar), via FiLM in the residual blocks plus cross-attention in the transformer blocks. Condition embedding dimension 512. |
52
+ | Age normalization | Min-max to the [0, 1] interval using `condition_ranges.json`, then clamped to [0, 1] so values outside the training range do not extrapolate. |
53
+ | Objective | Rectified Flow Matching (straight-line interpolation between noise and data, constant target velocity). |
54
+ | Sampling | Euler ODE integration, deterministic given the seed. High quality in few steps (100 steps for the highest-fidelity results). |
55
+ | Output | NIfTI (`.nii.gz`), intensities rescaled to [0, 1], identity affine. |
56
+
57
+ The codebase also implements other flow formulations (`cfm`, `vp_diffusion`, `trigonometric`), but
58
+ only the Rectified Flow Matching checkpoints are released here.
59
+
60
+ ## Models
61
+
62
+ Four checkpoints: two spatial resolutions, each in two U-Net configurations. All four
63
+ use Rectified Flow Matching (`rfm`) and age conditioning. The "base" and "large" configurations
64
+ differ in the U-Net channel multipliers and attention resolutions, and therefore in parameter
65
+ count.
66
+
67
+ | Model | Resolution (saved volume) | Config | U-Net params | Planned file | Status |
68
+ | --- | --- | --- | --- | --- | --- |
69
+ | FlowLet-RFM-91-base | 91 x 109 x 91 | base (channel_mult 1,2,3,4 / attn 16,8) | 356.4 M | `rfm-91-base/flowlet_rfm_91_base.pth` | In training, coming soon |
70
+ | FlowLet-RFM-91-large | 91 x 109 x 91 | large (channel_mult 1,2,4,8 / attn 4,8) | 1.00 B | `rfm-91-large/flowlet_rfm_91_large.pth` | In training, coming soon |
71
+ | FlowLet-RFM-182-base | 182 x 218 x 182 | base (channel_mult 1,2,3,4 / attn 16,8) | 356.4 M | `rfm-182-base/flowlet_rfm_182_base.pth` | In training, coming soon |
72
+ | FlowLet-RFM-182-large | 182 x 218 x 182 | large (channel_mult 1,2,4,8 / attn 4,8) | 1.00 B | `rfm-182-large/flowlet_rfm_182_large.pth` | In training, coming soon |
73
+
74
+ Each variant folder will also contain its `config.json` (the architecture the generation script
75
+ rebuilds the model from) and its `condition_ranges.json` (the age range used for normalization).
76
+ The 91 resolution uses a padded model input of 112 x 112 x 112, and the 182 resolution uses
77
+ 224 x 224 x 224.
78
+
79
+
80
+
81
+ ## How to use (ready for when the weights are released)
82
+
83
+ FlowLet uses a custom 3D architecture, so it is loaded with the repository code plus the released
84
+ `.pth`, not with `transformers` or `PyTorchModelHubMixin`. Once a checkpoint is available, download
85
+ it with its sidecar JSON files, then run the repository generation script.
86
+
87
+ ```bash
88
+ # Code and environment
89
+ git clone https://github.com/sisinflab/FlowLet && cd FlowLet
90
+ conda create -n flowlet_env python=3.11 && conda activate flowlet_env
91
+ pip install -r requirements.txt # torch==2.6.0, xformers optional
92
+ ```
93
+
94
+ ```python
95
+ # Download one variant (weights, config, age ranges). Available once Status shows released.
96
+ from huggingface_hub import hf_hub_download
97
+
98
+ repo_id = "danesed/FlowLet"
99
+ variant = "rfm-91-base" # rfm-91-base | rfm-91-large | rfm-182-base | rfm-182-large
100
+ fname = "flowlet_rfm_91_base.pth"
101
+
102
+ ckpt = hf_hub_download(repo_id, f"{variant}/{fname}", revision="main")
103
+ config = hf_hub_download(repo_id, f"{variant}/config.json", revision="main")
104
+ ranges = hf_hub_download(repo_id, f"{variant}/condition_ranges.json", revision="main")
105
+ print(ckpt, config, ranges)
106
+ ```
107
+
108
+ ```bash
109
+ # Generate. The script rebuilds the model from config.json and normalizes age with
110
+ # condition_ranges.json. Arguments are a flat argparse (no subcommands), so flag order is free.
111
+ PYTHONPATH=. python3 -u scripts/generate.py \
112
+ --checkpoint_path "$CKPT" \
113
+ --config_path "$CONFIG" \
114
+ --condition_ranges_path "$RANGES" \
115
+ --output_dir ./generated/rfm-91-base \
116
+ --generation_conditions "Age=45" "Age=70.5" \
117
+ --num_synthetic 5 \
118
+ --num_flow_steps 100 \
119
+ --save_size 91 109 91
120
+ ```
121
+
122
+ For the 182 resolution variants pass `--save_size 182 218 182` (the padded input size is read from
123
+ the variant's `config.json`).
124
+
125
+ Notes:
126
+ - Attention uses `xformers` when available and falls back to native PyTorch attention automatically
127
+ if it is not installed (a warning is logged). To force the fallback, set `"use_xformers": false`
128
+ in the variant `config.json` before generating.
129
+ - Loading: the released `.pth` files are slimmed (weights under `model_state_dict` plus a small
130
+ config block). The generation script calls `torch.load(..., map_location=device)` without setting
131
+ `weights_only`. On torch 2.6 (pinned here) the default is `weights_only=True`, and the slimmed
132
+ files contain only tensors and JSON-serializable config, so they load under that default.
133
+
134
+ ## Training data
135
+
136
+ FlowLet was trained on preprocessed T1-weighted brain MRI from public research cohorts:
137
+
138
+ - OpenBHB: https://baobablab.github.io/bhb/dataset
139
+ - ADNI: https://adni.loni.usc.edu/
140
+ - OASIS-3: https://sites.wustl.edu/oasisbrains/
141
+
142
+ No imaging data is redistributed in this repository. Because of patient-privacy regulations and
143
+ data-use agreements, the scans cannot be shared here. Access must be requested from the original
144
+ providers under their respective agreements. Preprocessing (per the paper and the code repository):
145
+ N4ITK bias-field correction (ANTs), affine registration to MNI152 (FSL FLIRT), skull stripping
146
+ (FSL BET), resampling to 91 x 109 x 91, and z-score intensity normalization. The conditioning
147
+ variable is the subject Age, and the released `condition_ranges.json` covers Age in [5.90, 95.46].
148
+
149
+ ## Intended use and limitations
150
+
151
+ Intended use: research on generative modeling of brain MRI, data augmentation for downstream
152
+ research (for example Brain Age Prediction), and benchmarking of flow-matching formulations.
153
+
154
+ Limitations and out-of-scope use:
155
+ - Not a medical device. No diagnostic, screening, or clinical use.
156
+ - Synthetic volumes may contain anatomical artifacts and do not correspond to real individuals.
157
+ - Outputs reflect the cohort bias of the training data (acquisition sites, scanners, demographics).
158
+ - Age is clamped to the training range [5.90, 95.46]. Values outside it are silently clipped, so
159
+ out-of-range ages do not produce reliable extrapolation.
160
+ - Generation is conditioned on age only. Other clinical or morphological factors are not controlled.
161
+
162
+ ## Citation
163
+
164
+ ```bibtex
165
+ @misc{danese2026flowletconditional3dbrain,
166
+ title={FlowLet: Conditional 3D Brain MRI Synthesis using Wavelet Flow Matching},
167
+ author={Danilo Danese and Angela Lombardi and Matteo Attimonelli and Giuseppe Fasano and Tommaso Di Noia},
168
+ year={2026},
169
+ eprint={2601.05212},
170
+ archivePrefix={arXiv},
171
+ primaryClass={cs.CV},
172
+ url={https://arxiv.org/abs/2601.05212},
173
+ }
174
+
175
+ @article{danese2026flowlet,
176
+ title = {FlowLet: Conditional 3D Brain MRI Synthesis using Wavelet Flow Matching},
177
+ author = {Danese, Danilo and Lombardi, Angela and Attimonelli, Matteo and Fasano, Giuseppe and Di Noia, Tommaso},
178
+ journal = {Medical Image Analysis},
179
+ year = {2026},
180
+ publisher = {Elsevier},
181
+ DOI = {TO_BE_ASSIGNED}
182
+ }
183
+ ```
184
+
185
+ ## License
186
+
187
+ Released under the MIT License. See https://github.com/sisinflab/FlowLet/blob/main/LICENSE