This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 49 | |
plt.figure(figsize=(12,6)) | |
plt.subplot(1,2,1) | |
plot_image(i, predictions_single[0], test_labels, test_images) | |
plt.subplot(1,2,2) | |
plot_value_array(i, predictions_single[0], test_labels) | |
_ = plt.xticks(range(10), class_names, rotation=45) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
predictions_single = probability_model.predict(img) | |
# Remember that if we do "predictions = probability_model.predict(test_images)" then we get predictions for all test data" | |
print(f'Probabilty for all classes: {predictions_single}, \nBest confidence score for class: {np.argmax(predictions_single)}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add the image to a batch where it's the only member. | |
img = (np.expand_dims(img, 0)) | |
print(img.shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Grab an image from the test dataset. | |
img = test_images[49] | |
print(img.shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plot the test images from 'test_list', their predicted labels, and the true labels. | |
# Color correct predictions in green and incorrect predictions in red. | |
test_list= [16, 17, 22, 23, 24, 25, 39, 40, 41, 42, 48, 49, 50, 51] | |
num_rows = 7 | |
num_cols = 2 | |
num_images = num_rows * num_cols | |
#plt.figure(figsize=(2*2*num_cols, 2*num_rows)) | |
plt.figure(figsize=(10,14)) | |
for i in range(num_images): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 12 | |
plt.figure(figsize=(12,6)) | |
plt.subplot(1,2,1) | |
plot_image(i, predictions[i], test_labels, test_images) | |
plt.subplot(1,2,2) | |
plot_value_array(i, predictions[i], test_labels) | |
_ = plt.xticks(range(10), class_names, rotation=45) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_value_array(i, predictions_array, true_label): | |
""" | |
This method will plot the percentage confidence score of each class prediction. | |
Input: | |
i: Index of the prediction to test | |
predictions_array: Every prediction contain array of 10 number | |
true_label: Correct image labels. In case of test data they are test_labels | |
""" | |
true_label = true_label[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_image(i, predictions_array, true_label, img): | |
""" | |
This method will plot the true image and also compare the prediction with true values if matcing write the caption in green color else in red color. | |
Format is : predicted class %confidence score (true class) | |
Input: | |
i: Index of the prediction to test | |
predictions_array: Every prediction contain array of 10 number | |
true_label: Correct image labels. In case of test data they are test_labels | |
img: Test images. In case of test data they are test_images. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_labels[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np.argmax(predictions[0]) |
NewerOlder