tensorboard
Posted francischeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tensorboard相关的知识,希望对你有一定的参考价值。
import tensorflow as tf import numpy as np from matplotlib import pyplot as plt # 清除 tf.reset_default_graph() logdir = ‘log‘ plt.figure() x_data = np.random.rand(1000).astype(np.float32) y_data = x_data * 8 + 1.5 plt.plot(x_data, y_data) plt.show() x = tf.placeholder(tf.float32) y = tf.placeholder(tf.float32) w = tf.Variable(tf.random_normal([1]), tf.float32) b = tf.Variable(tf.random_normal([1]), tf.float32) y_pre = tf.multiply(x, w) + b loss = tf.reduce_sum(tf.pow((y - y_pre), 2)) train = tf.train.GradientDescentOptimizer(0.01).minimize(loss) init = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init) for i in range(1000): sess.run(train, feed_dict={x: x_data[i], y: y_data[i]}) if i % 50 == 0: print(sess.run(loss, feed_dict={x: x_data[i], y: y_data[i]})) writer = tf.summary.FileWriter(logdir, tf.get_default_graph()) writer.close()
1. tf.reset_default_graph() 是清除default gragh 和不断增加的节点
2.定义一个writer,参数为log的地址,和图形这里我们直接用get_default_graph()来获得tensorflow默认生成的图
3.需要把write 关闭了
以上是关于tensorboard的主要内容,如果未能解决你的问题,请参考以下文章
错误处理笔记 导入 torch.utils.tensorboard时 找不到tensorboard
运行代码时出现ModuleNotFoundError: No module named ‘tensorboard‘解决方法
PyTorch tensorboard报错:TensorBoard logging requires TensorBoard version 1.15 or above
PyTorch tensorboard报错:TensorBoard logging requires TensorBoard version 1.15 or above