tensorflow-tf.estimator.Estimator在EVAL模式下的每一步将张量值写入张量板

时间:2018-11-23 17:30:46

标签: python tensorflow tensorboard tensorflow-estimator

我想在每次进入tensorboard的求值步骤之后写一个张量值。训练结束后,我会一次致电estimator.evaluate(..., steps=3000),并涵盖整个测试集的步数。

我尝试过:

tf.summary.scalar("mean", mean)
tf.summary.scalar("standard_deviation", standard_deviation)
summary_hook = tf.train.SummarySaverHook(
        save_steps=1,
        output_dir=self.output_dir + "/eval",
        summary_op=tf.summary.merge_all()
    )
return tf.estimator.EstimatorSpec(mode=mode, loss=loss, evaluation_hooks=[summary_hook])

mean, mean_op = tf.metrics.mean(mean)
standard_deviation, standard_deviation_op = tf.metrics.mean(standard_deviation)
metrics = {
        'mean': (mean, mean_op),
        'standard_deviation': (standard_deviation, standard_deviation_op),
}
return tf.estimator.EstimatorSpec(mode=mode, loss=loss, eval_metric_ops=metrics)

这两种方法都是在每次model_fn调用中写一次在我的evaluate()中声明的摘要,以进行最终的全局training_step。

但是,我想为每个步骤写点。估算器API中是否可能? eval_metric_opstf.train.SummarySaverHook似乎都无法获得此结果。

0 个答案:

没有答案