Skip to content

Instantly share code, notes, and snippets.

@AyishaR
Created March 6, 2021 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AyishaR/1a99094ffaccbdedac6da09a9feaf3b8 to your computer and use it in GitHub Desktop.
Save AyishaR/1a99094ffaccbdedac6da09a9feaf3b8 to your computer and use it in GitHub Desktop.
# pick random test data sample from one batch
x = random.randint(0, 41) # test set has 42 samples
for i in test_ds.as_numpy_iterator():
img, label = i
plt.axis('off') # remove axes
#print(img.shape, x)
plt.imshow(img[x]) # shape from (64, 256, 256, 3) --> (256, 256, 3)
output = model.predict(np.expand_dims(img[x],0)) # getting output; input shape (256, 256, 3) --> (1, 256, 256, 3)
pred = np.argmax(output[0]) # finding max
print("Prdicted: ", class_names[pred]) # Picking the label from class_names base don the model output
print("True: ", class_names[np.argmax(label[x])])
print("Probability: ", output[0][pred])
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment