'Tensorboard: Accessing tensor-objects in the tags of event_accumulator
I'm trying to access some data stored in a Tensorboard-file. I would prefer not opening it with the Tensorboard GUI in my browser but directly open it in a python-script to be able to do further calculations.
My current code:
file = # here, filename is provided
ea = event_accumulator.EventAccumulator(event_file[0])
ea.Reload()
print(ea.Tags())
Now, my tags (ea.Tags()) are sth. like this:
{'histograms': [], 'scalars': [], 'tensors': ['observable1', 'observable2' ], ...}
First thing that's interesting is that my data of the observables are not saved in 'scalars' but in 'tensors'. How can I access these observables now? I would expect that each of the two oberservables gives an array/ a list of values (that's what I'm interested in) and probably also some tensor-related data like shapes, datatype etc.
I've already tried out to access the tensors using
x=ea.Tensors("observable1")
print(x[0])
or similar, but I got stuck in there as the output is sth. like this:
TensorEvent(wall_time=1234567890.987654, step=123, tensor_proto=dtype: DT_FLOAT
tensor_shape {
}
tensor_content: "\123Y\123@"
)
and x seems to have a fixed length of 10 which was, in somehow, unexpected to me. Does somebody have an idea? All the explanations I found on the internet are dealing only about the scalars in a Tensorboard-file
Solution 1:[1]
Provided that it has been previously written like
from torch.utils.tensorboard import SummaryWriter
tensorboard_writer=SummaryWriter(log_dir=logpath)
tensorboard_writer.add_scalar("loss_val", loss, parameter)
this example will extract the score:
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
event_acc = EventAccumulator(logpath, size_guidance={"scalars": 0})
event_acc.Reload()
for scalar in event_acc.Tags()["scalars"]:
w_times, step_nums, vals = zip(*event_acc.Scalars(scalar))
Perhaps writing the scalars wasn't successful?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jacquesdirac |
