The forward diffusion process with a DDPM scheduler
Seeing how the scheduler adds noise gradually, as in the DDPM paper.
Goal: Loading a diffusion pipeline and generating an image.
import torch
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base", torch_dtype=torch.float16)
pipe = pipe.to("cuda")
image = pipe("a watercolor painting of a robot reading a book", num_inference_steps=25).images[0]
image.save("robot.png")
DiffusionPipeline.from_pretrained loads all the model's components (the text encoder, the U-Net, the scheduler and the decoder). It needs a GPU with enough memory and a download of several gigabytes, and some models require accepting their license on Hugging Face. Not run in the test environment.
This example was not run in the test environment: needs a GPU and a download of the model weights. Check it against the library documentation before relying on it.
Seeing how the scheduler adds noise gradually, as in the DDPM paper.
Sections
No section has this name. Press “Search” to search all site content.
Favourites
My results & certificates
My academy progressMy quiz resultsKids’ progressAcademy certificatesQuiz certificatesStart any lesson or quiz and it will show up here so you can get back to it quickly.
Settings
I am the AI Frameworks & Libraries Assistant. Describe your project or ask me about a library, a comparison or a code example, and I will answer from the encyclopedia's database with links and sources.
Answers from the encyclopedia's database only, without a language model and without sending your question to any third party.
The assistant can make mistakes, so check the attached sources.