Update README.md

This commit is contained in:
Patrick von Platen 2022-06-06 18:17:15 +02:00 committed by GitHub
parent 80b865878c
commit 20c2ab0269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 18 deletions

View File

@ -80,28 +80,18 @@ image_pil.save("test.png")
Example: Example:
```python ```python
from diffusers import UNetModel, GaussianDDPMScheduler
from modeling_ddpm import DDPM from modeling_ddpm import DDPM
import tempfile
unet = UNetModel.from_pretrained("fusing/ddpm_dummy") ddpm = DDPM.from_pretrained("fusing/ddpm-lsun-bedroom-pipe")
sampler = GaussianDDPMScheduler.from_config("fusing/ddpm_dummy")
# compose Diffusion Pipeline
ddpm = DDPM(unet, sampler)
# generate / sample
image = ddpm() image = ddpm()
print(image)
import PIL.Image
# save and load with 0 extra code (handled by general `DiffusionPipeline` class) import numpy as np
# will also be possible to do so from the Hub image_processed = image.cpu().permute(0, 2, 3, 1)
with tempfile.TemporaryDirectory() as tmpdirname: image_processed = (image_processed + 1.0) * 127.5
ddpm.save_pretrained(tmpdirname) image_processed = image_processed.numpy().astype(np.uint8)
print("Model saved") image_pil = PIL.Image.fromarray(image_processed[0])
ddpm_new = DDPM.from_pretrained(tmpdirname) image_pil.save("test.png")
print("Model loaded")
print(ddpm_new)
``` ```
## Library structure: ## Library structure: