你如何以编程方式读取 Tensorboard 文件? [英] How do you read Tensorboard files programmatically?

查看:28
本文介绍了你如何以编程方式读取 Tensorboard 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个python脚本来读取Tensorboard日志文件,提取损失和准确率等数值数据,而无需启动GUItensorboard --logdir=...?

How can you write a python script to read Tensorboard log files, extracting the loss and accuracy and other numerical data, without launching the GUI tensorboard --logdir=...?

推荐答案

您可以使用 TensorBoard 的 Python 类或脚本来提取数据:

You can use TensorBoard's Python classes or script to extract the data:

如何从 TensorBoard 导出数据?

如果您想导出数据以在其他地方进行可视化(例如 iPython Notebook),那也是可能的.您可以直接依赖 TensorBoard 用于加载数据的底层类:python/summary/event_accumulator.py(用于从单次运行加载数据)或 python/summary/event_multiplexer.py(用于从多次运行中加载数据,并使其井井有条).这些类加载事件文件组,丢弃被孤立"的数据以及by TensorFlow 崩溃,并按标签组织数据.

If you'd like to export data to visualize elsewhere (e.g. iPython Notebook), that's possible too. You can directly depend on the underlying classes that TensorBoard uses for loading data: python/summary/event_accumulator.py (for loading data from a single run) or python/summary/event_multiplexer.py (for loading data from multiple runs, and keeping it organized). These classes load groups of event files, discard data that was "orphaned" by TensorFlow crashes, and organize the data by tag.

作为另一种选择,有一个脚本 (tensorboard/scripts/serialize_tensorboard.py) 会像 TensorBoard 一样加载 logdir,但将所有数据作为 json 而不是写入磁盘启动服务器.这个脚本是用来制作假 TensorBoard 后端"的.用于测试,所以边缘有点粗糙.

As another option, there is a script (tensorboard/scripts/serialize_tensorboard.py) which will load a logdir just like TensorBoard does, but write all of the data out to disk as json instead of starting a server. This script is setup to make "fake TensorBoard backends" for testing, so it is a bit rough around the edges.

使用EventAccumulator:

# In [1]: from tensorflow.python.summary import event_accumulator  # deprecated
In [1]: from tensorboard.backend.event_processing import event_accumulator

In [2]: ea = event_accumulator.EventAccumulator('events.out.tfevents.x.ip-x-x-x-x',
   ...:  size_guidance={ # see below regarding this argument
   ...:      event_accumulator.COMPRESSED_HISTOGRAMS: 500,
   ...:      event_accumulator.IMAGES: 4,
   ...:      event_accumulator.AUDIO: 4,
   ...:      event_accumulator.SCALARS: 0,
   ...:      event_accumulator.HISTOGRAMS: 1,
   ...:  })

In [3]: ea.Reload() # loads events from file
Out[3]: <tensorflow.python.summary.event_accumulator.EventAccumulator at 0x7fdbe5ff59e8>

In [4]: ea.Tags()
Out[4]: 
{'audio': [],
 'compressedHistograms': [],
 'graph': True,
 'histograms': [],
 'images': [],
 'run_metadata': [],
 'scalars': ['Loss', 'Epsilon', 'Learning_rate']}

In [5]: ea.Scalars('Loss')
Out[5]: 
[ScalarEvent(wall_time=1481232633.080754, step=1, value=1.6365480422973633),
 ScalarEvent(wall_time=1481232633.2001867, step=2, value=1.2162202596664429),
 ScalarEvent(wall_time=1481232633.3877788, step=3, value=1.4660096168518066),
 ScalarEvent(wall_time=1481232633.5749283, step=4, value=1.2405034303665161),
 ScalarEvent(wall_time=1481232633.7419815, step=5, value=0.897326648235321),
 ...]

size_guide:

size_guidance: Information on how much data the EventAccumulator should
  store in memory. The DEFAULT_SIZE_GUIDANCE tries not to store too much
  so as to avoid OOMing the client. The size_guidance should be a map
  from a `tagType` string to an integer representing the number of
  items to keep per tag for items of that `tagType`. If the size is 0,
  all events are stored.

这篇关于你如何以编程方式读取 Tensorboard 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆