2

I'm having trouble with reading data from a tensorflow summary writer.

I'm using the writer from the example on the tensorflow website: https://www.tensorflow.org/tensorboard/migrate

import tensorflow as tf
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator

writer = tf.summary.create_file_writer("/tmp/mylogs/eager")

# write to summary writer
with writer.as_default():
  for step in range(100):
    # other model code would go here
    tf.summary.scalar("my_metric", 0.5, step=step)
    writer.flush()

# read from summary writer
event_acc = EventAccumulator("/tmp/mylogs/eager")
event_acc.Reload()
event_acc.Tags()

yields:

 'distributions': [],
 'graph': False,
 'histograms': [],
 'images': [],
 'meta_graph': False,
 'run_metadata': [],
 'scalars': [],
 'tensors': ['my_metric']}```

If I try to grab the tensor data:

import pandas as pd
pd.DataFrame(event_acc.Tensors('my_metric'))

I don't get the right values:

wall_time   step    tensor_proto
0   1.590743e+09    3   dtype: DT_FLOAT\ntensor_shape {\n}\ntensor_con...
1   1.590743e+09    20  dtype: DT_FLOAT\ntensor_shape {\n}\ntensor_con...
2   1.590743e+09    24  dtype: DT_FLOAT\ntensor_shape {\n}\ntensor_con...
3   1.590743e+09    32  dtype: DT_FLOAT\ntensor_shape {\n}\ntensor_con...
...

How do I grab the actual summary data (which should be 0.5, for each of 100 steps)?

Here is a colab notebook with the code above: https://colab.research.google.com/drive/1RlgZrGD_vY-YcOBLF_sEPelmtVuygkqz?usp=sharing

Tim
  • 1,360
  • 1
  • 12
  • 21

2 Answers2

3

To avoid a subset of steps, I would suggest:

event_acc = EventAccumulator("/tmp/mylogs/eager", size_guidance={'tensors': 0})

enter image description here

notacorn
  • 3,526
  • 4
  • 30
  • 60
marusan03
  • 31
  • 2
2

You need to convert the tensor values in the event accumulator, stored as TensorProto messages, into arrays, which you can do with tf.make_ndarray:

pd.DataFrame([(w, s, tf.make_ndarray(t)) for w, s, t in event_acc.Tensors('my_metric')],
             columns=['wall_time', 'step', 'tensor'])
jdehesa
  • 58,456
  • 7
  • 77
  • 121
  • Awesome, thank you. Is there a reason why only a subset of steps (3, 20, 24) are available? – Tim May 29 '20 at 17:26