gpt4 book ai didi

python - 如何从tensorflow 2摘要编写器读取数据

转载 作者:行者123 更新时间:2023-12-02 02:50:27 25 4
gpt4 key购买 nike

我在从 tensorflow 摘要编写器读取数据时遇到问题。

我正在使用tensorflow网站上示例中的编写器: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()

产量:

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

如果我尝试获取张量数据:

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

我没有得到正确的值:

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

如何获取实际的摘要数据(对于 100 个步骤,每一步应该为 0.5)?

这是一个 Colab 笔记本,其中包含上面的代码:https://colab.research.google.com/drive/1RlgZrGD_vY-YcOBLF_sEPelmtVuygkqz?usp=sharing

最佳答案

为了避免步骤子集,我建议:

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

enter image description here

关于python - 如何从tensorflow 2摘要编写器读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62082531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com