缺少张量板标量 [英] tensorboard scalar are missing
问题描述
我写了一个 Tensorflow 程序,现在我想看看我使用 Tensorboard 做了什么,这是代码中有趣的部分:
I've wrote a Tensorflow program, now I want see what I've done using Tensorboard, here is the interesting part of the code :
def train_neural_network(x):
prediction = neuronal_network_model(x)
tf.summary.scalar('Prediction',prediction)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=prediction, labels=y))
tf.summary.scalar('cost',cost)
# default step size of optimizer is 0.001
optimizer = tf.train.AdamOptimizer(learning_rate=1e-3).minimize(cost)
# epoch is feeding forward and + backpropagation (adjusting the weights and the biases )
number_of_epochs = 200
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for epoch in range(number_of_epochs):
shuffle_data()
epoch_loss = 0
for j in range(len(train_data)-1):
if np.shape(train_labels[j]) ==(batch_size,n_classes):
epoch_x = train_data[j]
epoch_y = train_labels[j]
_, c = sess.run([optimizer, cost], feed_dict={x: epoch_x, y: np.reshape(epoch_y,(batch_size,n_classes))})
epoch_loss += c
correct = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct, 'float'))
tf.summary.scalar('Prediction',prediction)
# print('Epoch', epoch, 'complete out of ', number_of_epochs, 'loss', epoch_loss)
loss_vector.append(epoch_loss)
for i in range(len(test_data)-1):
if np.shape(test_labels[i]) == (batch_size,n_classes):
print('Accuracy', accuracy.eval({x: test_data[i], y: test_labels[i]}))
accuracy_vector.append(accuracy.eval({x: test_data[i], y: test_labels[i]}))
merged = tf.summary.merge_all()
train_writer = tf.summary.FileWriter('Tensorboard/DNN',sess.graph)
当我运行 Tensorboard 时,我可以看到图表,但标量选项卡是空的?更新
when I run Tensorboard I can see the graphs but the scalar tab is empty ? Update
这里是输入占位符声明:
here the is the input placeholder declaration:
x = tf.placeholder('float', [None, len(Training_Data[0])],name='input_values')
y = tf.placeholder('float',name='prediction')
推荐答案
您需要像评估其他张量以转储数据一样评估 merged
摘要:
You need to evalute your merged
summaries the same way you evaluate other tensor for it to dump data:
_, c, smry = sess.run([optimizer, cost, merged], feed_dict={x: epoch_x, y: np.reshape(epoch_y,(batch_size,n_classes))})
train_writer.add_summary(smry, j)
其中 j
是您的训练索引.显然,这必须在训练循环中进行.您可能希望每隔 j
的第 n 个值编写摘要,以减轻摘要编写和可视化的负担.
where j
is your training index. Obviously this has to take place within the training loop. You may want to write summaries every n-th value of j
only to alleviate both summary writing and visualization.
更多详情此处.
这篇关于缺少张量板标量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!