1. 程式人生 > >tensorflow在訓練和驗證時監視不同的summary的操作

tensorflow在訓練和驗證時監視不同的summary的操作

write scalar all glob sca val rain 不同 valid

如果想在訓練和驗證時監視不同的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()

tensorflow在訓練和驗證時監視不同的summary的操作