Python 从Tensorflow摘要中获取CSV
我有一些非常大的tensorflow摘要。如果这些是使用tensorboard绘制的,我可以从中下载CSV文件 然而,使用张力板绘制这些曲线需要很长时间。我发现有一种方法可以直接用Python阅读摘要。此方法是Python 从Tensorflow摘要中获取CSV,python,csv,tensorflow,Python,Csv,Tensorflow,我有一些非常大的tensorflow摘要。如果这些是使用tensorboard绘制的,我可以从中下载CSV文件 然而,使用张力板绘制这些曲线需要很长时间。我发现有一种方法可以直接用Python阅读摘要。此方法是summary\u iterator,可按如下方式使用: import tensorflow as tf for e in tf.train.summary_iterator(path to events file): print(e) 我可以使用此方法直接创建CSV文件吗?如
summary\u iterator
,可按如下方式使用:
import tensorflow as tf
for e in tf.train.summary_iterator(path to events file):
print(e)
我可以使用此方法直接创建CSV文件吗?如果是,我该怎么做?这将节省大量时间。一种可能的方法是:
from tensorboard.backend.event_processing import event_accumulator
import numpy as np
import pandas as pd
import sys
def create_csv(inpath, outpath):
sg = {event_accumulator.COMPRESSED_HISTOGRAMS: 1,
event_accumulator.IMAGES: 1,
event_accumulator.AUDIO: 1,
event_accumulator.SCALARS: 0,
event_accumulator.HISTOGRAMS: 1}
ea = event_accumulator.EventAccumulator(inpath, size_guidance=sg)
ea.Reload()
scalar_tags = ea.Tags()['scalars']
df = pd.DataFrame(columns=scalar_tags)
for tag in scalar_tags:
events = ea.Scalars(tag)
scalars = np.array(map(lambda x: x.value, events))
df.loc[:, tag] = scalars
df.to_csv(outpath)
if __name__ == '__main__':
args = sys.argv
inpath = args[1]
outpath = args[2]
create_csv(inpath, outpath)
请注意,此代码将把整个事件文件加载到内存中,因此最好在集群上运行此代码。有关eventacculator
的sg
参数的信息,请参阅
另外一个改进可能是不仅存储每个标量的值
,而且还存储步骤
注意:代码段已针对最新版本的TF
进行了更新对于TF<1.1使用以下导入:
from tensorflow.tensorboard.backend.event_processing import event_accumulator as eva
好主意!顺便说一句,从TF 1.1开始,包是
tensorboard.backend.event\u processing import event\u acculator
。我冒昧地更新了你的代码