首页 > 解决方案 > 从 tensorboard 中提取直方图值并用 matplotlib 绘制它

问题描述

我想自己从张量板上绘制直方图,以发布它。我编写了这个提取函数来获取直方图值:

def _load_hist_from_tfboard(path):
    event_acc = event_accumulator.EventAccumulator(path)
    event_acc.Reload()
    vec_dict = {}
    for tag in sorted(event_acc.Tags()["distributions"]):
        hist_dict = {}

        for hist_event in event_acc.Histograms(tag):
            hist_dict.update({hist_event.step: (hist_event.histogram_value.bucket_limit,
                                                hist_event.histogram_value.bucket)})
        vec_dict[tag] = hist_dict
    return vec_dict

该函数收集事件文件的所有直方图。一个bucket_limit和bucket的输出如下:

[0.0, 1e-12, 0.0005418219168477906, 0.0005960041085325697, 0.0020575678275470133, 0.0022633246103017147, 0.004009617609950718, 0.00441057937094579, 0.005336801038844407, 0.005870481142728848, 0.007813610400972098, 0.008594971441069308, 0.022293142370048362, 0.0245224566070532, 0.026974702267758523, 0.035903328718386605, 0.03949366159022527, 0.043443027749247805, 0.04778733052417259, 0.052566063576589855, 0.057822669934248845, 0.06360493692767373, 0.06996543062044111, 0.07696197368248522, 0.24153964213356663, 0.2656936063469233, 0.29226296698161564, 0.3214892636797772, 0.35363819004775493, 0.38900200905253046, 0.42790220995778355, 0.47069243095356195, 0.5177616740489182, 0.56953784145381, 0.6264916255991911, 0.6891407881591103, 0.7580548669750213, 0.8338603536725235, 0.917246389039776, 1.0089710279437536]
[0.0, 3999936.0, 0.0, 4.0, 0.0, 4.0, 0.0, 4.0, 0.0, 4.0, 0.0, 4.0, 0.0, 4.0, 4.0, 0.0, 8.0, 8.0, 0.0, 4.0, 4.0, 0.0, 8.0, 4.0, 0.0, 9.0, 45.0, 50.0, 48.0, 85.0, 100.0, 109.0, 114.0, 15908.0, 74.0, 15856.0, 11908.0, 3973.0, 42.0, 7951679.0]

有人可以帮我将这些数字解释为直方图吗?

标签: tensorflowtensorboard

解决方案


推荐阅读