-
Notifications
You must be signed in to change notification settings - Fork 3
/
createPhotos.py
executable file
·78 lines (58 loc) · 1.8 KB
/
createPhotos.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
67
68
69
70
71
72
73
74
75
76
77
78
'''
Script to create a nxm matrix of photos generated by the generator
'''
import cv2
import tensorflow as tf
import numpy as np
from architecture import netG
import sys
if __name__ == '__main__':
checkpoint_dir = sys.argv[1]
n = 15 # cols
m = 5 # rows
num_images = n*m
img_size = (64, 64, 3)
canvas = 255*np.ones((m*img_size[0]+(10*m)+10, n*img_size[1]+(10*n)+10, 3), dtype=np.uint8)
z = tf.placeholder(tf.float32, shape=(num_images, 100), name='z')
generated_images = netG(z, num_images, 0)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
saver = tf.train.Saver()
ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
if ckpt and ckpt.model_checkpoint_path:
print "Restoring previous model..."
try:
saver.restore(sess, ckpt.model_checkpoint_path)
print "Model restored"
except:
raise
print "Could not restore model"
exit()
batch_z = np.random.normal(-1.0, 1.0, size=[num_images, 100]).astype(np.float32)
gen_imgs = sess.run([generated_images], feed_dict={z:batch_z})
gen_imgs = np.squeeze(np.asarray(gen_imgs))
start_x = 10
start_y = 10
x = 0
y = 0
for img in gen_imgs:
img = (img+1.)/2. # these two lines properly scale from [-1, 1] to [0, 255]
img *= 255.0/img.max()
end_x = start_x+64
end_y = start_y+64
canvas[start_y:end_y, start_x:end_x, :] = img
if x < n:
start_x += 64+10
x += 1
if x == n:
x = 0
start_x = 10
start_y = end_y + 10
end_y = start_y+64
import scipy.misc as misc
misc.imsave('results.jpg', canvas)
#cv2.imwrite('results.jpg', canvas)
#cv2.imshow('canvas', canvas)
#cv2.waitKey(0)
#cv2.destroyAllWindows()