tensorFlow九:可视化工具
(可视化)生成日志文件的代码:
import tensorflow as tf import os # 屏蔽info os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2' # 可视化的代码 with tf.device("/cpu:0"): with tf.variable_scope(name_or_scope="foo"): x_init1 = tf.get_variable(name="x_init1", shape=[10], initializer=tf.random_normal_initializer()) x = tf.Variable(initial_value=x_init1, name='x') y = tf.placeholder(dtype=tf.float32, name='y') z = tf.add(x, y, name='z') with tf.variable_scope(name_or_scope="bar"): a = tf.constant(3.0) + 4.0 w = z * a # 开始添加、记录信息 tf.summary.scalar(name='scalar_x_init1', tensor=x_init1) tf.summary.scalar(name='scalar_x', tensor=x) tf.summary.scalar(name='scalar_y', tensor=y) tf.summary.scalar(name='scalar_z', tensor=z) tf.summary.scalar(name='scalar_w', tensor=w) # update x assign_op = tf.assign(x, x+1) # 控制依赖:控制assign_op的更新操作 with tf.control_dependencies([assign_op]): with tf.device("/gpu:0"): out = x * y tf.summary.scalar(name='scalar_out', tensor=out) # merge all summary merge_summary = tf.summary.merge_all() # 构建变量初始化 init_op = tf.global_variables_initializer() # 图的执行阶段: with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)) as sess: sess.run(init_op) # 得到输出到文件的对象 writer = tf.summary.FileWriter(logdir="./result", graph=sess.graph) for i in range(1, 5): summary, r_out, r_x, r_w = sess.run([merge_summary, out, x, w], feed_dict={y: i}) writer.add_summary(summary=summary, global_step=i) print("\n{}==={}======{}====={}".format(i, r_out, r_x, r_w)) # 将writer对象关闭 writer.close()
访问tensorBoard:http://localhost:6006
posted on 2019-02-11 22:30 myworldworld 阅读(164) 评论(0) 收藏 举报
【推荐】AI 的力量,开发者的翅膀:欢迎使用 AI 原生开发工具 TRAE
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步