Plot custom data with Tensorboard

倖福魔咒の 提交于 2020-08-03 07:31:10

问题


I have a personal implementation of a RL algorithm that generates performance metrics every x time steps.

That metric is simply a scalar, so I have an array of scalars that I want to display as a simple graph such as:

I want to display it in real time in tensorboard like my above example.

Thanks in advance


回答1:


If you really want to use tensorboard you can start looking at tensorflow site and this datacamp tutorial on tensorboard.

With tensorflow you can use summary.scalar to plot your custom data (as the example), no need for particular format, as the summary is taking care of that, the only condition is that data has to be a real numeric scalar value, convertible to a float32 Tensor.

import tensorflow as tf

import numpy as np

import os
import time

now = time.localtime()
subdir = time.strftime("%d-%b-%Y_%H.%M.%S", now)

summary_dir1 = os.path.join("stackoverflow", subdir, "t1")
summary_writer1 = tf.summary.create_file_writer(summary_dir1)

for cont in range(200):
    with summary_writer1.as_default():
        tf.summary.scalar(name="unify/sin_x", data=np.math.sin(cont) ,step=cont)
        tf.summary.scalar(name="unify/sin_x_2", data=np.math.sin(cont/2), step=cont)
    summary_writer1.flush()

That said, if you are not planning on using tensorflow with your implementation, I would suggest you just use matplotlib as this library also enables you to plot data in real time https://youtu.be/Ercd-Ip5PfQ?t=444.



来源:https://stackoverflow.com/questions/61367382/plot-custom-data-with-tensorboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!