繁体   English   中英

如何在测试集中找到错误的预测案例(使用 Keras 的 CNNs)

[英]How to find wrong prediction cases in test set (CNNs using Keras)

我正在使用带有 60000 个训练图像和 10000 个测试图像的 MNIST 示例。 如何找到 10000 张测试图像中的哪一张分类/预测不正确?

只需使用model.predict_classes()并将输出与真实实验室进行比较。 即:

incorrects = np.nonzero(model.predict_class(X_test).reshape((-1,)) != y_test)

获取错误预测的索引

编辑之前不清楚

要识别错误分类的图像文件,您可以使用:

fnames = test_generator.filenames ## fnames is all the filenames/samples used in testing
errors = np.where(y_pred != test_generator.classes)[0] ## misclassifications done on the test data where y_pred is the predicted values
for i in errors:
    print(fnames[i])

如果您想查看分类错误的图像,您可以尝试:

#to get an array with predictions:
predict = np.argmax(model.predict(X_val), axis=1)

#to get an array with true labels:
true_y_val = np.argmax(y_val, axis=1)

#to get an array with erros positions:~
errors = np.flatnonzero(predict != true_y_val)

#to find images wrongly classified:
for i in errors:
  plt.imshow(X_val[i])
  plt.show()
  print("Predicted label:", predict[i])
  print("True label:", true_y_val[i])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM