harveymannering commited on
Commit
b518a95
1 Parent(s): af53208

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -0
README.md ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ See the following code:
2
+
3
+ ## Model Use
4
+
5
+ ```python
6
+ # !pip install diffusers
7
+ from diffusers import DDPMPipeline, DDIMPipeline, PNDMPipeline
8
+ import torch
9
+ import matplotlib.pyplot as plt
10
+
11
+
12
+ # load model and scheduler
13
+ model_id = "harveymannering/xfetus-ddpm-v2"
14
+ ddpm = DDPMPipeline.from_pretrained(model_id) # you can replace DDPMPipeline with DDIMPipeline or PNDMPipeline for faster inference
15
+
16
+ x = torch.randn(1, 3, 128, 128).to(device) # noise
17
+ for i, t in tqdm(enumerate(ddpm.scheduler.timesteps)):
18
+ model_input = ddpm.scheduler.scale_model_input(x, t)
19
+ with torch.no_grad():
20
+ # Conditiong on the 'Fetal brain' class (with index 1) because I am most familar
21
+ # with what these images look like
22
+ class_label = torch.ones(1, dtype=torch.int64)
23
+ noise_pred = ddpm.unet(model_input, t, class_label.to(device))["sample"]
24
+ x = ddpm.scheduler.step(noise_pred, t, x).prev_sample
25
+
26
+ plt.imshow(x[0].cpu().detach().numpy())
27
+ plt.show()
28
+ ```
29
+
30
+ ## Example Outputs
31
+
32
+ <img width="608" alt="image" src="https://cdn-uploads.huggingface.co/production/uploads/6349716695ab8cce385f450e/uxDp-0svPAp2dCmTK36rf.png">
33
+
34
+ ## Training Loss
35
+
36
+ <img width="608" alt="image" src="https://cdn-uploads.huggingface.co/production/uploads/6349716695ab8cce385f450e/XEZb34rdFYaeFckDMyCYm.png">