gpt4 book ai didi

python - 张量板中没有标量数据

转载 作者:行者123 更新时间:2023-12-01 02:45:25 25 4
gpt4 key购买 nike

我一直在阅读有关标量的张量板文档,但在张量板中呈现它时遇到问题。

我在 Windows 10 中安装了 pip install tensorflow

我的代码如下所示:

import tensorflow as tf

a = tf.constant(7, name='test_variable')
tf.summary.scalar('variable', a)

with tf.Session() as sess:
tf.summary.FileWriter('my_folder', graph=sess.graph)
X = tf.global_variables_initializer()
sess.run(X)

我看到my_folder中有一个文件

在命令提示符中:tensorboard --logdir=my_folder --port 6006

输出:

C:\Users\MM>tensorboard --logdir=my_folder --port 6006
Starting TensorBoard b'54' at http://DESKTOP-9S2D9VF:6006
(Press CTRL+C to quit)

当我打开浏览器时,我得到:

No scalar data was found. 
Probable causes: etc. etc.

最佳答案

您需要运行summary_op并将结果传递给FileWriter。例如:

import tensorflow as tf

a = tf.constant(7, name='test_variable')
tf.summary.scalar('variable', a)
summary_op = tf.summary.merge_all()

with tf.Session() as sess:
summary_writer = tf.summary.FileWriter('/tmp/summary', graph=sess.graph)
X = tf.global_variables_initializer()
sess.run(X)
summary = sess.run(summary_op)
summary_writer.add_summary(summary)

来自官方documentation :

Then, you can just run the merged summary op, which will generate a serialized Summary protobuf object with all of your summary data at a given step. Finally, to write this summary data to disk, pass the summary protobuf to a tf.summary.FileWriter.

关于python - 张量板中没有标量数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45308755/

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