Skip to content

Instantly share code, notes, and snippets.

@amobiny
Created June 10, 2018 04:49
Show Gist options
  • Save amobiny/7160b57e21041ebb91bd3e3d2cd4d1db to your computer and use it in GitHub Desktop.
Save amobiny/7160b57e21041ebb91bd3e3d2cd4d1db to your computer and use it in GitHub Desktop.
# create the variables
x_scalar = tf.get_variable('x_scalar', shape=[], initializer=tf.truncated_normal_initializer(mean=0, stddev=1))
x_matrix = tf.get_variable('x_matrix', shape=[30, 40], initializer=tf.truncated_normal_initializer(mean=0, stddev=1))
# ____step 1:____ create the summaries
# A scalar summary for the scalar tensor
scalar_summary = tf.summary.scalar('My_scalar_summary', x_scalar)
# A histogram summary for the non-scalar (i.e. 2D or matrix) tensor
histogram_summary = tf.summary.histogram('My_histogram_summary', x_matrix)
# ____step 2:____ merge all summaries
merged = tf.summary.merge_all()
init = tf.global_variables_initializer()
# launch the graph in a session
with tf.Session() as sess:
# ____step 3:____ creating the writer inside the session
writer = tf.summary.FileWriter('./graphs', sess.graph)
for step in range(100):
# loop over several initializations of the variable
sess.run(init)
# ____step 4:____ evaluate the merged summaries
summary = sess.run(merged)
# ____step 5:____ add summary to the writer (i.e. to the event file) to write on the disc
writer.add_summary(summary, step)
print('Done writing the summaries')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment