I'm using MNIST example with 60000 training image and 10000 testing image. How do I find which of the 10000 testing image that has an incorrect classification/prediction?
Simply use model.predict_classes()
and compare the output with true labes. ie:
incorrects = np.nonzero(model.predict_class(X_test).reshape((-1,)) != y_test)
to get indices of incorrect predictions
Editing as was not clear earlier
To identify the image files that are wrongly classified, you can use:
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])
If you want to see images inclorrectly classified you can try:
#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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.