我目前正试图开始使用tensorflow . 在这样做的同时,我遇到了一些关于张量板的问题 . 其中一些已经修复,但除此之外,当我使用隧道连接访问时,我仍然遇到张量板没有显示任何内容的问题 .

我100%肯定这与我的隧道结构无关,因为当与高级API(如keras)一起使用时,tensorboard确实会显示信息 . 我只是认为下面的代码创建了空文件,而我保存摘要的尝试是错误的 . 有人可以向我澄清为什么tensorboard没有显示任何信息?

n_epochs = 10
learning_rate = 0.01
batch_size = 100 
n_batches = int(np.ceil(m/ batch_size))

get_ipython().system_raw('tensorboard --logdir ./test_log --host 0.0.0.0 --port 6006')
get_ipython().system_raw('./ngrok http 6006 &')
! curl -s http://localhost:4040/api/tunnels | python3 -c \
"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"

X = tf.placeholder(tf.float32, shape=(None, n + 1), name="X")
y = tf.placeholder(tf.float32, shape=(None, 1), name="y")
theta = tf.Variable(tf.random_uniform([n + 1, 1], -1.0, 1.0), name="theta")

yPredictions = tf.matmul(X, theta)
error = yPredictions - y
mse = tf.reduce_mean(tf.square(error), name="mse")

training_op = optimizer.minimize(mse)

mse_summary = tf.summary.scalar("MSE", mse)
file_writer = tf.summary.FileWriter("./test_log", 
tf.get_default_graph())

optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate)

init = tf.global_variables_initializer()

with tf.Session() as session:
  session.run(init)

  for epoch in range(n_epochs):
    for batch_index in range(n_batches):
      # Get batch data
      X_batch, y_batch = fetch_batch(epoch, batch_index, batch_size)

      #Add summary for tensorboard
      if batch_index % 10 == 0:
        summary_string = mse_summary.eval(feed_dict={X: X_batch, y: y_batch})
        step = epoch * n_batches + batch_index
        file_writer.add_summary(summary_string, step)

      session.run(training_op, feed_dict={X: X_batch, y: y_batch})
  file_writer.close()
  best_theta = theta.eval()