Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save samples in config.sample_dir #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ def make_frame(t):
clip.write_gif(fname, fps = len(images) / duration)

def visualize(sess, dcgan, config, option):
sample_dir = config.sample_dir
image_frame_dim = int(math.ceil(config.batch_size**.5))
if option == 0:
z_sample = np.random.uniform(-0.5, 0.5, size=(config.batch_size, dcgan.z_dim))
samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample})
save_images(samples, [image_frame_dim, image_frame_dim], './samples/test_%s.png' % strftime("%Y-%m-%d-%H-%M-%S", gmtime()))
save_images(samples, [image_frame_dim, image_frame_dim], '%s/test_%s.png' % (sample_dir, strftime("%Y-%m-%d-%H-%M-%S", gmtime())))
elif option == 1:
values = np.arange(0, 1, 1./config.batch_size)
for idx in xrange(dcgan.z_dim):
Expand All @@ -192,7 +193,7 @@ def visualize(sess, dcgan, config, option):
else:
samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample})

save_images(samples, [image_frame_dim, image_frame_dim], './samples/test_arange_%s.png' % (idx))
save_images(samples, [image_frame_dim, image_frame_dim], '%s/test_arange_%s.png' % (sample_dir, idx))
elif option == 2:
values = np.arange(0, 1, 1./config.batch_size)
for idx in [random.randint(0, dcgan.z_dim - 1) for _ in xrange(dcgan.z_dim)]:
Expand All @@ -213,9 +214,9 @@ def visualize(sess, dcgan, config, option):
samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample})

try:
make_gif(samples, './samples/test_gif_%s.gif' % (idx))
make_gif(samples, '%s/test_gif_%s.gif' % (sample_dir, idx))
except:
save_images(samples, [image_frame_dim, image_frame_dim], './samples/test_%s.png' % strftime("%Y-%m-%d-%H-%M-%S", gmtime()))
save_images(samples, [image_frame_dim, image_frame_dim], '%s/test_%s.png' % (sample_dir, strftime("%Y-%m-%d-%H-%M-%S", gmtime())))
elif option == 3:
values = np.arange(0, 1, 1./config.batch_size)
for idx in xrange(dcgan.z_dim):
Expand All @@ -225,7 +226,7 @@ def visualize(sess, dcgan, config, option):
z[idx] = values[kdx]

samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample})
make_gif(samples, './samples/test_gif_%s.gif' % (idx))
make_gif(samples, '%s/test_gif_%s.gif' % (sample_dir, idx))
elif option == 4:
image_set = []
values = np.arange(0, 1, 1./config.batch_size)
Expand All @@ -236,11 +237,11 @@ def visualize(sess, dcgan, config, option):
for kdx, z in enumerate(z_sample): z[idx] = values[kdx]

image_set.append(sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample}))
make_gif(image_set[-1], './samples/test_gif_%s.gif' % (idx))
make_gif(image_set[-1], '%s/test_gif_%s.gif' % (sample_dir, idx))

new_image_set = [merge(np.array([images[idx] for images in image_set]), [10, 10]) \
for idx in range(64) + range(63, -1, -1)]
make_gif(new_image_set, './samples/test_gif_merged.gif', duration=8)
make_gif(new_image_set, '%s/test_gif_merged.gif' % sample_dir , duration=8)


def image_manifold_size(num_images):
Expand Down