Advertisement
Guest User

Untitled

a guest
Sep 19th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. from matplotlib import pyplot as plt
  2. import numpy as np
  3.  
  4. # Assuming x_test has shape (num_samples, 28, 28)
  5. index_to_predict = 13
  6. image_to_predict = x_test[index_to_predict]
  7.  
  8. input_image = np.array(x_test[index_to_predict], dtype='float')
  9. pixels = input_image.reshape((28, 28))
  10. plt.imshow(pixels, cmap='gray')
  11. plt.show()
  12.  
  13. print("Seeing if we can predict that it's " + str(y_test[index_to_predict]))
  14.  
  15. # Reshape the image to match the model's input shape
  16. image_to_predict = tf.reshape(image_to_predict, (1, 28, 28))
  17.  
  18. # Get the prediction using the probability_model
  19. predictions = probability_model.predict(image_to_predict)
  20.  
  21. # The predictions will be a probability distribution over classes.
  22. # You can extract the class with the highest probability using argmax.
  23. predicted_class = tf.argmax(predictions[0]).numpy()
  24.  
  25. print("Predicted Class:", predicted_class)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement