#coding=utf-8
import tensorflow as tf
import numpy as np
graph = tf.Graph()
with graph.as_default():
with tf.name_scope("variables"):
global_step = tf.Variable(0, dtype = tf.int32, trainable = False, name = "global_step")
total_output = tf.Variable(0.0, dtype = tf.float32, trainable = False, name = "total_output")
with tf.name_scope("transfromation"):
with tf.name_scope("input"):
a = tf.placeholder(tf.float32, shape = [None], name = "input_placeholder_a")
with tf.name_scope("intermediate_layer"):
b = tf.reduce_prod(a, name = "product_b")
c = tf.reduce_sum(a, name = "sum_c")
with tf.name_scope("output"):
output = tf.add(b, c, name = "output")
with tf.name_scope("update"):
update_total = total_output.assign_add(output)
increment_step = global_step.assign_add(1)
with tf.name_scope("summaries"):
avg = tf.div(update_total, tf.cast(increment_step, tf.float32), name = "average")
tf.scalar_summary(b'Output', output, name = "output_summary")
tf.scalar_summary(b'Sum of outputs over time', update_total, name = "total_summary")
tf.scalar_summary(b'Average of outputs over time', avg, name = "average_summary")
with tf.name_scope("global_ops"):
init = tf.initialize_all_variables()
merged_summaries = tf.merge_all_summaries()
sess = tf.Session(graph = graph)
writer = tf.train.SummaryWriter('./improved_graph', graph)
sess.run(init)
def run_graph(input_tensor):
feed_dict = {a: input_tensor}
_, step, summary = sess.run([output, increment_step, merged_summaries], feed_dict = feed_dict)
writer.add_summary(summary, global_step = step)
run_graph([2, 8])
run_graph([3, 1, 3, 3])
run_graph([8])
run_graph([1, 2, 3])
run_graph([11, 4])
run_graph([4, 1])
run_graph([7, 3, 1])
run_graph([6, 3])
run_graph([0, 2])
run_graph([4, 5, 6])
writer.flush()
writer.close()
sess.close()
improved graph
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 资料来源: Knowledge Graph tutorial (AAAI 2017-part 3) 相关链接:ht...
- 基本的graph搜索题 1: DFS BFS: 并查集,并查集直观找num of edges, 所以用n - nu...
- 世界名塔需要复杂的电网维持。其控制器是个很多网格的面板,一旁的胶水瓶貌似是用来粘贴什么东西的。面板左边画了很多进入...
- BGL官网入口Boost库说明 BGL的用途是给某些图的结构提供接口,而隐藏其内部细节不需要built,但是编译程...