我在Anaconda环境中的macOS系统中使用Python 3.7.3。 Tensorflow(1.14.0),Matplotlib(3.1.0)和其他模块已安装在那里,一切正常。我编写了以下代码并运行它。
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
def add_layer(inputs, inputs_size, outputs_size,activation_function = None):
with tf.name_scope('layer'):
with tf.name_scope('weight'):
Weights = tf.Variable(tf.random.normal([inputs_size, outputs_size]))
with tf.name_scope('biase'):
biases = tf.Variable(tf.zeros([1,outputs_size])+0.1)
with tf.name_scope('wx_plus_b'):
Wx_plus_b = tf.matmul(inputs, Weights) + biases
if activation_function == None:outputs = Wx_plus_b
else: outputs = activation_function(Wx_plus_b)
return outputs
'''
multiple lines omitted here
'''
writer = tf.compat.v1.summary.FileWriter("logs/",sess.graph)
我可以看到一个名称为
的本地文件"events.out.tfevents.1561289962.Botaos-MacBook-Pro.local"
在“ logs /”文件夹中生成。我打开了终端,并在Anaconda环境激活的情况下将其CD到该文件夹。然后我输入
"python -m tensorboard.main --logdir=‘logs/‘ --host localhost --port 6006"
得到回应
TensorBoard 1.14.0 at http://localhost:6006/ (Press CTRL+C to quit)
然后,无论我使用野生动物园还是Chrome浏览器打开“ http://localhost:6006/”,除了“当前数据集没有活动的仪表板”之外,始终没有显示任何内容。 enter image description here 实际上,我还尝试了其他建议,例如
python -m tensorboard.main --logd logs --host localhost --port 6006
python -m tensorboard.main --logd logs --host localhost --port 6006
但是没有区别。
原始代码如下:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
def add_layer(inputs, inputs_size, outputs_size,activation_function = None):
with tf.name_scope('layer'):
with tf.name_scope('weight'):
Weights = tf.Variable(tf.random.normal([inputs_size, outputs_size]))
with tf.name_scope('biase'):
biases = tf.Variable(tf.zeros([1,outputs_size])+0.1)
with tf.name_scope('wx_plus_b'):
Wx_plus_b = tf.matmul(inputs, Weights) + biases
if activation_function == None:outputs = Wx_plus_b
else: outputs = activation_function(Wx_plus_b)
return outputs
x_data = np.linspace(-1,1,300,dtype = np.float32)[:,np.newaxis]
noise = np.random.normal(0,0.05,x_data.shape).astype(np.float32)
y_data = np.square(x_data) - 0.5 + noise
with tf.name_scope('inputs'):
xs = tf.compat.v1.placeholder(tf.float32,[None,1],name='x_in')
ys = tf.compat.v1.placeholder(tf.float32,[None,1],name='y_in')
l1 = add_layer(xs, 1, 10, tf.nn.relu)
prediction = add_layer(l1, 10, 1, None)
with tf.name_scope('loss'):
loss = tf.reduce_mean(tf.reduce_sum(tf.square(prediction - ys),reduction_indices=[1])) #no need to do tf.sum() as in link. #tf.reduce_mean()
with tf.name_scope('train'):
train_step = tf.compat.v1.train.GradientDescentOptimizer(0.1).minimize(loss)
sess = tf.compat.v1.Session()
writer = tf.compat.v1.summary.FileWriter("logs/",sess.graph)
sess.run(tf.compat.v1.global_variables_initializer())
答案 0 :(得分:0)
我认为问题在于,当您已经在logs目录中时,您正在尝试查找logs目录。
尝试执行:张量板--logdir日志
从包含日志目录的目录中。