如何使用自定义tf.Estimator在Tensorboard事件文件中仅创建图的一个副本?

And*_*huk 9 python tensorflow tensorboard tensorflow-datasets tensorflow-estimator

我正在使用自定义tf.Estimator对象来训练神经网络。问题在于培训后事件文件的大小-太大了。我已经通过使用解决了将一部分数据集保存为常量的问题tf.Dataset.from_generator()。但是,尺寸仍然很大,开始时tensorboard我收到消息

W0225 10:38:07.443567 140693578311424 tf_logging.py:120] Found more than one metagraph event per run. Overwriting the metagraph with the newest event.

因此,我想我正在此事件文件中创建并保存许多不同的图形。是否可以关闭此保存或仅保存第一份副本?

众所周知,我找到了删除所有默认日志的唯一方法,方法是删除带有

list(map(os.remove, glob.glob(os.path.join(runtime_params['model_dir'], 'events.out.tfevents*'))))
Run Code Online (Sandbox Code Playgroud)

但是,这对我来说是一个不好的解决方案,因为我希望保留摘要,最好保留图表的一个副本。

从文档中,我可以看到

估算器自动将以下内容写入磁盘:

  • 检查点,它们是训练期间创建的模型的版本。
  • 事件文件,其中包含TensorBoard用于创建可视化文件的信息。是否可以关闭事件文件的写操作

Căt*_*ilă 1

您需要使用 TensorBoard 工具来可视化摘要日志的内容。

可以读取并使用事件文件日志。您可以看到此链接中的示例提供了有关如何读取写入事件文件的事件的信息。

# This example supposes that the events file contains summaries with a
# summary value tag 'loss'.  These could have been added by calling
# `add_summary()`, passing the output of a scalar summary op created with
# with: `tf.compat.v1.summary.scalar('loss', loss_tensor)`.
for e in tf.compat.v1.train.summary_iterator(path to events file):
    for v in e.summary.value:
        if v.tag == 'loss':
            print(v.simple_value)
Run Code Online (Sandbox Code Playgroud)