TensorFlow 可视化Tensorboard

TensorFlow 可视化Tensorboard,第1张

TensorFlow 可视化Tensorboard

童鞋们是不是想看到TensorFlow构建的网络呀!那请往下看!

此处只讲大体 *** 作,具体流程细节可见:

(28条消息) tensorflow Summary方法详解_hongxue8888的博客-CSDN博客_tensorflow的summary

TensorBoard的使用 - 简书 (jianshu.com)

在完成TensorFlow静态图构建后,在程序最后添加

file_writer = tf.summary.FileWriter('./log_dir', sess.graph)

此时,log_dir文件夹内生成如下文件

打开终端,CD到 上图中的log_dir相同目录,输入如下 *** 作:

PS C:UserslenovoDesktopuntitled2> tensorboard --logdir=./log_dir

此时,终端会提供链接

用谷歌浏览器打开后即出现下图

 

2021/1/24 补充,有的朋友想看到中间参数和mnist中的图片,那请往下看。

with tf.name_scope("input"):
    x = tf.placeholder("float", [None, 28, 28, 1],name="x_input")
    y = tf.placeholder("float", [None, n_classes],name="y_input")
    tf.summary.image("x",x)#第一步,查看输入的图片
with tf.name_scope("cost"):
    cost = tf.reduce_mean(
        tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=y))
    tf.summary.scalar("cost",cost)#第一步,查看cost的曲线图

with tf.name_scope("optimizer"):
    optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate).minimize(cost)


init = tf.global_variables_initializer()


with tf.Session() as sess:
    merge_summary = tf.summary.merge_all()  # 第二步,把上述summary合并到下边的Writer里
    file_writer = tf.summary.FileWriter('./log_dir', sess.graph)
    sess.run(init)
    for epoch in range(training_epochs):
        total_batch = int(mnist.train.num_examples/batch_size)

        for i in range(total_batch):
            batch_x, batch_y = mnist.train.next_batch(batch_size)
            sess.run(optimizer, feed_dict={x: batch_x, y: batch_y})
        res = sess.run(merge_summary,feed_dict={x: batch_x, y: batch_y})#第三步,在每次循环过后,将merge_summary 跑一下,然后add到file_writer
        file_writer.add_summary(res)

当当当!现在就tensorboard的其他选项卡里也有东西啦!

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5711608.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存