Skip to content

Commit

Permalink
Merge pull request #74 from deklesen/main
Browse files Browse the repository at this point in the history
Add zero-fills to progress output filenames, add sentence to README on how to convert to video
  • Loading branch information
lucidrains authored Mar 19, 2021
2 parents 24098fa + 66f547b commit ad2becd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ $ lightweight_gan \
--num-image-tiles {count of image result}
```

After run this command you will get folder near results image folder with postfix "-progress".
After running this command you will get a new folder in the results folder, with postfix "-progress". You can convert the images to a video with ffmpeg using the command "ffmpeg -framerate 10 -pattern_type glob -i '*-ema.jpg' out.mp4".

![Show progress gif demonstration](./docs/show_progress/show-progress.gif)

Expand Down
6 changes: 4 additions & 2 deletions lightweight_gan/lightweight_gan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,8 @@ def show_progress(self, num_images=4, types=['default', 'ema']):
ext = self.image_extension
latents = None

zfill_length = math.ceil(math.log10(len(checkpoints)))

if not dir_full.exists():
os.mkdir(dir_full)

Expand All @@ -1222,13 +1224,13 @@ def show_progress(self, num_images=4, types=['default', 'ema']):
# regular
if 'default' in types:
generated_image = self.generate_(self.GAN.G, latents)
path = str(self.results_dir / dir_name / f'{str(checkpoint)}.{ext}')
path = str(self.results_dir / dir_name / f'{str(checkpoint).zfill(zfill_length)}.{ext}')
torchvision.utils.save_image(generated_image, path, nrow=num_images)

# moving averages
if 'ema' in types:
generated_image = self.generate_(self.GAN.GE, latents)
path = str(self.results_dir / dir_name / f'{str(checkpoint)}-ema.{ext}')
path = str(self.results_dir / dir_name / f'{str(checkpoint).zfill(zfill_length)}-ema.{ext}')
torchvision.utils.save_image(generated_image, path, nrow=num_images)

@torch.no_grad()
Expand Down

0 comments on commit ad2becd

Please sign in to comment.