使用SummaryWriter

时间:2016-11-21 20:56:37

标签: tensorflow tensorboard

我在张量流中有一个模型,想要在开发集上评估当前模型。但是,这个集合太大而无法一步评估,所以我将它分成不同的批次。其中每一个都有准确性,损失等。除了保存最终批次的摘要,如下所示,我想将所有这些统计数据的平均值保存到TensorBoard中。

如何做到这一点,因为输出摘要是一个不可读的字符串,我可以将其加载到tf.Summary对象中,但我无法从此创建字符串..

summary = tf.Summary()
for batch in batches:
    x_batch, y_batch = zip(*batch)
    feed_dict = { cnn.input_x: x_batch, cnn.input_y: y_batch, cnn.keep_prob: 1.0 }

    step, summaries, loss, accuracy, mae = sess.run(
        [global_step, dev_summary_op, cnn.loss, cnn.accuracy, cnn.mae],
        feed_dict)
    loss_vector.append(loss)
    accuracy_vector.append(accuracy)
    mae_vector.append(mae)
    # read data into Summary object
    summary.MergeFromString(summaries)
time_str = datetime.datetime.now().isoformat()
loss, accuracy, mae = np.mean(loss_vector), np.mean(accuracy_vector), np.mean(mae_vector)
print("{}: step {}, loss {:g}, acc {:g}, MAE {:g}".format(time_str, step, loss, accuracy, mae))
if writer:
    # unable to use writer.add_summary(summary, step), does not plot in tensorboard....
    writer.add_summary(summaries, step) # saves only last one :(

0 个答案:

没有答案