sd with federated learning
#1
by MasudRanaHridoy - opened
README.md
CHANGED
|
@@ -15,59 +15,64 @@ pipeline_tag: image-to-image
|
|
| 15 |
|
| 16 |
# Conditional Latent Diffusion Model for Retinal Future-State Synthesis
|
| 17 |
|
| 18 |
-
Trained weights for predicting two-year follow-up retinal fundus images from
|
| 19 |
-
|
| 20 |
-
## Files
|
| 21 |
-
|
| 22 |
-
| File | Size | Description |
|
| 23 |
-
|------|------|-------------|
|
| 24 |
-
| `diffusion_v3_zerosnr_vpred_epoch500.pt` | ~6.9 GB | Conditional denoising U-Net (860M params, 15-channel input) plus the clinical encoder. Trained for 500 epochs (seed 42) under a zero-terminal-SNR schedule with the velocity-prediction objective. Contains both raw and EMA weights; the reported numbers use the raw (non-EMA) weights. Optimizer state is stripped. |
|
| 25 |
-
| `vae_finetuned.pt` | ~335 MB | SD 1.5 VAE fine-tuned on retinal fundus images (reconstruction SSIM 0.954). Stored under `model_state_dict`. |
|
| 26 |
|
| 27 |
## Model Description
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
## Performance
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|-----------|:----:|:---------:|:-----:|:---:|
|
| 39 |
-
| Single sample (w = 1) | 0.791 | 21.60 | 0.123 | 33.2 |
|
| 40 |
-
| Posterior mean (K = 12) | 0.809 | 21.39 | 0.175 | 103.3 |
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
```python
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
num_steps=50,
|
| 64 |
-
prediction_type="v_prediction",
|
| 65 |
-
zero_snr=True,
|
| 66 |
-
)[0]
|
| 67 |
```
|
| 68 |
|
| 69 |
-
The checkpoint exposes `unet_state_dict`, `clinical_encoder_state_dict`, `ema_unet_state_dict`, `ema_clinical_state_dict`, and `config`; the VAE exposes `model_state_dict`.
|
| 70 |
-
|
| 71 |
## Links
|
| 72 |
|
| 73 |
- **Code:** [github.com/Usama1002/retinal-diffusion](https://github.com/Usama1002/retinal-diffusion)
|
|
@@ -79,7 +84,7 @@ The checkpoint exposes `unet_state_dict`, `clinical_encoder_state_dict`, `ema_un
|
|
| 79 |
@article{usama2026retinal,
|
| 80 |
title={Conditional Latent Diffusion for Predictive Retinal Fundus Image Synthesis from Baseline Imaging and Clinical Metadata},
|
| 81 |
author={Usama, Muhammad and Pazo, Emmanuel Eric and Li, Xiaorong and Liu, Juping},
|
| 82 |
-
|
| 83 |
year={2026}
|
| 84 |
}
|
| 85 |
```
|
|
|
|
| 15 |
|
| 16 |
# Conditional Latent Diffusion Model for Retinal Future-State Synthesis
|
| 17 |
|
| 18 |
+
Trained model weights for predicting two-year follow-up retinal fundus images from baseline photographs and clinical metadata.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
## Model Description
|
| 21 |
|
| 22 |
+
This model adapts Stable Diffusion 1.5 for longitudinal retinal image prediction. It consists of two components:
|
| 23 |
|
| 24 |
+
1. **Fine-tuned VAE** (`vae_best.pt`, 320 MB): SD 1.5 VAE encoder/decoder fine-tuned on retinal fundus images with L1 + SSIM + LPIPS + KL loss. Achieves SSIM 0.954 on reconstruction.
|
| 25 |
+
|
| 26 |
+
2. **Conditional U-Net** (`diffusion_best.pt`, 13 GB): 860M-parameter denoising U-Net with 15-channel input (4 noisy latent + 4 baseline latent + 7 clinical feature maps). Trained for 500 epochs with cosine LR schedule, EMA, and classifier-free guidance dropout.
|
| 27 |
|
| 28 |
## Performance
|
| 29 |
|
| 30 |
+
| Metric | Value |
|
| 31 |
+
|--------|-------|
|
| 32 |
+
| SSIM | 0.762 |
|
| 33 |
+
| PSNR | 17.26 dB |
|
| 34 |
+
| LPIPS | 0.379 |
|
| 35 |
+
| FID | 107.28 |
|
| 36 |
|
| 37 |
+
Evaluated on 110 held-out test image pairs.
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
## Qualitative Results
|
| 40 |
|
| 41 |
+

|
| 42 |
+
|
| 43 |
+
Each row shows a different test patient. Columns: baseline fundus, ground-truth follow-up, our prediction, Regression U-Net, and Pix2Pix. Our diffusion model generates sharper, more realistic retinal textures compared to deterministic baselines.
|
| 44 |
+
|
| 45 |
+
## Training Dynamics
|
| 46 |
+
|
| 47 |
+

|
| 48 |
|
| 49 |
+
(a, b) Stage 1: VAE fine-tuning over 50 epochs reaching SSIM 0.954. (c-f) Stage 2: U-Net training over 500 epochs with cosine LR schedule and warmup.
|
| 50 |
+
|
| 51 |
+
## Guidance Scale Sweep
|
| 52 |
+
|
| 53 |
+

|
| 54 |
+
|
| 55 |
+
SSIM peaks at guidance scale 7.5, while FID increases monotonically with stronger guidance, reflecting the fidelity-diversity tradeoff.
|
| 56 |
+
|
| 57 |
+
## Usage
|
| 58 |
|
| 59 |
```python
|
| 60 |
+
import torch
|
| 61 |
+
from diffusers import AutoencoderKL, UNet2DConditionModel
|
| 62 |
+
|
| 63 |
+
# Load VAE
|
| 64 |
+
vae = AutoencoderKL.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="vae")
|
| 65 |
+
vae_state = torch.load("vae_best.pt", map_location="cpu")
|
| 66 |
+
if "model_state_dict" in vae_state:
|
| 67 |
+
vae_state = vae_state["model_state_dict"]
|
| 68 |
+
vae.load_state_dict(vae_state, strict=False)
|
| 69 |
+
|
| 70 |
+
# Load U-Net (requires modified conv_in for 15 input channels)
|
| 71 |
+
unet = UNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="unet")
|
| 72 |
+
# ... modify conv_in and load checkpoint
|
| 73 |
+
# See full inference code at the GitHub repository
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
```
|
| 75 |
|
|
|
|
|
|
|
| 76 |
## Links
|
| 77 |
|
| 78 |
- **Code:** [github.com/Usama1002/retinal-diffusion](https://github.com/Usama1002/retinal-diffusion)
|
|
|
|
| 84 |
@article{usama2026retinal,
|
| 85 |
title={Conditional Latent Diffusion for Predictive Retinal Fundus Image Synthesis from Baseline Imaging and Clinical Metadata},
|
| 86 |
author={Usama, Muhammad and Pazo, Emmanuel Eric and Li, Xiaorong and Liu, Juping},
|
| 87 |
+
journal={Computers in Biology and Medicine (under review)},
|
| 88 |
year={2026}
|
| 89 |
}
|
| 90 |
```
|
diffusion_best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:954df800e580074b38d1bae261eb3c5600899c0257d9c47f66e8f2ba01721ece
|
| 3 |
+
size 13753967793
|
vae_finetuned.pt → fig_guidance_scale.png
RENAMED
|
File without changes
|
diffusion_v3_zerosnr_vpred_epoch500.pt → fig_qualitative_comparison.png
RENAMED
|
File without changes
|
fig_training_dynamics.png
ADDED
|
Git LFS Details
|
vae_best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:238a627bae7ca14a7db7053b5dca1d9ce07e9af6ac9160b0a329bc120aabdc19
|
| 3 |
+
size 334695957
|