From 20c2ab026916fcdc808dbb89d56199883dfea632 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 6 Jun 2022 18:17:15 +0200 Subject: [PATCH 1/2] Update README.md --- README.md | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c03553078c..62f608fee1 100644 --- a/README.md +++ b/README.md @@ -80,28 +80,18 @@ image_pil.save("test.png") Example: ```python -from diffusers import UNetModel, GaussianDDPMScheduler from modeling_ddpm import DDPM -import tempfile -unet = UNetModel.from_pretrained("fusing/ddpm_dummy") -sampler = GaussianDDPMScheduler.from_config("fusing/ddpm_dummy") - -# compose Diffusion Pipeline -ddpm = DDPM(unet, sampler) -# generate / sample +ddpm = DDPM.from_pretrained("fusing/ddpm-lsun-bedroom-pipe") image = ddpm() -print(image) - -# save and load with 0 extra code (handled by general `DiffusionPipeline` class) -# will also be possible to do so from the Hub -with tempfile.TemporaryDirectory() as tmpdirname: - ddpm.save_pretrained(tmpdirname) - print("Model saved") - ddpm_new = DDPM.from_pretrained(tmpdirname) - print("Model loaded") - print(ddpm_new) +import PIL.Image +import numpy as np +image_processed = image.cpu().permute(0, 2, 3, 1) +image_processed = (image_processed + 1.0) * 127.5 +image_processed = image_processed.numpy().astype(np.uint8) +image_pil = PIL.Image.fromarray(image_processed[0]) +image_pil.save("test.png") ``` ## Library structure: From 7ec721c5f7309229be7c1067786cacd9bad9ea8f Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 6 Jun 2022 18:19:02 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 62f608fee1..b24623887a 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,13 @@ for t in reversed(range(len(scheduler))): sampled_prev_image = prev_image + prev_variance image = sampled_prev_image +# process image to PIL image_processed = image.cpu().permute(0, 2, 3, 1) image_processed = (image_processed + 1.0) * 127.5 image_processed = image_processed.numpy().astype(np.uint8) image_pil = PIL.Image.fromarray(image_processed[0]) + +# save image image_pil.save("test.png") ``` @@ -81,16 +84,22 @@ Example: ```python from modeling_ddpm import DDPM - -ddpm = DDPM.from_pretrained("fusing/ddpm-lsun-bedroom-pipe") -image = ddpm() - import PIL.Image import numpy as np + +# load model and scheduler +ddpm = DDPM.from_pretrained("fusing/ddpm-lsun-bedroom-pipe") + +# run pipeline in inference (sample random noise and denoise) +image = ddpm() + +# process image to PIL image_processed = image.cpu().permute(0, 2, 3, 1) image_processed = (image_processed + 1.0) * 127.5 image_processed = image_processed.numpy().astype(np.uint8) image_pil = PIL.Image.fromarray(image_processed[0]) + +# save image image_pil.save("test.png") ```