脚本(只是简单的线性回归线拟合):
import tensorflow as tf
import numpy as np
ITERS = 25
N = 5000
MINI_BATCH_SIZE = 500
LEARNING_RATE = 0.001
# create dataset & sampling
X = np.random.randn(N)
Y = 0.5 * X + 0.3 * np.random.random(N)
def sample(X, Y, n=MINI_BATCH_SIZE):
idx = np.random.choice(np.arange(X.shape[0]), n, replace=False)
return X[idx], Y[idx]
session = tf.InteractiveSession()
# graph setup
x = tf.placeholder(tf.float32, shape=[None], name="x")
y = tf.placeholder(tf.float32, shape=[None], name="y")
W = tf.Variable(tf.random_uniform([]), trainable=True, name="slope")
b = tf.Variable(tf.random_uniform([]), trainable=True, name="bias")
prediction = W*x + b
# loss & training
loss = tf.reduce_mean(tf.nn.l2_loss(y - prediction), name="l2_loss")
optimizer = tf.train.GradientDescentOptimizer(LEARNING_RATE)
trainer = optimizer.minimize(loss)
# for tensorboard
for value in [loss, W, b]:
print "Adding summaries for: %s" % value.op.name
tf.scalar_summary(value.op.name, value)
summaries_op = tf.merge_all_summaries()
summary_writer = tf.train.SummaryWriter('./stats', session.graph)
# initialize and start
session.run(tf.initialize_all_variables())
print "W: %s, b: %s" % (W.eval(), b.eval())
# train
for i in range(ITERS):
x_batch, y_batch = sample(X, Y)
feed = {x: x_batch, y: y_batch}
trainer.run(feed_dict=feed)
summary_str = summaries_op.eval(feed_dict=feed)
summary_writer.add_summary(summary_str, i)
运行后,目录中有一个protobuf文件stats
,我运行tensorboard
:
$ ls stats/
events.out.tfevents.1466477409.XXXXXXXXXX.local
$ tensorboard --logdir=/Users/me/tensorflow/stats/ --debug
INFO:tensorflow:TensorBoard is in debug mode.
INFO:tensorflow:Starting TensorBoard in directory /Users/me/tensorflow
INFO:tensorflow:TensorBoard path_to_run is: {'/Users/me/tensorflow/stats/': None}
INFO:tensorflow:Adding events from directory /Users/me/tensorflow/stats/
INFO:tensorflow:Constructing EventAccumulator for /Users/me/tensorflow/stats/
DEBUG:tensorflow:Opening a record reader pointing at /Users/me/tensorflow/stats/events.out.tfevents.1466477409.XXXXXXXXXXX.local
DEBUG:tensorflow:No more events in /Users/me/tensorflow/stats/events.out.tfevents.1466477409.XXXXXXXXXXX.local
INFO:tensorflow:No path found after /Users/me/tensorflow/stats/events.out.tfevents.1466477409.XXXXXXXXXXX.local
DEBUG:tensorflow:No more events in /Users/me/tensorflow/stats/events.out.tfevents.1466477409.XXXXXXXXXXX.local
INFO:tensorflow:No path found after /Users/me/tensorflow/stats/events.out.tfevents.1466477409.XXXXXXXXXXX.local
INFO:tensorflow:Multiplexer done loading. Load took 0.0 secs
INFO:tensorflow:TensorBoard is tag: 16
Starting TensorBoard 16 on port 6006
然后当我导航到张量板时,我什么也看不到:
我已经尝试在 Mac OS X 上使用 r0.9 和 r0.8 并获得相同的结果;使用 pip 和 virtualenv 安装。
这里出了什么问题?