簡體   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