在使用Estimator接口评估我的张量流模型时,我想使用中值运算而不是均值 .

我在model_function中使用此操作:

if mode == tf.estimator.ModeKeys.EVAL:
    return tf.estimator.EstimatorSpec(mode=mode, loss=loss, 
   eval_metric_ops={"accuracy": tf.metrics.mean(my_tensor)})

我没有在tf.metrics包中找到替换tf.metrics.mean的中值函数 . 我可以自己计算,但eval_metric_ops需要一个(tensor,update_op)元组,我不确定应该是什么update_op . 如何自己实施此指标?

谢谢!

编辑:我还没有找到怎么做,但是在tensorflow github上讨论过它:https://github.com/tensorflow/tensorflow/issues/5837

所以我将使用这个tf.contrib.metrics.streaming_concat来返回我的eval数据集上的完整数组:

如果mode == tf.estimator.ModeKeys.EVAL:return tf.estimator.EstimatorSpec(mode = mode,loss = loss,eval_metric_ops = {“all_accuracies”:tf.contrib.metrics.streaming_concat(my_tensor)})并使用numpy来计算中位数:

evaluation = estimator.evaluate(input_fn = myinput_fn,mode = tf.estimator.ModeKeys.EVAL,steps = None)print(np.median(evaluation ['all_accuracies']))我可以得到我的最终准确度,但我赢了在张量板训练期间看到它,有关如何做的任何想法?