AI-ENGINEERING
    intermediate

    Image Generation & Diffusion

    AI Engineer path · lesson 65 of 124
    The idea
    A sculptor claims the statue was always inside the marble — they just removed everything that wasn't statue. Diffusion works the same trick on static: the model learned what images look like, so at each step it chips away a little of what doesn't look like your prompt, until only the picture remains.
    How to use
    Drag the slider from pure noise to the finished image — notice structure (sky vs hill) locks in early while fine detail arrives last.
    prompt: "sun setting over a green hill"
    step 0 / 10
    pure noiseimage
    layout & structure
    early steps decide
    texture & detail
    late steps decide
    predict noise, subtract
    each step does

    Key insight

    Generation is just the training task run in reverse: the model was only ever taught to answer "what noise was added to this image?" Ask it that question repeatedly, starting from pure noise, and subtracting its answers is the painting process — coarse composition first, fine detail last.

    Generate an image by denoising

    Sequence

    Order one text-to-image generation.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    6. 6Drop a step here
    6 pieces left to place

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

    What single task is a diffusion model trained on?

    The short version

    A sculptor claims the statue was always inside the marble — they just removed everything that wasn't statue. Diffusion works the same trick on static: the model learned what images look like, so at each step it chips away a little of what doesn't look like your prompt, until only the picture remains.

    In more depth

    Image Generation & Diffusion

    Diffusion models create by destroying and rebuilding: learn to remove noise, then start from pure noise and remove it repeatedly until a picture appears.

    The loop

    Training: noise real images by random amounts; train the network to predict the added noise. That's the whole objective.
    Generation: start from Gaussian static; each step the model predicts the noise and a sampler subtracts a portion. Structure locks in early, detail arrives last.
    Conditioning: a text encoder (CLIP/T5) embeds the prompt; every denoising step cross-attends to it — the prompt steers all 30 steps, not just the start.

    The three-model architecture ("Stable Diffusion is three models in a trench coat")

    1.Text encoder — prompt → embedding.
    2.Denoiser (U-Net classically; diffusion transformers/DiT in newer models) — runs 20-50×.
    3.VAE — compresses pixels ~48× so the loop runs in cheap latent space; decodes once at the end.

    Engineering dials

    CFG (classifier-free guidance): amplifies "what the prompt adds" over the unconditional prediction. ~5-9 is the faithful-but-natural zone; too high fries colors and contrast. Negative prompts ride the same mechanism in reverse.
    Steps × resolution = unit economics: samplers converge ~20-35 steps; distilled (Turbo/LCM/Lightning) models jump many steps at once for 1-8-step previews.
    Production: safety filters on prompts AND outputs (plus provenance watermarks like C2PA), prompt-enhancement UX, control beyond text (reference images, ControlNet-style conditioning, LoRA styles, inpainting), two-tier preview/final serving. The same recipe over space-time latents powers modern video generation.

    Interview Questions

    Stability AI
    Google
    OpenAI
    Midjourney
    Stability AI
    Adobe
    Canva
    Stability AI
    Replicate
    Adobe
    Google
    Midjourney
    Adobe
    Midjourney
    Adobe
    Replicate

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required