【发布时间】:2018-03-01 18:28:45
【问题描述】:
我在使用 Tensorflow 和 Experimenter API 进行模型评估时遇到了一些麻烦。
我以前使用 2-classes NN 工作,但这次我设法训练了 4-classes 神经网络,我需要弄清楚在这种情况下如何构建混淆矩阵。我尝试使用tf.confusion_matrix 函数,但它根本不起作用。
这是我使用的代码片段:
if mode == ModeKeys.EVAL:
eval_metric_ops = {
'accuracy' : metrics.streaming_accuracy(predictions=predicted_classes, labels=labels),
# Other metrics...
'confusion_matrix': tf.confusion_matrix(prediction=predicted_classes, label=labels, num_classes=4)
}
return tf.estimator.EstimatorSpec(
mode=mode,
predictions=predicted_classes,
loss=loss,
eval_metric_ops=eval_metric_ops
)
这是我得到的错误:
TypeError: Values of eval_metric_ops must be (metric_value, update_op) tuples, given: (<tf.Operation 'test/group_deps' type=NoOp>, <tf.Tensor 'test/accuracy/value:0' shape=() dtype=float32>, <tf.Variable 'test/confusion:0' shape=(4, 4) dtype=int32_ref>) for key: confusion_matrix
我阅读了有关在 Tensorflow 中创建混淆矩阵的其他答案,并且我了解如何执行此操作,但我认为我的问题与 Estimator/Experimenter API 更相关。
【问题讨论】:
-
我也有同样的问题!
标签: python tensorflow neural-network confusion-matrix