如何在tf.estimator.Estimator API中获取tf.summary以在EVALUATE运行期间为张量板保存变量?

时间:2018-09-02 18:04:43

标签: tensorflow tensorboard tensorflow-estimator

我正在tf 1.9上使用tf.estimator API

我有多个输出损失,并且想在张量板上的TRAINING和EVAL步骤中记录每个单独的损失。

在model_fn内,我定义了几个tf.summary.scalar,例如:

loss1 = tf.reduce_mean(tf.keras.losses.binary_crossentropy(
            labels[label1], predictions[label1]))
tf.summary.scalar('loss1', loss1)

loss2 = tf.reduce_mean(tf.keras.losses.binary_crossentropy(
            labels[label2], predictions[label2]))
tf.summary.scalar('loss2', loss2)

combined_loss = tf.reduce_mean([loss1, loss2])

这些仅在TRAINING运行中显示在张量板上。对于EVAL运行,我只看到记录的eval_metric_ops和combined_loss,但看不到个人损失。

我尝试在model_fn内添加显式的Evaluation_hooks以按照建议的here进行tf.summary.merge_all()操作

summary_hook = tf.train.SummarySaverHook(save_steps=100,
                                    output_dir=params['model_dir'],
                                    summary_op=tf.summary.merge_all())

return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions,
                                  loss=combined_loss,
                                  train_op=train_op,
                                  eval_metric_ops=eval_metric_ops,
                                  evaluation_hooks=[summary_hook]
                                 )

结果相同,即在EVAL期间未保存tf.summary.scalar。 如何获得EVAL运行以写出tf.summary?

0 个答案:

没有答案
相关问题