有没有办法显示 tensorflow 上多个不同运行的平均值?
我只能在同一张图表上看到它们(通过发送不同运行的路径),但是我想在图表上看到它们的平均值
最佳答案
正如@dga所提到的,这尚未实现。这是一些使用 EventAccumulator
组合标量tensorflow摘要值的代码。可以扩展为容纳其他摘要类型。
import os
from collections import defaultdict
import numpy as np
import tensorflow as tf
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
def tabulate_events(dpath):
summary_iterators = [EventAccumulator(os.path.join(dpath, dname)).Reload() for dname in os.listdir(dpath)]
tags = summary_iterators[0].Tags()['scalars']
for it in summary_iterators:
assert it.Tags()['scalars'] == tags
out = defaultdict(list)
for tag in tags:
for events in zip(*[acc.Scalars(tag) for acc in summary_iterators]):
assert len(set(e.step for e in events)) == 1
out[tag].append([e.value for e in events])
return out
def write_combined_events(dpath, d_combined, dname='combined'):
fpath = os.path.join(dpath, dname)
writer = tf.summary.FileWriter(fpath)
tags, values = zip(*d_combined.items())
timestep_mean = np.array(values).mean(axis=-1)
for tag, means in zip(tags, timestep_mean):
for i, mean in enumerate(means):
summary = tf.Summary(value=[tf.Summary.Value(tag=tag, simple_value=mean)])
writer.add_summary(summary, global_step=i)
writer.flush()
dpath = '/path/to/root/directory'
d = tabulate_events(dpath)
write_combined_events(dpath, d)
该解决方案采用如下目录结构:
dpath
├── 1
│ └── events.out.tfevents.1518552132.Alexs-MacBook-Pro-2.local
├── 11
│ └── events.out.tfevents.1518552180.Alexs-MacBook-Pro-2.local
├── 21
│ └── events.out.tfevents.1518552224.Alexs-MacBook-Pro-2.local
├── 31
│ └── events.out.tfevents.1518552264.Alexs-MacBook-Pro-2.local
└── 41
└── events.out.tfevents.1518552304.Alexs-MacBook-Pro-2.local
关于tensorflow - 如何在张量板上显示多次运行的平均值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43068200/