-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgan_generator_vis.py
48 lines (40 loc) · 1.43 KB
/
gan_generator_vis.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
"""Script for visualizing generator samples."""
import tensorflow as tf
import matplotlib.pyplot as plt
from gan import GanBuilder
from human_pose_util.register import get_skeleton
from human_pose_util.skeleton import vis3d
def vis(gan_id):
"""Visualize output from the given gan."""
builder = GanBuilder(gan_id)
skeleton = get_skeleton(
builder.params['dataset']['normalize_kwargs']['skeleton_id'])
print('Building graph...')
graph = tf.Graph()
with graph.as_default():
gen_input = builder.get_random_generator_input()
with tf.variable_scope('Generator'):
sample = builder.get_generator_sample(gen_input)
generator_vars = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)
print('Starting session...')
with tf.Session(graph=graph) as sess:
print('Restoring variables...')
saver = tf.train.Saver(var_list=generator_vars)
saver.restore(
sess, builder.latest_checkpoint)
print('Generating...')
sample_data = sess.run(sample)
print('Visualizing...')
for s in sample_data:
vis3d(skeleton, s)
plt.show()
if __name__ == '__main__':
import argparse
from serialization import register_defaults
parser = argparse.ArgumentParser()
parser.add_argument(
'gan_id',
help='id of GAN spec defined in gan_params')
args = parser.parse_args()
register_defaults()
vis(args.gan_id)