【问题标题】:tensorboard scalar are missing缺少张量板标量
【发布时间】:2017-09-14 03:33:36
【问题描述】:

我已经写了一个 Tensorflow 程序,现在我想看看我用 Tensorboard 做了什么,这里是代码中有趣的部分:

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 时,我可以看到图表,但标量选项卡是空的? 更新

这里是输入占位符声明:

x = tf.placeholder('float', [None, len(Training_Data[0])],name='input_values')
y = tf.placeholder('float',name='prediction')

【问题讨论】:

  • 不要将 tf.reduce_meantf.summary.scalartf.summary.merge_all 等图形构建函数放在训练循环中。它们应该只执行一次。
  • @interjay 你到底是什么意思?
  • 图形构建操作应该只执行一次,但是您将其中一些放在训练循环中,这样图形元素将不断被重建。

标签: tensorflow tensorboard


【解决方案1】:

您需要评估您的 merged 总结,就像评估其他张量以转储数据一样:

_, 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 个值编写摘要,以减轻摘要编写和可视化。

更多详情here.

【讨论】:

  • * 抱歉,我不知道应该在哪里声明合并?
  • 您的摘要,以及您的合并摘要,以及基本上所有的张量和对它们的操作,都应该在图形构建期间,在您的训练循环之前声明。
  • 当我按照您所说的方式尝试时,我得到一个错误:您必须使用 dtype float 为占位符张量“input_values”提供一个值
  • 我在你的代码中没有看到 input_values 占位符张量,你能更新一下吗?
  • 不确定这是问题,但我已经更新了问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-08
  • 1970-01-01
  • 2013-11-17
  • 2018-02-26
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
相关资源
最近更新 更多