我有一些这样的代码。 它计算两个不同输出( control 和 steer )的平均平均误差。我想定义一个结合其他两个指标的指标。
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
,每个时期的每个步骤都为零?为什么?
答案 0 :(得分:0)
如果使用指标,则必须提及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,
)