【问题标题】:Tensorflow accuracy evaluation gives different results when measuring each class separately分别测量每个类别时,Tensorflow 准确度评估会给出不同的结果
【发布时间】:2017-04-08 23:09:36
【问题描述】:

我正在评估我在 tensorflow 中的神经网络模型的结果(识别 CIFAR10 图像)。 在每个时代之后,我都会像这样在测试集上打印精度(x 是图像,y 是真实标签):

predict = tf.equal(tf.argmax(layer_model, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(predict, "float"))

print("Accuracy: ", accuracy.eval({ x: test_images, y: test_labels)

但是,我正在尝试为每类图像分别获得准确度结果:

# test_labels look like: [0,1,0,...,0], [0,0,0,1,...,0], ...
labels_classes = np.argwhere(test_labels == 1)

chosen_class = np.argwhere(labels_classes[:,1] == j)
chosen_class = chosen_class.reshape(chosen.shape[0])
class_images = test_images[chosen]
class_labels = test_labels[chosen]
accuracy.eval({x: class_images, y: class_labels)

第二种方式的打印精度平均会降低 10% 左右的结果。谁能告诉我这里发生了什么?

【问题讨论】:

    标签: tensorflow average conv-neural-network evaluation


    【解决方案1】:

    您可以使用tf.metrics.mean_per_class_accuracy(labels,predictions,num_classes)

    哪些标签是您的基本事实标签,哪些预测是您的预测结果。标签和预测的形状应为 [batch size] 并输入 int32 或 int64。

    【讨论】:

      猜你喜欢
      • 2020-01-10
      • 2021-09-11
      • 1970-01-01
      • 2021-04-16
      • 2017-12-20
      • 2018-09-22
      • 2019-05-17
      • 1970-01-01
      • 2018-05-11
      相关资源
      最近更新 更多