This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
greeter_demo.py
73 lines (51 loc) · 2.17 KB
/
greeter_demo.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
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Simple demo which greets several people."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os.path
import tensorflow as tf
# TODO(chihuahua): Figure out why pylint invalidates this import.
import greeter_summary # pylint: disable=import-error
# Directory into which to write tensorboard data.
LOGDIR = '/tmp/greeter_demo'
def run(logdir, run_name, characters, extra_character):
"""Greet several characters from a given cartoon."""
tf.reset_default_graph()
input_ = tf.placeholder(tf.string)
summary_op = greeter_summary.op("greetings", input_)
writer = tf.summary.FileWriter(os.path.join(logdir, run_name))
sess = tf.Session()
for character in characters:
summary = sess.run(summary_op, feed_dict={input_: character})
writer.add_summary(summary)
# Demonstrate that we can also add summaries without using the
# TensorFlow session or graph.
summary = greeter_summary.pb("greetings", extra_character)
writer.add_summary(summary)
writer.close()
def run_all(logdir, unused_verbose=False):
"""Run the simulation for every logdir.
"""
run(logdir, "steven_universe", ["Garnet", "Amethyst", "Pearl"], "Steven")
run(logdir, "futurama", ["Fry", "Bender", "Leela"],
"Lrrr, ruler of the planet Omicron Persei 8")
def main(unused_argv):
print('Saving output to %s.' % LOGDIR)
run_all(LOGDIR, unused_verbose=True)
print('Done. Output saved to %s.' % LOGDIR)
if __name__ == '__main__':
tf.app.run()