TensorFlow:打开SummaryWriter

时间:2016-04-18 17:19:51

标签: tensorflow tensorboard

summaries and TensorBoard上完成本教程之后,我已经能够使用TensorBoard成功保存并查看数据。是否可以用TensorBoard以外的其他东西打开这些数据?

顺便说一句,我的申请是做政策外学习。我目前正在使用SummaryWriter保存每个状态 - 动作 - 奖励元组。我知道我可以手动存储/训练这些数据,但我认为使用TensorFlow的内置日志记录功能存储/加载这些数据会很不错。

7 个答案:

答案 0 :(得分:19)

截至2017年3月,从Tensorflow核心到Tensorboard后端的EventAccumulator工具has been moved。您仍然可以使用它从Tensorboard日志文件中提取数据,如下所示:

from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
event_acc = EventAccumulator('/path/to/summary/folder')
event_acc.Reload()
# Show all tags in the log file
print(event_acc.Tags())

# E. g. get wall clock, number of steps and value for a scalar 'Accuracy'
w_times, step_nums, vals = zip(*event_acc.Scalars('Accuracy'))

答案 1 :(得分:5)

我认为数据是编码的protobufs RecordReader格式。要从文件中获取序列化字符串,您可以使用py_record_reader或使用TFRecordReader op构建图表,并将这些字符串反序列化为protobuf,并使用事件schema。如果你得到一个有效的例子,请更新这个q,因为我们似乎缺少相关的文档。

答案 2 :(得分:3)

很简单,数据实际上可以导出到“事件”选项卡下的TensorBoard中的$controllers = [ 1 => 'ServicesHallController', 2 => 'ServicesBeautycenterController', 3 => 'ServicesDressController', 4 => 'ServicesCarController', 5 => 'ServicesPhotographyController', 6 => 'ServicesHoneymoonController', ]; Route::group(['middleware'=>'auth'],function(){ Route::Resource('profile', $controllers[session()->get('category')]); }); 文件,例如,在Python中加载Pandas数据帧。请务必查看数据下载链接框。

要获得更加自动化的方法,请查看TensorBoard readme

  

如果您想将数据导出到其他地方(例如iPython)   笔记本),这也是可能的。你可以直接依赖   TensorBoard用于加载数据的基础类:   .csv(用于从单个数据加载数据)   运行)或python/summary/event_accumulator.py(用于加载数据)   多次运行,并保持有序)。这些类加载组   事件文件,丢弃"孤立的数据"通过TensorFlow崩溃,   并按标签组织数据。

     

作为另一种选择,有一个脚本   (python/summary/event_multiplexer.py)将加载一个   logdir就像TensorBoard一样,但写出所有数据   磁盘作为json而不是启动服务器。此脚本设置为   make"假TensorBoard后端"用于测试,所以它有点粗糙   在边缘。

答案 3 :(得分:2)

我为以前的项目做过这些方面的事情。正如其他人所提到的,主要成分是tensorflows事件累加器

from tensorflow.python.summary import event_accumulator as ea

acc = ea.EventAccumulator("folder/containing/summaries/")
acc.Reload()

# Print tags of contained entities, use these names to retrieve entities as below
print(acc.Tags())

# E. g. get all values and steps of a scalar called 'l2_loss'
xy_l2_loss = [(s.step, s.value) for s in acc.Scalars('l2_loss')]

# Retrieve images, e. g. first labeled as 'generator'
img = acc.Images('generator/image/0')
with open('img_{}.png'.format(img.step), 'wb') as f:
  f.write(img.encoded_image_string)

答案 4 :(得分:1)

您还可以使用tf.train.summaryiterator:在./logs - 仅包含经典标量lraccloss,{{的文件夹中提取事件1}}和val_acc存在,您可以使用此GIST:tensorboard_to_csv.py

答案 5 :(得分:0)

当 tfevent 文件中的数据点少于 10000 个时,Chris Cundy 的回答很有效。然而,当你有一个超过 10000 个数据点的大文件时,Tensorboard 会自动对它们进行采样,并且最多只给你 10000 个点。这是一个非常烦人的潜在行为,因为它没有得到很好的记录。见https://github.com/tensorflow/tensorboard/blob/master/tensorboard/backend/event_processing/event_accumulator.py#L186

要绕过它并获取所有数据点,有点笨拙的方法是:

from tensorboard.backend.event_processing.event_accumulator import EventAccumulator

class FalseDict(object):
    def __getitem__(self,key):
        return 0
    def __contains__(self, key):
        return True

event_acc = EventAccumulator('path/to/your/tfevents',size_guidance=FalseDict())

答案 6 :(得分:0)

看起来对于 tb 版本 >=2.3,您可以使用 tensorboard.data.experimental.ExperimentFromDev() 简化将 tb 事件转换为 Pandas 数据帧的过程。 不过,它要求您将日志上传到 TensorBoard.dev,这是公开的。未来有计划将功能扩展到本地存储的日志。 https://www.tensorflow.org/tensorboard/dataframe_api