Created
August 5, 2022 00:44
-
-
Save naiborhujosua/db3d0d07a17e7d4a6774a0ab3c4bf008 to your computer and use it in GitHub Desktop.
ground truth predicted
This file contains hidden or 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
# Make preds on a series of random images | |
import os | |
import random | |
plt.figure(figsize=(20, 14)) | |
for i in range(3): | |
# Choose a random image from a random class | |
class_name = random.choice(class_names) | |
filename = random.choice(os.listdir(test_dir + "/" + class_name)) | |
filepath = test_dir + class_name + "/" + filename | |
# Load the image and make predictions | |
img = load_and_prep_images(filepath, scale=False) # don't scale images for EfficientNet predictions | |
pred_prob = model_3.predict(tf.expand_dims(img, axis=0)) # model accepts tensors of shape [None, 224, 224, 3] | |
pred_class = class_names[pred_prob.argmax()] # find the predicted class | |
# Plot the image(s) | |
plt.subplot(1, 3, i+1) | |
plt.imshow(img/255.) | |
if class_name == pred_class: # Change the color of text based on whether prediction is right or wrong | |
title_color = "g" | |
else: | |
title_color = "r" | |
plt.title(f"actual: {class_name}, pred: {pred_class}, prob: {pred_prob.max():.2f}", c=title_color) | |
plt.axis(False); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment