【问题标题】:Can I use TensorBoard also with jupyter notebooks我可以将 TensorBoard 也用于 jupyter 笔记本吗
【发布时间】:2016-07-02 22:47:25
【问题描述】:

我正在试验(学习)TensorBoard,并使用我从网上获得的以下代码(简单回归函数)

import tensorflow as tf
import numpy as np
#sess = tf.InteractiveSession()  #define a session
# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype("float32")
y_data = x_data * 0.1 + 0.3

# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but Tensorflow will
# figure that out for us.)
with tf.name_scope("calculatematmul") as scope:
    W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
    b = tf.Variable(tf.zeros([1]))
    y = W * x_data + b

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# Before starting, initialize the variables.  We will 'run' this first.
init = tf.initialize_all_variables()

# Launch the graph.
sess = tf.Session()
sess.run(init)

#### ----> ADD THIS LINE <---- ####
writer = tf.train.SummaryWriter('mnist_logs', sess.graph_def)

# Fit the line.
for step in xrange(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(W), sess.run(b))

当我创建一个 python 文件并运行该文件时,代码运行良好

python test.py

它在 jupyter notebook 中也运行良好

然而,虽然 Tensorboard 从运行 python 文件中获取信息(也就是说,它会创建 xyz....home 文件),但交互式版本不会创建任何可用于 Tensorboard 的信息。

谁能给我解释一下为什么!

谢谢 彼得

【问题讨论】:

  • 它是否创建事件文件?此外,如果它将事件文件放入“somedirectory/mnist_logs”,则需要启动 TensorBoard,并将 logdir 设置为 somedirectory,而不是 somedirectory/mnist_logs
  • 笔记本版本不创建事件文件,即使两个版本使用完全相同的代码。

标签: tensorflow tensorboard


【解决方案1】:

确保在启动 tensorboard 时使用完整路径。

tensorboard --logdir='./somedirectory/mnist_logs'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-13
    • 2018-04-08
    • 1970-01-01
    • 2016-05-30
    • 2022-01-25
    • 1970-01-01
    • 2018-09-07
    • 2019-10-03
    相关资源
    最近更新 更多