DDPMModel<T>
Models & Types · AiDotNet.Diffusion
DDPM (Denoising Diffusion Probabilistic Models) implementation.
Inheritance: DiffusionModelBase<T> → DDPMModel<T>
For Beginners
DDPM is like learning to restore a damaged photograph.
Training process:
- Take a clear photo
- Add a specific amount of noise (determined by timestep)
- Train a neural network to predict what noise was added
- Repeat with different photos and noise levels
Generation process:
- Start with pure random noise
- Ask the trained model “what noise is in this?”
- Remove the predicted noise to get a slightly clearer image
- Repeat 1000 times (or use DDIM for faster generation)
- End up with a new, never-before-seen image
This implementation provides a minimal but functional DDPM that serves as:
- A reference implementation for understanding diffusion
- A base for more sophisticated diffusion models
- A demonstration of scheduler integration
How It Works
DDPM is the foundational diffusion model architecture that introduced the modern approach to diffusion-based generation. It learns to reverse a gradual noising process to generate data from pure noise.
Reference: “Denoising Diffusion Probabilistic Models” by Ho et al., 2020
Example
var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
// Create a DDPM model for image generation
var options = new DiffusionModelOptions<float>
{
};
// Generate an image from random noise
var noise = Tensor<float>.CreateRandom(new[] { 1, 3, 64, 64 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
.ConfigureModel(new DDPMModel<float>(architecture))
.Build(trainX, trainY);
var generated = result.Predict(noise);
Constructors
| Constructor | Summary |
|---|---|
DDPMModel(INoiseScheduler<T> scheduler, Func<Tensor<T>, int, Tensor<T>> customPredictor) |
Initializes a new instance of the DDPM model with a scheduler only. |
DDPMModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> unet, Func<Tensor<T>, int, Tensor<T>> customPredictor, int channels, int imageSize, int? seed) |
Initializes a new instance of the DDPM model. |
DDPMModel(int seed) |
Initializes a new instance of the DDPM model with a seed for reproducibility. |
Methods
| Method | Summary |
|---|---|
DDPMModel<T> Create(SchedulerConfig<T> config, Func<Tensor<T>, int, Tensor<T>> customPredictor) |
Creates a DDPM model with a custom noise predictor function (for testing). |
DDPMModel<T> Create(SchedulerConfig<T> config, UNetNoisePredictor<T> unet) |
Creates a DDPM model with a custom noise predictor function (for testing). |
Tensor<T> PredictNoise(Tensor<T> noisySample, int timestep) |