【问题标题】:Why does tf.metric return zero?为什么 tf.metric 返回零?
【发布时间】:2018-12-05 10:18:13
【问题描述】:

我有一些这样的代码。 它计算两个不同输出(controlsteer)的平均平均误差。我想定义一个结合其他两个指标的指标。

import tensorflow as tf

lambda_speed = 0.05

control_mae = tf.metrics.mean_absolute_error(ground_truth_control, predictions_control, weights=weights)
speed_mae = tf.metrics.mean_absolute_error(ground_truth_speed, prediction_speed, name='speed_loss')

mae_total = ((1 - lambda_speed) * nonspeed_mae[0] + lambda_speed * speed_mae[0],
             tf.no_op())

eval_metric_ops = {
    "mae_total": mae_total,
}
tf.estimator.EstimatorSpec(
    mode, predictions=predictions, loss=total_loss, train_op=train_op, eval_metric_ops=eval_metric_ops,
)

在调试时,我检查了数据和预测是否正常。 可悲的是,我得到一个mae_total,每个时代的每一步都为零?为什么?

【问题讨论】:

    标签: tensorflow deep-learning metrics tensorflow-estimator


    【解决方案1】:

    如果我使用指标,我必须提及 eval_metrics_ops 中使用的所有指标,否则它们将不会由 tf.estimator 运行。像这样:

    import tensorflow as tf
    
    lambda_speed = 0.05
    
    control_mae = tf.metrics.mean_absolute_error(ground_truth_control, predictions_control, weights=weights)
    speed_mae = tf.metrics.mean_absolute_error(ground_truth_speed, prediction_speed, name='speed_loss')
    
    mae_total = ((1 - lambda_speed) * nonspeed_mae[0] + lambda_speed * speed_mae[0],
                 tf.no_op())
    
    eval_metric_ops = {
        "control_mae": control_mae,
        "speed_mae": speed_mae,
        "mae_total": mae_total,
    }
    tf.estimator.EstimatorSpec(
        mode, predictions=predictions, loss=total_loss, train_op=train_op, eval_metric_ops=eval_metric_ops,
    )
    

    【讨论】:

      猜你喜欢
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-08
      • 1970-01-01
      相关资源
      最近更新 更多