Compare commits

..
3 Commits
Author SHA1 Message Date
Phil Wang 16c9ae7bb3 fix data not being normalized to range of -1 to 1 2021-06-21 18:51:36 -07:00
Phil Wang f5916111f8 0.6.3 2021-06-21 17:41:16 -07:00
Phil Wang ad9e303ff3 fix channels 2021-06-11 15:28:36 -07:00
2 changed files with 12 additions and 5 deletions
@@ -190,6 +190,8 @@ class Unet(nn.Module):
channels = 3
):
super().__init__()
self.channels = channels
dims = [channels, *map(lambda m: dim * m, dim_mults)]
in_out = list(zip(dims[:-1], dims[1:]))
@@ -229,7 +231,7 @@ class Unet(nn.Module):
Upsample(dim_in) if not is_last else nn.Identity()
]))
out_dim = default(out_dim, 3)
out_dim = default(out_dim, channels)
self.final_conv = nn.Sequential(
Block(dim, dim),
nn.Conv2d(dim, out_dim, 1)
@@ -291,11 +293,13 @@ class GaussianDiffusion(nn.Module):
denoise_fn,
*,
image_size,
channels = 3,
timesteps = 1000,
loss_type = 'l1',
betas = None
):
super().__init__()
self.channels = channels
self.image_size = image_size
self.denoise_fn = denoise_fn
@@ -389,7 +393,8 @@ class GaussianDiffusion(nn.Module):
@torch.no_grad()
def sample(self, batch_size = 16):
image_size = self.image_size
return self.p_sample_loop((batch_size, 3, image_size, image_size))
channels = self.channels
return self.p_sample_loop((batch_size, channels, image_size, image_size))
@torch.no_grad()
def interpolate(self, x1, x2, t = None, lam = 0.5):
@@ -450,7 +455,8 @@ class Dataset(data.Dataset):
transforms.Resize(image_size),
transforms.RandomHorizontalFlip(),
transforms.CenterCrop(image_size),
transforms.ToTensor()
transforms.ToTensor(),
transforms.Lambda(lambda t: (t * 2) - 1)
])
def __len__(self):
@@ -548,7 +554,8 @@ class Trainer(object):
batches = num_to_groups(36, self.batch_size)
all_images_list = list(map(lambda n: self.ema_model.sample(batch_size=n), batches))
all_images = torch.cat(all_images_list, dim=0)
utils.save_image(all_images, str(RESULTS_FOLDER / f'sample-{milestone}.png'), nrow=6)
all_images = (all_images + 1) * 0.5
utils.save_image(all_images, str(RESULTS_FOLDER / f'sample-{milestone}.png'), nrow = 6)
self.save(milestone)
self.step += 1
+1 -1
View File
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup(
name = 'denoising-diffusion-pytorch',
packages = find_packages(),
version = '0.6.0',
version = '0.6.5',
license='MIT',
description = 'Denoising Diffusion Probabilistic Models - Pytorch',
author = 'Phil Wang',