张量板直方图到 matplotlib [英] Tensorboard histograms to matplotlib

查看:28
本文介绍了张量板直方图到 matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to "dump" the tensorboard histograms and plot them via matplotlib. I would have more scientific paper appealing plots.

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

I managed to hack the way through the Summary file using the tf.train.summary_iterator and dump the histogram that I wanted to dump( tensorflow.core.framework.summary_pb2.HistogramProto object). By doing that and implementing what the java-script code does with the data (https://github.com/tensorflow/tensorboard/blob/c2fe054231fe77f3a5b05dbc519f713d2e738d1c/tensorboard/plugins/histogram/tf_histogram_dashboard/histogramCore.ts#L104), I managed to get something similar (same trends) with the tensorboard plots, but not the exact same plot.

我可以对此有所了解吗?

Can I have some light on this?

谢谢

推荐答案

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

The best solution is loading all events and reconstructing all the histogram (as the answer of @khuesmann) but not using EventAccumulator but EventFileLoader. This will give you a histogram per wall time and step as the ones Tensorboard plots. It can be extended to return a list of actions by timestep and wall time.

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

Don't forget to check which tag will you use.

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)

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

bear in mind that tensorflow approximates the actions and treats the actions as continuous variables, so even if you have discrete actions (e.g. 0,1,3) you will end up actions as 0.2,0.4,0.9,1.4 ... in that case round the values will do it.

这篇关于张量板直方图到 matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆