Python—tf.summary.scalar()用法

简单应用代码:

import tensorflow.compat.v1 as tf
tf.compat.v1.disable_eager_execution()
#由于当前环境使用的是tensorflow 2,使用兼容版本1‘compat v1’之后使用placeholder会不兼容
#tf.placeholder() is not compatible with eager execution.
#所以添加disable_eager_execution
#https://blog.csdn.net/weixin_43763859/article/details/104537392

# 定义两个变量
a = tf.placeholder(dtype=tf.float32, shape=[])
b = tf.placeholder(dtype=tf.float32, shape=[])
#添加变量进去
tf.summary.scalar('a', a)
tf.summary.scalar('b', b)
# 将所有summary全部保存到磁盘,以便tensorboard显示
smy = tf.summary.merge_all()
#初始化全局变量
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
    # 初始化变量
    sess.run(init_op)
    #把信息存储在具体的文件夹里面
    writer = tf.summary.FileWriter("tf_summary_FILE", sess.graph)
    for i in range(5):
        #赋值
        sumers=sess.run(smy,feed_dict={a:i+9,b:i+2})
        #把步骤都记录下来
        writer.add_summary(summary=sumers,global_step=i)

获得文件夹:
在这里插入图片描述
在cmd当中直接在当前环境下,输入:

tensorboard --logdir=文件夹绝对路径\

在这里插入图片描述
浏览器当中输入:

http://localhost:6006/

在这里插入图片描述
参考:
https://blog.csdn.net/weixin_43763859/article/details/104537392
https://blog.csdn.net/tian_jiangnan/article/details/105121217

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值