Most Simple Usage Of Tensorboard

Starting to learn tensorflow, some questions confused me so much. The problems are like such. Does it necessary to initialize the tensorflow.summaryFileWriter instance? sometimes I wrote a graph and be able to access the graph, sometimes failed to do so.
I had some try. I figured some of my questions out.

Write A Most Simple Graph

import tensorflow as tf
with tf.name_scope('scp1'):
a = tf.Variable(5.5,name="var0")
b = a + tf.Variable(34.2)
with tf.Session() as sess0:
tf.summary.FileWriter('logs',sess0.graph)

save the above code to a .py file, execute it. In the directory where the .py file is stored, there will be a subdirectory logs created. Open command prompt at the dierectory contented the .py file and execute the command tensorboard --logdir logs. It should not be tensorboard --logdir = logs. Then, you can view the graph in chrome.

Problems I Encountered

P1

import tensorflow as tf
with tf.name_scope('scp1'):
a = tf.Variable(5.5,name="var0")
b = a + 34.2
with tf.Session() as sess0:
tf.summary.FileWriter('logs',sess0.graph)

I tried this code, I never wrote a graph. The number 3.42 in the code should be tensorflow.constant(34.2) or tensorflow.Variable(34.2) .

P2

import tensorflow as tf
with tf.name_scope('scp1'):
a = tf.Variable(5.5,name="var0")
b = a + 34.2
with tf.Session() as sess0:
graf = tf.summary.FileWriter('logs',sess0.graph)
tf.global_variables_initializer().run()

Once, I thought the instance of tensorflow.summary.FileWriter may also need to be initialized. I tried some code like the above. In fact, the last sentence above is not necessary.
As the name implied, it’s the the initializer for variables. The graph is not a variable. So, the initializer is not work for the graph. What’s more. The graph is just depends on the definition of the structure. For showing a graph of the structure, initializing the whole structure seems strange. These were what I perplexed with, when I found a code with tf.global_variables_initializer().run() worked.

posted on   yusisc  阅读(21)  评论(0编辑  收藏  举报

编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示