如何在张量流中的同一图上绘制两个不同的摘要?

时间:2018-12-15 16:55:59

标签: python tensorflow

我看到了许多与此问题有关的问题,但仍然没有一个能解决我的问题。我想绘制每个步骤的训练损失,并在一个时代结束时绘制平均验证损失。这就是为什么我需要两个不同的摘要。目前,我设法做到了,但是图形是分开的。如何在张量板的一张图中同时显示它们?

相关代码如下:

training_summary_op = tf.summary.scalar('loss', tf.squeeze(loss))
val_placeholder = tf.placeholder(tf.float32, shape=())
validation_summary_op = tf.summary.scalar('loss', val_placeholder)

train_writer = tf.summary.FileWriter(self.output_dir + "/train", sess.graph)
val_writer = tf.summary.FileWriter(self.output_dir + "/val", sess.graph)

for epoch in range(epochs):
    for iter_train in range(iters_train):
        training_summary, loss_value, loss_cls_value, loss_vertex_value, loss_pose_value, lr, _ = sess.run(
            [training_summary_op, loss, loss_cls, loss_vertex, loss_pose, learning_rate, train_op])
        train_writer.add_summary(training_summary, iters_train * epoch + iter_train)
    losses_val = []
    for iter_val in range(iters_val):
        loss_value, loss_cls_value, loss_vertex_value, loss_pose_value, lr = sess.run(
            [loss, loss_cls, loss_vertex, loss_pose, learning_rate])
        losses_val.append(loss_val)
    validation_summary = sess.run(validation_summary_op, feed_dict={val_placeholder: np.mean(losses_val)})
    val_writer.add_summary(validation_summary, iters_train * (epoch + 1))

我和here的不同作家有这个想法。但这似乎仅在摘要相同时才有效。 如何在同一张图中绘制两个不同的摘要?

0 个答案:

没有答案