save samples and models to ./results path

This commit is contained in:
Phil Wang
2020-10-09 21:39:46 -07:00
parent ff451f697e
commit 5ad56dda25
2 changed files with 7 additions and 4 deletions
@@ -28,6 +28,9 @@ SAVE_AND_SAMPLE_EVERY = 1000
UPDATE_EMA_EVERY = 10
EXTS = ['jpg', 'jpeg', 'png']
RESULTS_FOLDER = Path('./results')
RESULTS_FOLDER.mkdir(exist_ok = True)
# helpers functions
def exists(x):
@@ -497,10 +500,10 @@ class Trainer(object):
'model': self.model.state_dict(),
'ema': self.ema_model.state_dict()
}
torch.save(data, f'./model-{milestone}.pt')
torch.save(data, str(RESULTS_FOLDER / f'model-{milestone}.pt'))
def load(self, milestone):
data = torch.load(f'./model-{milestone}.pt')
data = torch.load(str(RESULTS_FOLDER / 'model-{milestone}.pt'))
self.step = data['step']
self.model.load_state_dict(data['model'])
@@ -527,7 +530,7 @@ class Trainer(object):
batches = num_to_groups(36, self.batch_size)
all_images_list = list(map(lambda n: self.ema_model.sample(self.image_size, batch_size=n), batches))
all_images = torch.cat(all_images_list, dim=0)
utils.save_image(all_images, f'./sample-{milestone}.png', nrow=6)
utils.save_image(all_images, str(RESULTS_FOLDER / '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.5.0',
version = '0.5.1',
license='MIT',
description = 'Denoising Diffusion Probabilistic Models - Pytorch',
author = 'Phil Wang',