Skip to content

Commit

Permalink
allow for turning off horizontal flip augmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed Jun 10, 2022
1 parent 479f60c commit 79c5f04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions denoising_diffusion_pytorch/denoising_diffusion_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,15 @@ def forward(self, img, *args, **kwargs):
# dataset classes

class Dataset(data.Dataset):
def __init__(self, folder, image_size, exts = ['jpg', 'jpeg', 'png']):
def __init__(self, folder, image_size, exts = ['jpg', 'jpeg', 'png'], augment_horizontal_flip = False):
super().__init__()
self.folder = folder
self.image_size = image_size
self.paths = [p for ext in exts for p in Path(f'{folder}').glob(f'**/*.{ext}')]

self.transform = transforms.Compose([
transforms.Resize(image_size),
transforms.RandomHorizontalFlip(),
transforms.RandomHorizontalFlip() if augment_horizontal_flip else nn.Identity(),
transforms.CenterCrop(image_size),
transforms.ToTensor()
])
Expand Down Expand Up @@ -580,7 +580,8 @@ def __init__(
step_start_ema = 2000,
update_ema_every = 10,
save_and_sample_every = 1000,
results_folder = './results'
results_folder = './results',
augment_horizontal_flip = True
):
super().__init__()
self.model = diffusion_model
Expand All @@ -596,7 +597,7 @@ def __init__(
self.gradient_accumulate_every = gradient_accumulate_every
self.train_num_steps = train_num_steps

self.ds = Dataset(folder, image_size)
self.ds = Dataset(folder, image_size, augment_horizontal_flip = augment_horizontal_flip)
self.dl = cycle(data.DataLoader(self.ds, batch_size = train_batch_size, shuffle=True, pin_memory=True))
self.opt = Adam(diffusion_model.parameters(), lr=train_lr)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name = 'denoising-diffusion-pytorch',
packages = find_packages(),
version = '0.18.0',
version = '0.18.1',
license='MIT',
description = 'Denoising Diffusion Probabilistic Models - Pytorch',
author = 'Phil Wang',
Expand Down

0 comments on commit 79c5f04

Please sign in to comment.