Last active
February 28, 2017 18:43
-
-
Save phraniiac/337a791bb091154a8f6fc34990672120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
def add_values(num_list): | |
# making a list of tensors. | |
tensor_list = tf.constant(num_list, shape=[1, 3], name='tensor_list') | |
tensor_ten = tf.constant([10] * len(num_list), \ | |
shape=[len(num_list), 1], name='tensor_ten') | |
# the below statement declares a scope under which the | |
# variables will be used. | |
with tf.name_scope('number_layer1'): | |
tensor_mean = tf.reduce_mean(tensor_list) | |
tensor_val = tf.matmul(tensor_list, tensor_ten) | |
tf.summary.scalar('tensor_mean', tensor_mean) | |
# the below layer is like a nested layer in the above one, | |
# and hence will also be the same way in the graph. | |
with tf.name_scope('number_layer2'): | |
result_tensor = tf.reduce_sum(tensor_val) | |
tf.summary.scalar('result_tensor', result_tensor) | |
return result_tensor | |
# initializing our graph | |
with tf.Graph().as_default(): | |
init = tf.global_variables_initializer() | |
# file writer initialization. | |
writer = tf.summary.FileWriter('./tf_summary/1') | |
with tf.Session() as sess: | |
sess.run(init) | |
sess.run(add_values([10, 20, 30])) | |
writer.add_graph(sess.graph) | |
# this function saves from writing all summaries individually to | |
# the file writer. | |
merged = tf.summary.merge_all() | |
# calculate the summaries. | |
s = sess.run(merged) | |
# write them. | |
writer.add_summary(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment