我正在使用名为“ tensorboardcolab”的软件包。但是到目前为止,我只能基于以下代码从张量板获取图形:
!pip install -U tensorboardcolab
from tensorboardcolab import *
tbc=TensorBoardColab()
tf.reset_default_graph()
with tf.get_default_graph().as_default():
x = tf.placeholder(tf.float32, [], name="x")
y = tf.placeholder(tf.float32, [], name="y")
k = tf.get_variable("k", shape=[])
b = tf.get_variable("b", shape=[])
loss = tf.square(k * x + b - y, name="square_error")
optimizer = tf.train.GradientDescentOptimizer(0.5)
train_op = optimizer.minimize(loss)
with tf.Session() as sess:
# Initialize `k` and `b`
sess.run(tf.global_variables_initializer())
for i in range(100):
# y = 3x-1 + noise
data_x = np.random.random()
data_y = 3.0 * data_x - 1.0 + 0.0001*np.random.randn()
k_val, b_val, loss_val, _ = sess.run([k, b, loss, train_op],
feed_dict={x: data_x, y: data_y})
if i % 20 == 0:
print("k, b, loss: ", k_val, b_val, loss_val)
sess.close()
train_writer = tbc.get_writer();
train_writer.add_graph(sess.graph)
train_writer.flush();
tbc.close()
我可以添加一些代码以可视化直方图吗?我不知道要填写“ write_grads = True”等参数。