如何在张量板上显示多次运行的平均值

编程入门 行业动态 更新时间:2024-10-14 20:19:09
本文介绍了如何在张量板上显示多次运行的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

有没有办法在 tensorflow 上显示多次不同运行的平均值?我只能在同一张图上看到它们(通过发送不同运行的路径),但我想在图上看到它们的平均值

Is there a way to display the average of multiple different runs on tensorflow? I can only see them on the same graph (by sending the path of the different runs), but I want to see their average on the graph

推荐答案

正如@dga 提到的,这还没有实现.这是一些使用 EventAccumulator 结合标量张量流汇总值.这可以扩展以适应其他摘要类型.

As @dga mentioned this is not implemented yet. Here is some code that uses EventAccumulator to combine scalar tensorflow summary values. This can be extended to accommodate the other summary types.

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)

此解决方案假定目录结构如下:

This solution assumes a directory structure like the following:

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

这篇关于如何在张量板上显示多次运行的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 05:49:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405468.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:张量   平均值   板上   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!