Subscribe to Tech with Tim
Using the Model
Now that we have trained the model it is time to actually use it! We will pick a few images from our testing data, show them on the screen and then use the model to predict what they are.
To make predictions we use our model name and .predict() passing it a list of data to predict. It is important that we understand it is used to make MULTIPLE predictions and that whatever data it is expecting mus be inside of a list. Since it is making multiple predictions it will also return to use a list of predicted values.
predictions = model.predict(test_images)
Now we will display the first 5 images and their predictions using matplotlib.
plt.figure(figsize=(5,5)) for i in range(5): plt.grid(False) plt.imshow(test_images[i], cmap=plt.cm.binary) plt.xlabel(class_names[test_labels[i]]) plt.title(class_names[np.argmax(predictions[i])]) plt.show()