在使用估算器评估期间保存直方图 api

Save histogram during evaluation with estimator api

是否可以在使用估算器进行评估时保存直方图 API?

我找不到解决方案,因为估算器 api 在评估期间没有写下任何摘要,我只能将标量添加到评估指标中。

您可以使用 SummarySaverHook

eval_hooks = []

eval_summary_hook = tf.train.SummarySaverHook(
                    save_steps=1,
                    output_dir='model_dir',
                    summary_op=tf.summary.histogram(logits.name, logits))

eval_hooks.append(eval_summary_hook)

return tf.estimator.EstimatorSpec(mode=mode,
                                          loss=loss,
                                          eval_metric_ops=eval_metric_ops,
                                          evaluation_hooks=evaluation_hooks
                                          )

为了那些来到这里但还没有找到解决方案的人,我将更新我使用上面的方法,稍作修改:

    summary_writer = tf.compat.v1.summary.FileWriter(
        logdir=self.model_dir + '/eval_histograms/',
        filename_suffix='.host_call')
    summary_ops = [tf.compat.v1.summary.histogram(name=k, values=v)
                   for k, v in
                   prepare_endpoints_for_summary(endpoints).items()]
    eval_hooks = [
        tf.estimator.SummarySaverHook(save_steps=1,
                                      summary_writer=summary_writer,
                                      summary_op=summary_op)
        for summary_op in summary_ops]

而且效果很好!