你如何以编程方式阅读Tensorboard文件?

mik*_*305 22 python machine-learning tensorflow tensorboard

如何在不启动GUI的情况下编写python脚本来读取Tensorboard日志文件,提取损失和准确性以及其他数值数据tensorboard --logdir=...

use*_*961 27

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

如何从TensorBoard导出数据?

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

作为另一个选项,有一个脚本(tensorboard/scripts/serialize_tensorboard.py)将像TensorBoard一样加载logdir,但是将所有数据作为json写入磁盘而不是启动服务器.此脚本设置为"伪TensorBoard后端"进行测试,因此它的边缘有点粗糙.

使用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),
 ...]
Run Code Online (Sandbox Code Playgroud)

size_guidance:

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.
Run Code Online (Sandbox Code Playgroud)

  • 从Tensorflow的1.1.0版本开始,event_accumulator已移至tensorflow/tensorflow/tensorboard/backend/event_processing.要使代码在1.1.0版中工作,import语句应该是来自tensorflow.tensorboard.backend.event_processing import event_accumulator` [更多信息在这里](https://github.com/tensorflow/tensorflow/issues/9532) (8认同)
  • 从1.3开始,它已从TensorFlow仓库转移到专用的TensorBoard仓库.新家:https://github.com/tensorflow/tensorboard.可以作为独立包进行pip安装,import语句现在是:`from tensorboard.backend.event_processing import event_accumulator` (8认同)
  • 您能否提供一个工作示例,说明在这些脚本中究竟要使用什么? (2认同)
  • 仅供参考:我创建了一个工具,可以聚合多个张量板摘要并将结果保存到新的张量板摘要中或保存为.csv文件。在这里看看:https://github.com/Spenhouet/tensorboard-aggregator (2认同)

mik*_*305 6

要完成user1501961的回答,您只需要将标量列表轻松导出到带有熊猫的csv文件中 pd.DataFrame(ea.Scalars('Loss)).to_csv('Loss.csv')