我可以将TensorBoard与jupyter笔记本一起使用

时间:2016-03-16 20:18:44

标签: tensorflow tensorboard

我正在试验(学习)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笔记本中运行良好

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

有人可以向我解释原因!

由于 彼得

1 个答案:

答案 0 :(得分:0)

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

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