This is often called Denoising Diffusion Probabilistic Models (DDPM). Standard Diffusion Models contain 2 different processes:
1. Forward Process (Add Noise)
- we first start with a full clear image
- next we slowly corrupt it by added small amounts of gaussian noise over steps (normally its )
- at time step , a small amount of noise is added according to a fixed variance schedule ()
- Instead of calculating how much noise to add at each step 1000 times over, we can use a direct closed form formula that allows us to calculate the final output at any time step:
(where is pure random noise, and is a predefined scaling parameter calculated from the noise schedule )
2. Reverse Process (Denoise)
Starting with pure static noise at time step , we can go back to using a U-Net.
3 Training Process
- Pick a clean real image from your dataset.
- Pick a random timestep between and .
- Sample a random noise vector .
- Use the closed-form shortcut formula to generate the noisy image .
- Feed and into the U-Net.
- The U-Net predicts the noise: .
- Calculate the loss using standard Mean Squared Error (MSE):
4 Inference Process
To generate a brand-new image from scratch after training:
- Start with pure random Gaussian static noise .
- Run a loop backward from down to :
- Pass and timestep into the trained U-Net to predict noise .
- Subtract a fraction of that predicted noise from to get a slightly cleaner image .
- Add a tiny bit of random jitter (to preserve diversity)
- At step , a brand new image appears
5 Notes
- one network handles every timestep, so a diffusion model does not need a separately trained network for each one
- the timestep is passed to the denoiser as an additional input, and it is positionally encoded
- the network is trained to predict the noise, and not the clean image directly
- a basic approach runs roughly 1000 denoising steps
- during sampling, after removing a little noise the standard DDPM update also adds back a bit of noise, which keeps diversity, and some variants skip this
- training uses the easy direction, so cats to noise, because that direction is simple to simulate while noise to cat is hard
- in the reverse process the model moves random noise gradually onto the manifold of real images
The score function behind all of this is in Tweedie's Formula.