【问题标题】:Tensorboard visualization don't appear in google collabTensorboard 可视化不会出现在谷歌协作中
【发布时间】:2020-11-10 13:42:19
【问题描述】:

我正在 google collab 中实现一个简单的线性回归代码,并尝试使用以下命令使用 tensorboard 可视化结果 %tensorboard --logdir=/tmp/lr-train.

但是,当我运行此命令时,张量板根本不显示。相反,我只看到以下消息Reusing TensorBoard on port 6012 (pid 3219), started 0:07:06 ago. (Use '!kill 3219' to kill it.)

在我的情况下如何启动张量板?这是我要运行的代码:

%tensorflow_version 1.x
import tensorflow as tf
import numpy as np

N = 100
x_zeros = np.random.multivariate_normal(
                            mean=np.array((-1, -1)), cov = 0.1 * np.eye(2), size = (N//2))
y_zeros = np.zeros((N//2,))
x_ones = np.random.multivariate_normal(mean=np.array((1, 1)), cov = 0.1 * np.eye(2), size=(N//2))
y_ones = np.zeros((N//2))
x_np = np.vstack([x_zeros, x_ones])
y_np = np.concatenate([y_zeros, y_ones])

with tf.name_scope("placeholders"):
  x = tf.placeholder(tf.float32, (N, 2))
  y = tf.placeholder(tf.float32, (N, 1))
with tf.name_scope("weights"):
  W = tf.Variable(tf.random_normal((2, 1)))
  b = tf.Variable(tf.random_normal((1, )))
with tf.name_scope("prediction"):
  y_pred = tf.matmul(x, W) + b
with tf.name_scope("loss"):
  l = tf.reduce_sum((y - y_pred)**2)
with tf.name_scope("optim"):
  train_op = tf.train.AdamOptimizer(0.05).minimize(l)
with tf.name_scope("summaries"):
  tf.summary.scalar("loss", l)
  merged = tf.summary.merge_all()

train_writer = tf.summary.FileWriter('/tmp/lr-train', tf.get_default_graph())

n_steps = 100
with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  # Train model
  for i in range(n_steps):
    feed_dict = {x: x_np, y: y_np.reshape(-1,1)}
    _, summary, loss = sess.run([train_op, merged, l], feed_dict=feed_dict)
    if i%10 == 0:
      print("step %d, loss: %f" % (i, loss))

我在 tf-2 中尝试了 an example,并且使用相同的命令启动了 tensorboard,没有任何问题。

【问题讨论】:

    标签: tensorflow google-colaboratory tensorboard


    【解决方案1】:

    您还可以终止活动会话,然后重新运行所有单元格。但也许你甚至找到了一种在会话中杀死张量板的方法。

    【讨论】:

      【解决方案2】:

      我在 Colab 中尝试了您的代码,并且能够重现您提到的内容,并找到了一个如下所述的解决方案。

      —logdir/tmp/lr-train 之间使用“空格”而不是=

      问题中提到的什么不起作用:

      %load_ext tensorboard
      %tensorboard --logdir=/tmp/lr-train
      

      什么有效:

      %load_ext tensorboard
      %tensorboard --logdir /tmp/lr-train
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-13
        • 2020-05-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-09
        • 1970-01-01
        相关资源
        最近更新 更多