From 9ec8d27217e11e575a779a444df5c8ff9ae49b5c Mon Sep 17 00:00:00 2001 From: Phil Wang Date: Wed, 31 Aug 2022 07:36:19 -0700 Subject: [PATCH] 0.27.7 --- .../denoising_diffusion_pytorch.py | 29 ++++++++++--------- setup.py | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py b/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py index b3854c0..cfae2e6 100644 --- a/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py +++ b/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py @@ -570,7 +570,7 @@ class GaussianDiffusion(nn.Module): times = torch.linspace(-1, total_timesteps - 1, steps=sampling_timesteps + 1) # [-1, 0, 1, 2, ..., T-1] when sampling_timesteps == total_timesteps times = list(reversed(times.int().tolist())) - time_pairs = list(zip(times[:-1], times[1:])) # [(T-1, T-2), (T-2, T-3), ..., (1, 0), (0, -1)] + time_pairs = list(zip(times[:-1], times[1:])) # [(T-1, T-2), (T-2, T-3), ..., (1, 0), (0, -1)] img = torch.randn(shape, device = device) @@ -584,20 +584,21 @@ class GaussianDiffusion(nn.Module): if clip_denoised: x_start.clamp_(-1., 1.) - if time_next > -1: - alpha = self.alphas_cumprod[time] - alpha_next = self.alphas_cumprod[time_next] - - sigma = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt() - c = (1 - alpha_next - sigma ** 2).sqrt() - - noise = torch.randn_like(img) - - img = x_start * alpha_next.sqrt() + \ - c * pred_noise + \ - sigma * noise - else: + if time_next < 0: img = x_start + continue + + alpha = self.alphas_cumprod[time] + alpha_next = self.alphas_cumprod[time_next] + + sigma = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt() + c = (1 - alpha_next - sigma ** 2).sqrt() + + noise = torch.randn_like(img) + + img = x_start * alpha_next.sqrt() + \ + c * pred_noise + \ + sigma * noise img = unnormalize_to_zero_to_one(img) return img diff --git a/setup.py b/setup.py index 414f322..ba5b1e8 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup( name = 'denoising-diffusion-pytorch', packages = find_packages(), - version = '0.27.6', + version = '0.27.7', license='MIT', description = 'Denoising Diffusion Probabilistic Models - Pytorch', author = 'Phil Wang',