d3v-26 commited on
Commit
b93e0b2
·
verified ·
1 Parent(s): 9813e6f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +257 -3
README.md CHANGED
@@ -1,3 +1,257 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: uk-biobank-mta
4
+ license_link: https://www.ukbiobank.ac.uk/media/p3el3p0f/mta-v20-final-29mar2021-clean.pdf
5
+ tags:
6
+ - medical
7
+ - mri
8
+ - brain-segmentation
9
+ - self-supervised-learning
10
+ - swin-transformer
11
+ - monai
12
+ - uk-biobank
13
+ - brats
14
+ - atlas
15
+ pipeline_tag: image-segmentation
16
+ ---
17
+
18
+ # BrainSegFounder: UK Biobank Brain MRI Foundation Models
19
+
20
+ ## Overview
21
+
22
+ This repository contains pretrained model weights derived from UK Biobank MRI data and downstream medical imaging datasets. These weights correspond to the self-supervised pretraining and supervised finetuning stages described in the **BrainSegFounder** framework.
23
+
24
+ **Paper:** [BrainSegFounder: Self-supervised Learning for Brain MRI Segmentation](https://doi.org/10.1016/j.media.2024.103301)
25
+
26
+ **Please cite this paper if you use these model weights.**
27
+
28
+ ### Available Model Weights
29
+
30
+ This repository includes:
31
+
32
+ | Model File | Description | Training Data | Subjects |
33
+ |------------|-------------|---------------|----------|
34
+ | `model_weights_UKB-pretrain.pt` | SSL pretraining weights | UK Biobank MRI (fields 20252-20253) | ~41,000 |
35
+ | `model_weights_BRATS-pretrain.pt` | SSL pretraining weights | UKB + BraTS (multimodal MRI) | 42,470 |
36
+ | `model_weights_BRATS-finetune.pt` | SwinUNETR finetuning weights | BraTS tumor segmentation | 1,470 |
37
+ | `model_weights_ATLAS-pretrain.pt` | SSL pretraining weights | UKB + ATLAS v2.0 (multimodal MRI) | 42,271 |
38
+ | `model_weights_ATLAS-finetune.pt` | SwinUNETR finetuning weights | ATLAS stroke lesion segmentation | 1,271 |
39
+ | `SSL_Head.py` | Source code | SSL head implementation for pretraining | - |
40
+
41
+ This README provides instructions for loading the weights, architecture descriptions, dataset information, and required UK Biobank privacy/policy statements.
42
+
43
+
44
+ ## Quick Start
45
+
46
+ ### Installation
47
+
48
+ All models use MONAI components and require:
49
+
50
+ ```bash
51
+ pip install git+https://github.com/Project-MONAI/MONAI.git@a23c7f54
52
+ pip install torch
53
+ ```
54
+
55
+ ### Usage Examples
56
+
57
+ #### Loading UKB-only Pretraining Weights
58
+
59
+ ```python
60
+ import torch
61
+ from huggingface_hub import hf_hub_download
62
+ from SSL_Head import SSLHead # Download SSL_Head.py from this repo
63
+ from argparse import Namespace
64
+
65
+ # Download model weights
66
+ model_path = hf_hub_download(
67
+ repo_id="smilelab/BrainSegFounder",
68
+ filename="model_weights_UKB-pretrain.pt"
69
+ )
70
+
71
+ # Configure model
72
+ args = Namespace(
73
+ in_channels=2, # T1 + T2
74
+ spatial_dims=3,
75
+ bottleneck_depth=768,
76
+ feature_size=48,
77
+ num_swin_blocks_per_stage=[2,2,2,2],
78
+ num_heads_per_stage=[3,6,12,24],
79
+ dropout_path_rate=0.0,
80
+ use_checkpoint=False
81
+ )
82
+
83
+ # Load model
84
+ model = SSLHead(args)
85
+ state_dict = torch.load(model_path, map_location="cpu")
86
+ model.load_state_dict(state_dict)
87
+ model.eval()
88
+ ```
89
+
90
+ #### Loading Multimodal Pretraining Weights (UKB + BraTS/ATLAS)
91
+
92
+ ```python
93
+ import torch
94
+ from huggingface_hub import hf_hub_download
95
+ from SSL_Head import SSLHead
96
+ from argparse import Namespace
97
+
98
+ # Download BRATS or ATLAS pretrain weights
99
+ model_path = hf_hub_download(
100
+ repo_id="smilelab/BrainSegFounder",
101
+ filename="model_weights_BRATS-pretrain.pt" # or model_weights_ATLAS-pretrain.pt
102
+ )
103
+
104
+ args = Namespace(
105
+ in_channels=2,
106
+ spatial_dims=3,
107
+ bottleneck_depth=768,
108
+ feature_size=48,
109
+ num_swin_blocks_per_stage=[2,2,2,2],
110
+ num_heads_per_stage=[3,6,12,24],
111
+ dropout_path_rate=0.0,
112
+ use_checkpoint=False
113
+ )
114
+
115
+ model = SSLHead(args)
116
+ state_dict = torch.load(model_path, map_location="cpu")
117
+ model.load_state_dict(state_dict)
118
+ model.eval()
119
+ ```
120
+
121
+ #### Loading Finetuned Segmentation Weights (SwinUNETR)
122
+
123
+ ```python
124
+ import torch
125
+ from huggingface_hub import hf_hub_download
126
+ from monai.networks.nets import SwinUNETR
127
+
128
+ # Download BRATS or ATLAS finetune weights
129
+ model_path = hf_hub_download(
130
+ repo_id="smilelab/BrainSegFounder",
131
+ filename="model_weights_BRATS-finetune.pt" # or model_weights_ATLAS-finetune.pt
132
+ )
133
+
134
+ # Configure SwinUNETR
135
+ depths = [2, 2, 2, 2]
136
+ num_heads = [3, 6, 12, 24]
137
+
138
+ model = SwinUNETR(
139
+ img_size=(96, 96, 96),
140
+ in_channels=4,
141
+ out_channels=3,
142
+ feature_size=48,
143
+ use_checkpoint=False,
144
+ depths=depths,
145
+ num_heads=num_heads
146
+ )
147
+
148
+ state_dict = torch.load(model_path, map_location="cpu")
149
+ model.load_state_dict(state_dict)
150
+ model.eval()
151
+ ```
152
+
153
+ ## Architecture Description
154
+
155
+ This project uses two architectures:
156
+
157
+ 1. **SSLHead** - Self-supervised pretraining model built on a 3D Swin Transformer encoder
158
+ 2. **SwinUNETR** - Supervised segmentation model for downstream tasks
159
+
160
+ ### SSLHead (Pretraining Model)
161
+
162
+ The SSL pretraining model is a 3D SwinViT encoder equipped with self-supervised learning heads for **rotation prediction** and **contrastive representation learning**, as well as a VAE-style trilinear decoder for volume reconstruction.
163
+
164
+ **Key components:**
165
+
166
+ - **Backbone**: 3D Swin Transformer (`SwinViT` from MONAI)
167
+ - Patch size: `[2,2,2]`
168
+ - Window size: `[7,7,7]`
169
+ - Embedding dimension: 48
170
+ - Depths: `[2,2,2,2]`
171
+ - Number of heads: `[3,6,12,24]`
172
+ - **Bottleneck dimension**: 768
173
+ - **Self-supervised heads**:
174
+ - Rotation prediction: `nn.Linear(768, 4)`
175
+ - Contrastive learning: `nn.Linear(768, 512)`
176
+ - **Reconstruction decoder**: 5-stage upsampling with 3D convolutions + InstanceNorm + LeakyReLU (trilinear interpolation)
177
+
178
+ The SSLHead combines three self-supervised learning objectives in equal proportion:
179
+ - **Reconstruction loss**: VAE-style image reconstruction
180
+ - **Rotation prediction**: 4-way rotation classification
181
+ - **Contrastive loss**: Feature representation learning
182
+
183
+ See [SSL_Head.py](SSL_Head.py) for the complete implementation.
184
+
185
+ ### SwinUNETR (Finetuning Model)
186
+
187
+ The finetuning model uses MONAI's 3D **SwinUNETR**, which integrates a Swin Transformer encoder with a U-Net-style hierarchical decoder for dense segmentation tasks.
188
+
189
+ **Key components:**
190
+ - Patch-based 3D Swin Transformer encoder
191
+ - U-Net-style symmetric decoder with skip connections
192
+ - Depths: `[2,2,2,2]`
193
+ - Number of heads: `[3,6,12,24]`
194
+ - Input image size: `(96, 96, 96)`
195
+ - Output channels: 3 (task-dependent segmentation classes)
196
+
197
+ Both architectures are implemented using **MONAI** (commit `a23c7f54`).
198
+
199
+ ## Training Data
200
+
201
+ ### UK Biobank (Pretraining)
202
+
203
+ - **Subjects**: ~41,000
204
+ - **Data fields**: 20252 (T1-weighted MRI), 20253 (T2-weighted MRI)
205
+ - **Preprocessing**: Standard MONAI transforms (resizing and normalization)
206
+ - **Used in**: `model_weights_UKB-pretrain.pt`
207
+
208
+ ### BraTS (Pretraining and Finetuning)
209
+
210
+ - **Subjects**: 1,470
211
+ - **Task**: Brain tumor segmentation
212
+ - **Modalities**: Multi-modal 3D MRI
213
+ - **Preprocessing**: Standard normalization and cropping
214
+ - **Used in**: `model_weights_BRATS-pretrain.pt`, `model_weights_BRATS-finetune.pt`
215
+
216
+ ### ATLAS v2.0 (Pretraining and Finetuning)
217
+
218
+ - **Subjects**: 1,271
219
+ - **Task**: Stroke lesion segmentation
220
+ - **Preprocessing**: Standard MONAI transforms
221
+ - **Used in**: `model_weights_ATLAS-pretrain.pt`, `model_weights_ATLAS-finetune.pt`
222
+
223
+ ## Citation
224
+
225
+ If you use these model weights, please cite:
226
+
227
+ ```bibtex
228
+ @article{brainsegfounder2024,
229
+ title={BrainSegFounder: Self-supervised Learning for Brain MRI Segmentation},
230
+ journal={Medical Image Analysis},
231
+ year={2024},
232
+ doi={10.1016/j.media.2024.103301},
233
+ url={https://doi.org/10.1016/j.media.2024.103301}
234
+ }
235
+ ```
236
+
237
+ ## Privacy and Data Protection Statement
238
+
239
+ The returned model parameters do **not** contain any UK Biobank participant-level data, do not embed identifiable features, and cannot be used to reconstruct or infer individual-level MRI volumes.
240
+
241
+ The models store only aggregated statistical representations learned across tens of thousands of participants. They do not contain per-participant embeddings, IDs, or reconstructed images.
242
+
243
+ This submission complies with the UK Biobank requirement that *any parameters derived from UKB data be returned as derived variables*, while ensuring that no participant-level data or re-identifiable elements are included.
244
+
245
+ ## License and Allowed Use
246
+
247
+ These derived variables (model weights) may be accessed by future approved UK Biobank researchers under UK Biobank's standard access procedures.
248
+
249
+ The model architectures and research software used to train these models remain the intellectual property of the submitting researcher. The learned parameters, however, are derived from UK Biobank data and are therefore returned in accordance with:
250
+ - The UK Biobank Material Transfer Agreement (MTA)
251
+ - The UK Biobank "Use of Artificial Intelligence Applications and Models" policy
252
+
253
+ **License**: The model weights are subject to the [UK Biobank Material Transfer Agreement](https://www.ukbiobank.ac.uk/media/p3el3p0f/mta-v20-final-29mar2021-clean.pdf).
254
+
255
+ ## Contact
256
+
257
+ For questions about these models or collaborations, please open an issue in this repository or contact the authors through the paper.