【问题标题】:How to see accuracy breakdown by class in tensorflow?如何在张量流中按类别查看准确度细分?
【发布时间】:2019-12-31 19:05:48
【问题描述】:

我正在尝试使用具有 N=26 个类的 softmax 分类器创建神经网络。初步结果似乎很有希望,但我需要知道按类别划分的准确性。在 150 个 epoch 之后,测试准确率为 71.1%,但这是 26 个类的总数。我确信有些课程做得很好,有些课程做得很差,我需要知道每个课程的准确度和准确度。

我已经花了 搜索,但不知道如何得到它。这似乎是某人需要的基本、简单、显而易见的东西,所以我怀疑我只是遗漏了一些东西。

我试过print(tf.print(tf.compat.v1.metrics.mean_per_class_accuracy(labels, logits, n)))但得到了

name: "PrintV2"
op: "PrintV2"
input: "StringFormat"
attr {
  key: "end"
  value {
    s: "\n"
  }
}
attr {
  key: "output_stream"
  value {
    s: "stderr"
  }
}

我尝试删除 tf.print 并尝试print(tf.compat.v1.metrics.mean_per_class_accuracy(labels, logits, n)),但得到了(<tf.Tensor 'mean_accuracy/mean_accuracy:0' shape=() dtype=float32>, <tf.Tensor 'mean_accuracy/update_op:0' shape=(27,) dtype=float32>)。从技术上讲,它们都不是错误,但它们也没有告诉我我需要知道什么。

我还尝试了print(classification_report(labels, logits))print(classification_report(labels, tf.argmax(logits))),它们都给了我错误TypeError: object of type 'Tensor' has no len()。 Logits 是张量。我一直无法找到将其转换为数组或向量的方法,甚至无法打印它的内容。

如何查看按类别划分的准确率? (如果我的意思不是很明显,当 71% 是整体准确率时,我希望它告诉我,例如:1 类 = 82%,...,N 类 = 13%。)

【问题讨论】:

    标签: python tensorflow softmax


    【解决方案1】:

    假设您满足于在训练之后而不是在训练期间找到类级别的准确度,您可以简单地 predict 您的模型在测试集上的输出并自己检查准确度,例如,存储每个命中和未命中数组中的 26 个类。

    如果您愿意,也可以使用tf.math.confusion_matrix。这将计算出比您想要的更多的信息(它以一种简洁的方式对所有错误分类进行分类),然后您可以处理这些信息以生成百分比。

    【讨论】:

      猜你喜欢
      • 2019-12-28
      • 2021-06-01
      • 2022-12-10
      • 2017-04-14
      • 2021-04-16
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 2020-11-10
      相关资源
      最近更新 更多