-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_training_gif.py
31 lines (24 loc) · 1.02 KB
/
create_training_gif.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import glob
import imageio
NTH_IMAGE = 10
if __name__ == '__main__':
print('Createing GIF ...')
training_img_dir = 'training_images'
num_training_images = len([name for name in os.listdir(training_img_dir)])
output_name = 'MNIST_GAN_Training_{}_epochs.gif'.format(
num_training_images)
with imageio.get_writer(output_name, mode='I') as writer:
filenames = glob.glob('{}/*.png'.format(training_img_dir))
filenames = sorted(filenames)
for i, filename in enumerate(filenames):
# Only add every nth image or last to gif
if i % NTH_IMAGE == 0 or i == len(filenames) - 1:
image = imageio.imread(filename)
writer.append_data(image)
# Add extra frames of the last image
if i == len(filenames) - 1:
num_extra_frames = 5
for _ in range(num_extra_frames):
writer.append_data(image)
print('GIF written to {}'.format(os.path.abspath(output_name)))