How to visualize a tensor summary in tensorboard

☆樱花仙子☆ 提交于 2019-11-27 23:57:30

问题


I'm trying to visualize a tensor summary in tensorboard. However I can't see the tensor summary at all in the board. Here is my code:

        out = tf.strided_slice(logits, begin=[self.args.uttWindowSize-1, 0], end=[-self.args.uttWindowSize+1, self.args.numClasses],
                               strides=[1, 1], name='softmax_truncated')
        tf.summary.tensor_summary('softmax_input', out)

where out is a multi-dimensional tensor. I guess there must be something wrong with my code. Probably I used the tensor_summary function incorrectly.


回答1:


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()




回答2:


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)




回答3:


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.



来源:https://stackoverflow.com/questions/41671817/how-to-visualize-a-tensor-summary-in-tensorboard

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