Skip to content

Commit 6f75ef1

Browse files
Merge branch 'main' of https://github.com/huggingface/diffusers into main
2 parents 8a79ed6 + 7ec721c commit 6f75ef1

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ for t in reversed(range(len(scheduler))):
6767
sampled_prev_image = prev_image + prev_variance
6868
image = sampled_prev_image
6969

70+
# process image to PIL
7071
image_processed = image.cpu().permute(0, 2, 3, 1)
7172
image_processed = (image_processed + 1.0) * 127.5
7273
image_processed = image_processed.numpy().astype(np.uint8)
7374
image_pil = PIL.Image.fromarray(image_processed[0])
75+
76+
# save image
7477
image_pil.save("test.png")
7578
```
7679

@@ -80,28 +83,24 @@ image_pil.save("test.png")
8083
Example:
8184

8285
```python
83-
from diffusers import UNetModel, GaussianDDPMScheduler
8486
from modeling_ddpm import DDPM
85-
import tempfile
87+
import PIL.Image
88+
import numpy as np
8689

87-
unet = UNetModel.from_pretrained("fusing/ddpm_dummy")
88-
sampler = GaussianDDPMScheduler.from_config("fusing/ddpm_dummy")
90+
# load model and scheduler
91+
ddpm = DDPM.from_pretrained("fusing/ddpm-lsun-bedroom-pipe")
8992

90-
# compose Diffusion Pipeline
91-
ddpm = DDPM(unet, sampler)
92-
# generate / sample
93+
# run pipeline in inference (sample random noise and denoise)
9394
image = ddpm()
94-
print(image)
9595

96+
# process image to PIL
97+
image_processed = image.cpu().permute(0, 2, 3, 1)
98+
image_processed = (image_processed + 1.0) * 127.5
99+
image_processed = image_processed.numpy().astype(np.uint8)
100+
image_pil = PIL.Image.fromarray(image_processed[0])
96101

97-
# save and load with 0 extra code (handled by general `DiffusionPipeline` class)
98-
# will also be possible to do so from the Hub
99-
with tempfile.TemporaryDirectory() as tmpdirname:
100-
ddpm.save_pretrained(tmpdirname)
101-
print("Model saved")
102-
ddpm_new = DDPM.from_pretrained(tmpdirname)
103-
print("Model loaded")
104-
print(ddpm_new)
102+
# save image
103+
image_pil.save("test.png")
105104
```
106105

107106
## Library structure:

0 commit comments

Comments
 (0)