gpt4 book ai didi

python - 如何使用 python 在 Tensorboard 上显示训练值和预测值

转载 作者:行者123 更新时间:2023-11-28 18:08:29 25 4
gpt4 key购买 nike

我试过这样的:

with tf.Session() as sess: 
sess.run(tf.global_variables_initializer())

merged = tf.summary.merge_all()
writer = tf.summary.FileWriter('logs', sess.graph)
for iteration in range(int(n_epochs*train_set_size/batch_size)):
x_batch, y_batch = get_next_batch(batch_size) # fetch the next training batch

sess.run(training_op, feed_dict={X: x_batch, y: y_batch})

if iteration % int(1*train_set_size/batch_size) == 0:
mse_train = loss.eval(feed_dict={X: x_train, y: y_train})
mse_valid = loss.eval(feed_dict={X: x_valid, y: y_valid})
mse_test = loss.eval(feed_dict={X: x_test, y: y_test})
y_train_pred,summary1,outimage = sess.run([outputs,merged,out_img_sum], feed_dict={X: x_train,y:y_train})
y_valid_pred,summary2 = sess.run([outputs,merged], feed_dict={X: x_valid,y:y_valid})
y_test_pred,summary3 = sess.run([outputs,merged], feed_dict={X: x_test,y:y_test})
writer.add_summary(summary1, iteration*batch_size/train_set_size)

我愿意在张量板上显示 y_trainy_train_pred 值。我该怎么做?这些就像数组,我没有办法在 Tensorboard 上显示这些值的比较。请帮助我。

最佳答案

更新:

是的,您可以沿 x 轴绘图。你在张量板上得到错误图像的原因是因为 int(iteration*float(batch_size)/train_set_size) 总是返回相同的值(0.0001804630682330861 根据你)。我在下面创建了类似您的情况的代码(因为我没有您的数据)。而且效果很好。

import tensorflow as tf
import numpy as np

summary_writer = tf.summary.FileWriter('/tmp/test')

for iteration in range(5):
y_train_preds = np.random.rand(10)
summary = tf.Summary()
for idx, value in enumerate(y_train_preds):
summary.value.add(tag='y_train', simple_value=value)
summary_writer.add_summary(summary, iteration*len(y_train_preds)+idx)

summary_writer.close()

张量板上的输出

enter image description here

唯一需要注意的一点是确保 add_summary() 中的全局步骤每次都应该增加。

也许您可以尝试以下操作:我已经更新了你的代码,你也可以试试

with tf.Session() as sess: 
sess.run(tf.global_variables_initializer())

merged = tf.summary.merge_all()
writer = tf.summary.FileWriter('logs', sess.graph)
for iteration in range(int(n_epochs*train_set_size/batch_size)):
x_batch, y_batch = get_next_batch(batch_size) # fetch the next training batch

sess.run(training_op, feed_dict={X: x_batch, y: y_batch})

if iteration % int(1*train_set_size/batch_size) == 0:
summary = tf.Summary()
mse_train = loss.eval(feed_dict={X: x_train, y: y_train})
mse_valid = loss.eval(feed_dict={X: x_valid, y: y_valid})
mse_test = loss.eval(feed_dict={X: x_test, y: y_test})
y_train_pred,summary1,outimage = sess.run([outputs,merged,out_img_sum], feed_dict={X: x_train,y:y_train})
y_valid_pred,summary2 = sess.run([outputs,merged], feed_dict={X: x_valid,y:y_valid})
y_test_pred,summary3 = sess.run([outputs,merged], feed_dict={X: x_test,y:y_test})
for value in y_train:
summary.value.add(tag='y_train', simple_value=value)
for idx, value in enumerate(y_train_pred):
summary.value.add(tag='y_train_pred', simple_value=value)
writer.add_summary(summary, iteration*len(y_train_pred)+idx)
writer.add_summary(summary1, int(iteration*float(batch_size)/train_set_size))

引用帖子:tensorboard with numpy array

关于python - 如何使用 python 在 Tensorboard 上显示训练值和预测值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52200075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com