张量板直方图到 matplotlib

Tia*_*ira 6 tensorflow tensorboard

我想“转储”张量板直方图并通过 matplotlib 绘制它们。我会有更多的科学论文吸引人的情节。

我设法使用tf.train.summary_iterator并转储了我想转储的直方图(tensorflow.core.framework.summary_pb2.HistogramProto对象)来破解摘要文件。通过这样做并实现 java 脚本代码对数据的作用(https://github.com/tensorflow/tensorboard/blob/c2fe054231fe77f3a5b05dbc519f713d2e738d1c/tensorboard/plugins/histogram/tf_histogram_dashboard/histogram1 managed to Ito4.ts)#L得到与张量板图相似(相同趋势)的东西,但不是完全相同的图。

我可以对此有所了解吗?

谢谢

小智 5

为了使用 matplotlib 绘制张量板直方图,我正在执行以下操作:

event_acc = EventAccumulator(path, size_guidance={
    'histograms': STEP_COUNT,
})
event_acc.Reload()
tags = event_acc.Tags()
result = {}
for hist in tags['histograms']:
    histograms = event_acc.Histograms(hist)
    result[hist] = np.array([np.repeat(np.array(h.histogram_value.bucket_limit), np.array(h.histogram_value.bucket).astype(np.int)) for h in histograms])
return result
Run Code Online (Sandbox Code Playgroud)

h.histogram_value.bucket_limit给我这个值的值和h.histogram_value.bucket计数。因此,当我相应地重复这些值 ( np.repeat(...)) 时,我会得到一个预期大小的巨大数组。现在可以使用默认的 matplotlib 逻辑绘制此数组。

  • 这是最好的解决方案,同时 tf 支持以 csv 下载它。 (2认同)

Mik*_*e W 5

最好的解决方案是加载所有事件并重建所有直方图(作为@khuesmann 的答案)但不使用EventAccumulatorbut EventFileLoader。这将为您提供每个墙壁时间和步骤的直方图,如 Tensorboard 绘图所示。它可以扩展为按时间步长和墙时间返回动作列表。

不要忘记检查您将使用哪个标签。

from tensorboard.backend.event_processing.event_file_loader import EventFileLoader
# Just in case, PATH_OF_FILE is the path of the file, not the folder
loader = EventFileLoader(PATH_Of_FILE)

# Where to store values
wtimes,steps,actions = [],[],[]
for event in loader.Load():
    wtime   = event.wall_time
    step    = event.step
    if len(event.summary.value) > 0:
        summary = event.summary.value[0]
        if summary.tag == HISTOGRAM_TAG:
            wtimes += [wtime]*int(summary.histo.num)
            steps  += [step] *int(summary.histo.num)

            for num,val in zip(summary.histo.bucket,summary.histo.bucket_limit):
                actions += [val] *int(num)
Run Code Online (Sandbox Code Playgroud)

请记住,张量流近似动作并将动作视为连续变量,因此即使您有离散动作(例如 0,1,3),您最终的动作也会为 0.2,0.4,0.9,1.4 ... 在这种情况下轮值将做到这一点。