如何在 tensorflow 中查看 class 的精度细分?
How to see accuracy breakdown by class in tensorflow?
我正在尝试使用 N=26 classes 的 softmax classifier 创建一个神经网络。初步结果似乎很有希望,但我需要知道 class 的准确度细分。在 150 个 epoch 之后,测试准确率为 71.1%,但这是 26 classes 的总和。我确定有些 classes 做得很好,有些做得很差,我需要知道每个 class.
的准确度
我已经花了 天 搜索但无法弄清楚如何得到它。这似乎是某人需要的基本、简单、明显的东西,所以我怀疑我只是遗漏了一些东西。
我尝试了 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 是张量。我一直找不到将它转换为数组或向量的方法,甚至无法打印它的内容。
如何查看 class 的准确度细分? (如果我的意思不是很明显,当 71% 是整体准确度时,我希望它告诉我,例如:class 1 = 82%,...,class N = 13%.)
假设您满足于在训练后而不是在训练期间找到 class 级的准确性,您可以简单地 predict
模型在测试集上的输出并通过以下方式自行检查准确性,例如,将 26 个 class 中的每一个的命中和未命中存储在一个数组中。
如果您愿意,也可以使用tf.math.confusion_matrix
。这将计算出比您正在寻找的更多的信息(它以一种简洁的方式对所有错误class化验进行分类),然后您可以处理这些信息以生成百分比。
我正在尝试使用 N=26 classes 的 softmax classifier 创建一个神经网络。初步结果似乎很有希望,但我需要知道 class 的准确度细分。在 150 个 epoch 之后,测试准确率为 71.1%,但这是 26 classes 的总和。我确定有些 classes 做得很好,有些做得很差,我需要知道每个 class.
的准确度我已经花了 天 搜索但无法弄清楚如何得到它。这似乎是某人需要的基本、简单、明显的东西,所以我怀疑我只是遗漏了一些东西。
我尝试了 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 是张量。我一直找不到将它转换为数组或向量的方法,甚至无法打印它的内容。
如何查看 class 的准确度细分? (如果我的意思不是很明显,当 71% 是整体准确度时,我希望它告诉我,例如:class 1 = 82%,...,class N = 13%.)
假设您满足于在训练后而不是在训练期间找到 class 级的准确性,您可以简单地 predict
模型在测试集上的输出并通过以下方式自行检查准确性,例如,将 26 个 class 中的每一个的命中和未命中存储在一个数组中。
如果您愿意,也可以使用tf.math.confusion_matrix
。这将计算出比您正在寻找的更多的信息(它以一种简洁的方式对所有错误class化验进行分类),然后您可以处理这些信息以生成百分比。