Tensorboard:访问event_accumulator标签中的张量对象



我正在尝试访问存储在Tensorboard文件中的一些数据。我宁愿不在浏览器中使用Tensorboard GUI打开它,而是直接在python脚本中打开它,以便进行进一步的计算。

我当前的代码:

file = # here, filename is provided
ea = event_accumulator.EventAccumulator(event_file[0])
ea.Reload()
print(ea.Tags())

现在,我的标签(ea.tags(((是这样的:

{'histograms': [], 'scalars': [], 'tensors': ['observable1', 'observable2' ], ...}

第一件有趣的事是,我的可观测数据不是保存在"标量"中,而是保存在"张量"中。现在我该如何访问这些可观测值?我希望这两个oberservable中的每一个都给出一个数组/一个值列表(这就是我感兴趣的(,可能还有一些与张量相关的数据,如形状、数据类型等。

我已经试过使用访问张量

x=ea.Tensors("observable1")
print(x[0])

或者类似的,但我被困在那里了,因为输出是这样的:

TensorEvent(wall_time=1234567890.987654, step=123, tensor_proto=dtype: DT_FLOAT
tensor_shape {
}
tensor_content: "123Y123@"
)

x似乎有一个固定的长度10,这在某种程度上出乎我的意料。有人知道吗?我在网上找到的所有解释都只涉及Tensorboard文件中的标量

前提是它以前是像一样编写的

from torch.utils.tensorboard import SummaryWriter
tensorboard_writer=SummaryWriter(log_dir=logpath)
tensorboard_writer.add_scalar("loss_val", loss, parameter)

此示例将提取分数:

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

也许编写标量不成功?

这篇文章相当古老,但在这里发布是为了将来参考。

例如,要访问observable1中的tensor_content,请执行

x = ea.Tensors("observable1")[0].tensor_proto.tensor_content[0]

并且x将以二进制形式包含您想要的值。

基于这个答案,我更改了

ea = event_accumulator.EventAccumulator(event_file[0])

ea = event_accumulator.EventAccumulator(
event_file[0],
size_guidance={event_accumulator.TENSORS: 0})
)

并且我能够获得所有(超过10个(记录的值。

最新更新