当我打开Tensorboard时,即使我的Tensorboard日志目录中包含文件,也会出现一个窗口,显示“当前数据集没有活动的仪表板”。
这是我用来启动Tensorboard的命令
tensorboard --logdir tf_logs/
tf_logs
目录中包含这些文件夹和文件
run-20190609234531
events.out.tfevents.1560125157.BRUBIN
run-20190610010816
events.out.tfevents.1560128897.BRUBIN
run-20190610010949
events.out.tfevents.1560128989.BRUBIN
这是我用来创建日志文件的代码(add_summary
位于代码的结尾)。
import datetime
import numpy as np
import sklearn
import tensorflow as tf
from datetime import datetime
from sklearn.datasets import fetch_california_housing
from sklearn.preprocessing import StandardScaler
def fetch_batch(epoch, batch_index, batch_size):
np.random.seed(epoch * n_batches + batch_index)
indices = np.random.randint(m, size=batch_size)
X_batch = scaled_housing_data_plus_bias[indices]
y_batch = housing.target.reshape(-1, 1)[indices]
return X_batch, y_batch
now = datetime.utcnow().strftime("%Y%m%d%H%M%S")
root_logdir = "tf_logs"
logdir = "{}/run-{}/".format(root_logdir, now)
housing = fetch_california_housing()
m, n = housing.data.shape
housing_data_plus_bias = np.c_[np.ones((m, 1)), housing.data]
scaler = StandardScaler(copy = True)
scaled_housing_data = scaler.fit_transform(housing.data)
scaled_housing_data_plus_bias = np.c_[np.ones((m, 1)), scaled_housing_data]
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, seed=42), name="theta")
y_pred = tf.matmul(X, theta, name="predictions")
error = y_pred - y
mse = tf.reduce_mean(tf.square(error), name="mse")
optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate)
training_op = optimizer.minimize(mse)
init = tf.global_variables_initializer()
batch_size = 100
learning_rate = 0.01
n_epochs = 1000
n_batches = int(np.ceil(m / batch_size))
mse_summary = tf.summary.scalar('MSE', mse)
file_writer = tf.summary.FileWriter(logdir, tf.get_default_graph())
with tf.Session() as sess:
sess.run(init)
for epoch in range(n_epochs):
for batch_index in range(n_batches):
X_batch, y_batch = fetch_batch(epoch, batch_index, batch_size)
if batch_index % 10 == 0:
summary_str = mse_summary.eval(feed_dict={X: X_batch, y: y_batch})
step = epoch * n_batches + batch_index
##### Write the Tensorboard log #####
file_writer.add_summary(summary_str, step)
sess.run(training_op, feed_dict={X: X_batch, y: y_batch})
best_theta = theta.eval()
file_writer.close()
sess.close()
为什么Tensorboard不显示这些图?
答案 0 :(得分:1)
我运行了您的代码,发现了一个错误:
learning_rate = 0.01
是在使用后定义的。
我在使用它之前将其更改为已定义,并且代码运行良好,还运行了张量板,并向我显示了图形和标量。
如果那不是您的问题,我只能想到另一个问题:
您必须位于tf_logs目录所在的目录中。