如果想在训练和验证时监视不同的summary,将train summary ops和val summary ops放进不同的集合中即可。
train_writer = tf.summary.FileWriter(log_dir + '/train', sess.graph)
val_writer = tf.summary.FileWriter(log_dir + '/val', sess.graph)# 假设train_loss和val_loss的计算方式不同
tf.summary.scalar("train_loss", train_loss, collections=['train'])
tf.summary.scalar("val_loss", val_loss, collections=['val'])train_summary_ops = tf.summary.merge_all('train')
val_summary_ops = tf.summary.merge_all('val')# training
...
train_summary = sess.run(train_summary_ops, feed_dict=train_dict)
train_writer.add_summary(train_summary, global_step)# validation
...
val_summary = sess.run(val_summary_ops, feed_dict=val_dict)
val_writer.add_summary(val_summary, global_step)# end
train_writer.close()
val_writer.close()