A Denoising Diffusion Probabilistic Model (DDPM) trained on CIFAR-10 for unconditional image generation. The model generates 32x32 RGB images spanning all 10 CIFAR-10 categories without class conditioning.
Implements DDPM (Ho et al., 2020) with a U-Net denoising network featuring self-attention blocks and sinusoidal time embeddings.
1import torch
2from model import UNet
3from diffusion import GaussianDiffusionSampler
4
5device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6
7model = UNet(T=1000, ch=128, ch_mult=[1,2,2,2], attn=[1], num_res_blocks=2, dropout=0.1)
8model.load_state_dict(torch.load("Checkpoints/ckpt_199.pth", map_location=device))
9model.eval().to(device)
10
11sampler = GaussianDiffusionSampler(beta_1=1e-4, beta_t=0.02, model=model, T=1000).to(device)
12
13with torch.no_grad():
14 x_T = torch.randn(16, 3, 32, 32, device=device)
15 samples = sampler(x_T)
16
17samples = (samples.clamp(-1, 1) + 1) / 2 # rescale to [0, 1]