python - 如何使用自定义 tf.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*'))))
但是,这对我来说是一个糟糕的解决方案,因为我更愿意保留摘要,最好保留一份图表副本。
从文档中,我可以看到
估算器自动将以下内容写入磁盘:
- 检查点,它们是在训练期间创建的模型的版本。
- 事件文件,其中包含 TensorBoard 用于创建可视化的信息。是否可以关闭事件文件的写入?
解决方案
您需要使用 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)