Learn Diffusion
0%

Lesson 2 • 3 min

Reverse Process

Removing noise to reveal images

Forensic photo restoration

Crime scene investigators enhance blurry photos to reveal details. They use knowledge of how cameras work to reverse the blur. Diffusion models do the same: they learn how noise was added, then reverse it.

The model's job: given a noisy image and a text prompt, predict what the slightly cleaner version should look like. Repeat this 8-50 times, and you go from pure noise to a clean image.

Step through the denoising process one step at a time

Reverse process in code
def generate_image(prompt, num_steps=8):
    # Start with pure random noise
    image = random_noise(shape=(1024, 1024))

    # Text guides the denoising
    text_embedding = encode(prompt)

    # Denoise step by step
    for step in range(num_steps):
        # Model predicts the noise to remove
        predicted_noise = model(image, text_embedding, step)
        # Subtract predicted noise
        image = image - predicted_noise * step_size

    return image

Quick Win

You understand the reverse process: the model predicts and removes noise iteratively, guided by the text prompt.