Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
license: mit
|
| 2 |
+
tags:
|
| 3 |
+
- pytorch
|
| 4 |
+
- diffusers
|
| 5 |
+
- unconditional-image-generation
|
| 6 |
+
- diffusion-models-class
|
| 7 |
+
- medical-imaging
|
| 8 |
+
- brain-mri
|
| 9 |
+
- multiple-sclerosis
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Brain MRI Synthesis with Latent Diffusion (from scratch)
|
| 13 |
+
|
| 14 |
+
This model is a diffusion-based model for unconditional image generation of **latent representations of brain MRI FLAIR slices**. The model is designed to synthesize high-resolution brain MRI images (256x256 pixels) through a Latent Diffusion process, leveraging a U-Net architecture with ResNet and Attention-based blocks.
|
| 15 |
+
|
| 16 |
+
## Training Details
|
| 17 |
+
|
| 18 |
+
- **Architecture:** Latent Diffusion Model (LDM)
|
| 19 |
+
- **Resolution:** Latent resolution of 32x32 to generate 256x256 final images
|
| 20 |
+
- **Dataset:** Lesion2D VH split (FLAIR MRI slices) (70% of the dataset)
|
| 21 |
+
- **Channels:** 4 (latents are multi-channel representations of the original images)
|
| 22 |
+
- **Epochs:** 50
|
| 23 |
+
- **Batch size:** 16
|
| 24 |
+
- **Optimizer:** AdamW with:
|
| 25 |
+
- Learning Rate: `1.0e-4`
|
| 26 |
+
- Betas: (0.95, 0.999)
|
| 27 |
+
- Weight Decay: `1.0e-6`
|
| 28 |
+
- Epsilon: `1.0e-8`
|
| 29 |
+
- **Scheduler:** Cosine with 500 warm-up steps
|
| 30 |
+
- **Gradient Accumulation:** 1 step
|
| 31 |
+
- **Mixed Precision:** No
|
| 32 |
+
- **Gradient Clipping:** Max norm of 1.0
|
| 33 |
+
- **Noise Scheduler:** Linear schedule with:
|
| 34 |
+
- `num_train_timesteps`: 1000
|
| 35 |
+
- `beta_start`: 0.0001
|
| 36 |
+
- `beta_end`: 0.02
|
| 37 |
+
- **Hardware:** Trained on **NVIDIA GPUs** with a distributed dataloader using 12 workers.
|
| 38 |
+
- **Memory Consumption:** Approx. **11 GB** during training.
|
| 39 |
+
|
| 40 |
+
## U-Net Architecture
|
| 41 |
+
- **Down Blocks:** [DownBlock2D, DownBlock2D, DownBlock2D, DownBlock2D, AttnDownBlock2D, DownBlock2D]
|
| 42 |
+
- **Up Blocks:** [UpBlock2D, AttnUpBlock2D, UpBlock2D, UpBlock2D, UpBlock2D, UpBlock2D]
|
| 43 |
+
- **Layers per Block:** 2
|
| 44 |
+
- **Block Channels:** [128, 128, 256, 256, 512, 512]
|
| 45 |
+
|
| 46 |
+
The model is designed to learn a compressed representation of the brain MRI images at a latent level, making the synthesis process more memory-efficient while maintaining high fidelity.
|
| 47 |
+
|
| 48 |
+
## Usage
|
| 49 |
+
You can use the model directly with the `diffusers` library:
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
from diffusers import LatentDiffusionPipeline
|
| 53 |
+
import torch
|
| 54 |
+
|
| 55 |
+
# Load the model
|
| 56 |
+
pipeline = LatentDiffusionPipeline.from_pretrained("benetraco/latent_scratch")
|
| 57 |
+
pipeline.to("cuda") # or "cpu"
|
| 58 |
+
|
| 59 |
+
# Generate an image
|
| 60 |
+
image = pipeline(batch_size=1).images[0]
|
| 61 |
+
|
| 62 |
+
# Display the image
|
| 63 |
+
image.show()
|