Most Simple Usage Of Tensorboard

本文探讨了使用TensorFlow进行日志记录和图结构可视化的技巧。通过实例介绍了如何创建简单的图结构,并利用summaryFileWriter成功显示这些图。同时,解决了在尝试可视化过程中遇到的一些常见问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值