From 8e020677ad5f4c45a7e8dd89e952cad50a13fb49 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 15 Jun 2022 12:17:17 +0200 Subject: [PATCH 1/2] Update README.md --- README.md | 58 ------------------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/README.md b/README.md index 35986bb620..d8ff34e7ee 100644 --- a/README.md +++ b/README.md @@ -255,61 +255,3 @@ from scipy.io.wavfile import write as wavwrite sampling_rate = 22050 wavwrite("generated_audio.wav", sampling_rate, audio.squeeze().cpu().numpy()) ``` - -## Library structure: - -``` -├── LICENSE -├── Makefile -├── README.md -├── pyproject.toml -├── setup.cfg -├── setup.py -├── src -│ ├── diffusers -│ ├── __init__.py -│ ├── configuration_utils.py -│ ├── dependency_versions_check.py -│ ├── dependency_versions_table.py -│ ├── dynamic_modules_utils.py -│ ├── modeling_utils.py -│ ├── models -│ │ ├── __init__.py -│ │ ├── unet.py -│ │ ├── unet_glide.py -│ │ └── unet_ldm.py -│ ├── pipeline_utils.py -│ ├── pipelines -│ │ ├── __init__.py -│ │ ├── configuration_ldmbert.py -│ │ ├── conversion_glide.py -│ │ ├── modeling_vae.py -│ │ ├── pipeline_bddm.py -│ │ ├── pipeline_ddim.py -│ │ ├── pipeline_ddpm.py -│ │ ├── pipeline_glide.py -│ │ └── pipeline_latent_diffusion.py -│ ├── schedulers -│ │ ├── __init__.py -│ │ ├── classifier_free_guidance.py -│ │ ├── scheduling_ddim.py -│ │ ├── scheduling_ddpm.py -│ │ ├── scheduling_plms.py -│ │ └── scheduling_utils.py -│ ├── testing_utils.py -│ └── utils -│ ├── __init__.py -│ └── logging.py -├── tests -│ ├── __init__.py -│ ├── test_modeling_utils.py -│ └── test_scheduler.py -└── utils - ├── check_config_docstrings.py - ├── check_copies.py - ├── check_dummies.py - ├── check_inits.py - ├── check_repo.py - ├── check_table.py - └── check_tf_ops.py -``` From f8cd3a20e47be25e96929ed2929f2e402fc2d074 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 15 Jun 2022 12:25:48 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d8ff34e7ee..f97838df89 100644 --- a/README.md +++ b/README.md @@ -58,12 +58,14 @@ git clone https://github.com/huggingface/diffusers.git cd diffusers && pip install -e . ``` -### 1. `diffusers` as a central modular diffusion and sampler library +### 1. `diffusers` as a toolbox for schedulers and models. `diffusers` is more modularized than `transformers`. The idea is that researchers and engineers can use only parts of the library easily for the own use cases. It could become a central place for all kinds of models, schedulers, training utils and processors that one can mix and match for one's own use case. Both models and schedulers should be load- and saveable from the Hub. +For more examples see [schedulers](https://github.com/huggingface/diffusers/tree/main/src/diffusers/schedulers) and [models](https://github.com/huggingface/diffusers/tree/main/src/diffusers/models) + #### **Example for [DDPM](https://arxiv.org/abs/2006.11239):** ```python @@ -171,25 +173,35 @@ image_pil = PIL.Image.fromarray(image_processed[0]) image_pil.save("test.png") ``` -### 2. `diffusers` as a collection of most important Diffusion systems (GLIDE, Dalle, ...) -`models` directory in repository hosts the complete code necessary for running a diffusion system as well as to train it. A `DiffusionPipeline` class allows to easily run the diffusion model in inference: +### 2. `diffusers` as a collection of popula Diffusion systems (GLIDE, Dalle, ...) -#### **Example image generation with DDPM** +For more examples see [pipelines](https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines). + +#### **Example image generation with PNDM** ```python -from diffusers import DiffusionPipeline +from diffusers import PNDM, UNetModel, PNDMScheduler import PIL.Image import numpy as np +import torch + +model_id = "fusing/ddim-celeba-hq" + +model = UNetModel.from_pretrained(model_id) +scheduler = PNDMScheduler() # load model and scheduler -ddpm = DiffusionPipeline.from_pretrained("fusing/ddpm-lsun-bedroom") +ddpm = PNDM(unet=model, noise_scheduler=scheduler) # run pipeline in inference (sample random noise and denoise) -image = ddpm() +with torch.no_grad(): + 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 + 1.0) / 2 +image_processed = torch.clamp(image_processed, 0.0, 1.0) +image_processed = image_processed * 255 image_processed = image_processed.numpy().astype(np.uint8) image_pil = PIL.Image.fromarray(image_processed[0])