How to visualize a tensor summary in tensorboard

…衆ロ難τιáo~ 提交于 2019-11-29 06:11:19
Michael Gygli

What you do is you create a summary op, but you don't invoke it and don't write the summary (see documentation). To actually create a summary you need to do the following:

# Create a summary operation
summary_op = tf.summary.tensor_summary('softmax_input', out)

# Create the summary
summary_str = sess.run(summary_op)

# Create a summary writer
writer = tf.train.SummaryWriter(...)

# Write the summary
writer.add_summary(summary_str)

Explicitly writing a summary (last two lines) is only necessary if you don't have a higher level helper like a Supervisor. Otherwise you invoke

sv.summary_computed(sess, summary_str)

and the Supervisor will handle it.

More info, also see: How to manually create a tf.Summary()

Hopefully a workaround which achieves what you want. ..

If you wish to view the tensor values, you can convert them using as_string, then use summary.text. The values will appear in the tensorboard text tab.

Not tried with 3D tensors, but feel free to slice according to needs.

code snippet, which includes use of inserting a print statement to get console output as well.

predictions = tf.argmax(reshaped_logits, 1)
txtPredictions = tf.Print(tf.as_string(predictions),[tf.as_string(predictions)], message='predictions', name='txtPredictions')
txtPredictions_op = tf.summary.text('predictions', txtPredictions)

Not sure whether this is kinda obvious, but you could use something like

def make_tensor_summary(tensor, name='defaultTensorName'):
    for i in range(tensor.get_shape()[0]:
        for j in range(tensor.get_shape()[1]:
            tf.summary.scalar(Name + str(i) + '_' + str(j), tensor[i, j])

in case you know it is a 'matrix-shaped' Tensor in advance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!