Compare commits

..
2 Commits
Author SHA1 Message Date
Phil Wang 1345a8a41d do not noise at the last timestep for ddim 2022-07-09 18:36:45 -07:00
Phil Wang 931a5af2c3 bring in ddim sampling 2022-07-09 16:10:23 -07:00
2 changed files with 11 additions and 7 deletions
@@ -533,11 +533,10 @@ class GaussianDiffusion(nn.Module):
return img
@torch.no_grad()
def ddim_sample(self, shape, clip_denoised = False):
def ddim_sample(self, shape, clip_denoised = True):
batch, device, total_timesteps, sampling_timesteps, eta, objective = shape[0], self.betas.device, self.num_timesteps, self.sampling_timesteps, self.ddim_sampling_eta, self.objective
times = torch.linspace(0., total_timesteps, steps = sampling_timesteps + 2)[:-1]
times = list(reversed(times.int().tolist()))
time_pairs = list(zip(times[:-1], times[1:]))
@@ -551,12 +550,17 @@ class GaussianDiffusion(nn.Module):
pred_noise, x_start, *_ = self.model_predictions(img, time_cond)
c1 = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt()
c2 = ((1 - alpha_next) - torch.square(c1)).sqrt()
if clip_denoised:
x_start.clamp_(-1., 1.)
sigma = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt()
c = ((1 - alpha_next) - sigma ** 2).sqrt()
noise = torch.randn_like(img) if time_next > 0 else 0.
img = x_start * alpha_next.sqrt() + \
c1 * torch.randn_like(img) + \
c2 * pred_noise
c * pred_noise + \
sigma * noise
img = unnormalize_to_zero_to_one(img)
return img
+1 -1
View File
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup(
name = 'denoising-diffusion-pytorch',
packages = find_packages(),
version = '0.25.0',
version = '0.25.2',
license='MIT',
description = 'Denoising Diffusion Probabilistic Models - Pytorch',
author = 'Phil Wang',