tensorflow - 为什么 tf.metric 返回零?
问题描述
我有一些这样的代码。它计算两个不同输出(控制和转向)的平均平均误差。我想定义一个结合其他两个指标的指标。
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
每个时代的每一步都为零?为什么?
解决方案
如果我使用指标,我必须提及 中使用的所有指标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,
)
推荐阅读
- printing - Hoin POS-58 热敏打印机打印效果不佳
- pine-script - 有没有办法将新策略应用于交易视图中的顶级筛选资产?
- php - Laravel 验证 - 确保 Json 列中不存在值
- python - 为什么我在 tkinter 画布中的内容没有滚动?即使我已经将滚动条链接到它?
- typescript - 传播参数中的打字稿函数通用参数
- ios - iOS 使用 Transform 时如何将 CGContextShowTextAtPoint 转换为 CTLineDraw?
- angular - Jasmine 中的测试吸气剂
- python - Getting error in Could not find a version that satisfies the requirement conda==4.8.4 while downloading package from requirement.txt?
- objective-c - Invert Objective-C @available?
- swift - cannot find "count" in scope