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

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

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

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

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

获取错误预测的索引

Editing as was not clear earlier

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

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])