-
Notifications
You must be signed in to change notification settings - Fork 31
/
test_celeba_lsgan.py
66 lines (52 loc) · 1.41 KB
/
test_celeba_lsgan.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
import glob
import utils
import traceback
import numpy as np
import tensorflow as tf
import models_64x64 as models
""" param """
epoch = 50
batch_size = 100
lr = 0.0002
z_dim = 100
gpu_id = 3
''' data '''
# you should prepare your own data in ./data/img_align_celeba
# celeba original size is [218, 178, 3]
""" graphs """
with tf.device('/gpu:%d' % gpu_id):
''' models '''
generator = models.generator
''' graph '''
# inputs
z = tf.placeholder(tf.float32, shape=[None, z_dim])
# generate
gene = generator(z, training=False, reuse=False)
""" train """
''' init '''
# session
sess = utils.session()
# saver
saver = tf.train.Saver()
''' initialization '''
ckpt_dir = './checkpoints/celeba_lsgan/Epoch_(49)_(2915of3165).ckpt'
saver.restore(sess, ckpt_dir)
sess.run(tf.global_variables_initializer())
saver.restore(sess, ckpt_dir)
try:
for it in range(2000):
z_ipt = np.random.normal(size=[batch_size, z_dim])
img = sess.run(gene, feed_dict={z: z_ipt})
save_dir = './results/celeba_lsgan'
utils.mkdir(save_dir + '/')
utils.batchimwrite(img, '%s/img%d' % (save_dir,it))
if it%1000==0:
print("Batch %d images are done!!"%(it))
except Exception, e:
traceback.print_exc()
finally:
print(" [*] Close main session!")
sess.close()