6

Currently tensorflow's tensorboard is not compatible with python3. Therefore and generally, I am looking for a way to print out the summary readouts once in 100 epochs.

Is there a function to parse the summary_str byte string produced in the following lines into a dictionary of floats?

summary_op = tf.merge_all_summaries()
summary_str = sess.run(summary_op, feed_dict=feed_dict)
Dima Lituiev
  • 12,544
  • 10
  • 41
  • 58

1 Answers1

12

You can get a textual representation of summary_str by parsing it into a tf.Summary protocol buffer as follows:

summary_proto = tf.Summary()
summary_proto.ParseFromString(summary_str)
print(summary_proto)

You can then convert it into a dictionary mapping string tags to floats:

summaries = {}
for val in summary_proto.value:
    # Assuming all summaries are scalars.
    summaries[val.tag] = val.simple_value
Engineero
  • 12,340
  • 5
  • 53
  • 75
mrry
  • 125,488
  • 26
  • 399
  • 400
  • I tried it, modifying the third line to `print( summary_str, summary_proto , sep = ":\t")`. What I get is `b'\n\x0e\n\x07L2_loss\x15\xd4J\xcdA\n\x11\n\nL1_penalty\x15\xef\xab\xa6A\n\x0b\n\x04loss\x15j\xa0\xeeA\n\t\n\x02R2\x15@\xd8Y\xbf': None`. And therefore: None has no attribute "value". – Dima Lituiev Jan 03 '16 at 15:52
  • 1
    Ah, there was an error in my original answer on the line with `ParseFromString()`. Should be fixed now. – mrry Jan 03 '16 at 15:54
  • Is there an option to edit the summary_proto after parsing? If I would like for instance to change the tag and then serialize back to string? – aarbelle Jun 22 '17 at 07:41