Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying tf.summary.text with underscores correctly in Tensorboard

I want to log a few strings with underscores to tensorboard. However, the underscores are treated as emphasis somewhere in the pipeline. Here's some example code to illustrate the problem. I've included a few versions that attempt to escape the underscores

import tensorflow as tf
sess = tf.InteractiveSession()
text0 = """/a/b/c_d/f_g_h_2017"""
text1 = """/a/b/c\_d/f\_g\_h\_2017"""
text2 = """/a/b/c\\_d/f\\_g\\_h\\_2017"""

summary_op0 = tf.summary.text('text', tf.convert_to_tensor(text0))
summary_op1 = tf.summary.text('text', tf.convert_to_tensor(text1))
summary_op2 = tf.summary.text('text', tf.convert_to_tensor(text2))
summary_op = tf.summary.merge([summary_op0, summary_op1, summary_op2])
summary_writer = tf.summary.FileWriter('/tmp/tensorboard', sess.graph)
summary = sess.run(summary_op)
summary_writer.add_summary(summary, 0)
summary_writer.flush()
summary_writer.close()

Here's the output:

enter image description here

How can I use tensorboard to properly render strings with tensorboard? Package versions: Tensorflow 1.3.0, TensorBoard 0.1.8

like image 395
eqzx Avatar asked Oct 18 '22 04:10

eqzx


2 Answers

This is working as intended. The docs for tf.summary.text and also for tensorboard.summary.text state that the text will be rendered using Markdown formatting—just like the text in this question and answer—and in Markdown, underscores create italics.

If you don't want this to be the case, you can consider formatting these strings as code, by using either

text0 = """`/a/b/c_d/f_g_h_2017`"""  # backticks: inline code formatting
text1 = """    /a/b/c\_d/f\_g\_h\_2017"""  # four-space indent: code block

This yields the following result:

Screenshot of the resulting text dashboard

(Disclaimer: I work on TensorBoard.)

like image 188
wchargin Avatar answered Oct 21 '22 06:10

wchargin


According to this github issue, this is a bug with the current tensorsorboard and Python 3. For now, using backticks as suggested in another answer is sufficient to render the underscores correctly.

https://github.com/tensorflow/tensorboard/issues/647#issuecomment-337380296

like image 45
eqzx Avatar answered Oct 21 '22 07:10

eqzx