Tensorboard 的tensorflow2的启动及应用

 TensorFlow2的tensorflow1的静态图实现

import tensorflow as tf
 
g = tf.compat.v1.Graph()
with g.as_default():
    x = tf.compat.v1.placeholder(name='x', shape=[], dtype=tf.string)
    y = tf.compat.v1.placeholder(name='y', shape=[], dtype=tf.string)
    z = tf.strings.join([x,y],name = "join",separator = " ")
 
with tf.compat.v1.Session(graph = g) as sess:
    # fetches的结果非常像一个函数的返回值,而feed_dict中的占位符相当于函数的参数序列。
    result = sess.run(fetches = z,feed_dict = {x:"hello",y:"world"})
    print(result)

tensorflow动态图的展示:

#https://www.cnblogs.com/xiximayou/p/12673167.html
#tensorflow three different graphs
import tensorflow as tf
 
# 使用autograph构建静态图
 
@tf.function
def strjoin(x,y):
    z =  tf.strings.join([x,y],separator = " ")
    tf.print(z)
    return z
 
result = strjoin(tf.constant("hello"),tf.constant("world"))
print(result)

 

import datetime
 
# 创建日志
stamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
logdir = './data/autograph/%s' % stamp
writer = tf.summary.create_file_writer(logdir)
 
# 开启autograph跟踪
tf.summary.trace_on(graph=True, profiler=True) 
 
# 执行autograph
result = strjoin("hello","world")
 
# 将计算图信息写入日志
with writer.as_default():
    tf.summary.trace_export(
        name="autograph",
        step=0,
        profiler_outdir=logdir)
# 启动 tensorboard在jupyter中的魔法命令
%load_ext tensorboard
# 启动tensorboard
%tensorboard --logdir ./data/autograph/

整个动态图运行:

 该总结对于学习使用tensorflow board 的启动及应用可以参考。

参考链接:【tensorflow2.0】三种计算图 - 西西嘛呦 - 博客园 (cnblogs.com)icon-default.png?t=LA92https://www.cnblogs.com/xiximayou/p/12673167.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值