source: https://www.cs.utah.edu/~cmertin/dogs+cats+redux.html
First, we need to calculate the predictions on the validation set, since we know those labels, rather than looking at the test set. In [19]:
vgg.model.load_weights(latest_weights_filename)
In [20]:
val_batches, probs = vgg.test(VAL_PATH, batch_size = batch_size)
Found 2000 images belonging to 2 classes.
In [22]:
filenames = val_batches.filenames
expected_labels = val_batches.classes # makes them 0 or 1
our_predictions = probs[:, 0]
our_labels = np.round(1 - our_predictions)
1 a few correct labels at random
correct = np.where(preds==val_labels[:,1])[0]
idx = permutation(correct)[:n_view]
plots_idx(idx, probs[idx])
2 a few incorrect labels at random
incorrect = np.where(preds!=val_labels[:,1])[0]
idx = permutation(incorrect)[:n_view]
plots_idx(idx, probs[idx])
3 the most correct labels of each class (ie those with highest probability that are correct)
correct_cats = np.where((preds==0) & (preds==val_labels[:,1]))[0]
most_correct_cats = np.argsort(probs[correct_cats])[::-1][:n_view]
plots_idx(correct_cats[most_correct_cats], probs[correct_cats][most_correct_cats])
4 the most incorrect labels of each class (ie those with highest probability that are incorrect)
incorrect_dogs = np.where((preds==1) & (preds!=val_labels[:,1]))[0]
most_incorrect_dogs = np.argsort(probs[incorrect_dogs])[:n_view]
plots_idx(incorrect_dogs[most_incorrect_dogs], 1-probs[incorrect_dogs][most_incorrect_dogs])
5 the most uncertain labels (ie those with probability closest to 0.5)
most_uncertain = np.argsort(np.abs(probs-0.5))
plots_idx(most_uncertain[:n_view], probs[most_uncertain])