This repository is pytorch implement of Denoising Diffusion Probabilistic Models
.
the following parameters are set manually.
the following parameters are computed from the above parameters.
$$ \bar{\alpha}t = \prod{i=1}^t{\alpha}_i $$
the optimization goal of the Decoder is to predict
$$ \mu_{target} = \frac{\sqrt{\alpha_t}\left(1 - \bar{\alpha}{t-1}\right)x_t+\sqrt{\bar{\alpha}{t-1}}\left(1-\alpha_t\right)x_0}{1-\bar{\alpha}_t} $$
$$ \mu_{prediction} = \frac{\sqrt{\alpha_t}\left(1 - \bar{\alpha}{t-1}\right)x_t+\sqrt{\bar{\alpha}{t-1}}\left(1-\alpha_t\right)\hat{x}_{\theta}\left(x_t, t\right)}{1-\bar{\alpha}_t} $$
the loss function is:
$$ \log{p(x)} = \mathbb{E_{q\left(x_1|x_0\right)}}\left[\log{p_{\theta}}(x_0|x_1)\right] - D_{KL}\left(q(x_T|x_0)||p(x_T)\right) - \sum_{t=2}^T{\mathbb{E}{q(x_t|x_0)}\left[D{KL}(q(x_{t-1}|x_t, x_0))||p_{\theta}(x_{t-1}|x_t)\right]} $$
We ignore optimizing the first term when training, because we don't add noise in the first step (let
$$ x_t = \sqrt{\bar{\alpha}t}x_0 + \sqrt{1 - \bar{\alpha}t}\epsilon{\theta};\quad \epsilon{\theta} \sim \mathcal{N}\left(\mu_{prediction},\sigma^2\left(t\right)\mathbf{I}\right) $$
$ git clone https://github.com/yl-jiang/Diffusion-Model-Demo.git
$ cd Diffusion-Model-Demo
$ conda activate your_pytorch_environment
$ python train.py
if everything is ok, then you will see something like this:
Logging at: Logs_Checkpoints/Inference/version_0
Model Checkpoint at: Logs_Checkpoints/checkpoints/version_0
Train :: Epoch: 1/30: 9%|█▏ | 42/469 [00:06<00:49, 8.61it/s, Loss: 0.0507]