usama10 commited on
Commit
82a57d5
·
verified ·
1 Parent(s): e77fd93

Update model card: zero-SNR/v-pred, corrected results, w=1

Browse files
Files changed (1) hide show
  1. README.md +39 -44
README.md CHANGED
@@ -15,64 +15,59 @@ pipeline_tag: image-to-image
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
- ![Qualitative comparison](fig_qualitative_comparison.png)
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
- ![Training dynamics](fig_training_dynamics.png)
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
- ![Guidance scale](fig_guidance_scale.png)
 
 
 
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,7 +79,7 @@ unet = UNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5", su
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
  ```
 
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 a baseline photograph and a seven-variable clinical profile (age, sex, glycated hemoglobin, fasting glucose, DR severity grade, hypertension status, follow-up interval).
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
+ The U-Net takes a 15-channel latent input formed by concatenating the noisy target latent (4), the encoded baseline latent (4), and a per-feature clinical map (7). It is initialized from Stable Diffusion 1.5 and trained on eye-corrected, registered baseline/follow-up pairs. The zero-terminal-SNR schedule with velocity prediction removes a color-space artifact mode and reduces the low-quality prediction rate from 26.4% to 5.5%. Optimal inference uses DDIM with guidance w = 1 (no classifier-free guidance); larger guidance over-exposes the output.
30
 
31
+ From the single trained model two estimators span the distortion-perception frontier: a single sample (best perceptual quality) and the posterior mean over K = 12 samples (best structural similarity).
32
 
33
+ ## Performance
34
 
35
+ Held-out test set (n = 110 pairs), field-of-view-masked metrics.
36
 
37
+ | Estimator | SSIM | PSNR (dB) | LPIPS | FID |
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
+ Five-seed means: single-sample SSIM 0.781 +/- 0.006, FID 32.5 +/- 0.6. No baseline retrained on the same corrected data significantly outperforms these on any metric under paired Wilcoxon testing.
43
 
44
  ## Usage
45
 
46
+ The full sampler is in the code repository (`src/inference/diffusion_sampler.py`). It loads the two checkpoints as follows:
47
+
48
  ```python
49
+ from src.inference.diffusion_sampler import load_model, sample
50
+
51
+ unet, clin, vae = load_model(
52
+ "diffusion_v3_zerosnr_vpred_epoch500.pt",
53
+ "vae_finetuned.pt",
54
+ device="cuda",
55
+ use_ema=False, # raw weights reproduce the reported numbers
56
+ )
57
+
58
+ pred = sample(
59
+ unet, clin, vae,
60
+ baseline, # (1, 3, 512, 512) in [-1, 1]
61
+ clinical, # (1, 7) standardized clinical vector
62
+ guidance_scale=1.0,
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
  @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
+ note={Manuscript under review},
83
  year={2026}
84
  }
85
  ```