Image Classification: Keras
Image Classification: Keras
Image Classification: Keras
• Each image is mapped to a single label. Since the class names are not included
with the dataset, store them here to use later when plotting the images:
• Explore the data:
– Let's explore the format of the dataset before training the model. The
following shows there are 60,000 images in the training set, with each image
represented as 28 x 28 pixels:
– There are 10,000 images in the test set. Again, each image is represented as
28 x 28 pixels:
• It turns out that the accuracy on the test dataset is a little less than the
accuracy on the training dataset.
• This gap between training accuracy and test accuracy represents
overfitting.
• Overfitting happens when a machine learning model performs worse on
new, previously unseen inputs than it does on the training data.
• An overfitted model "memorizes" the noise and details in the training
dataset to a point where it negatively impacts the performance of the
model on the new data.
Make predictions
• With the model trained, you can use it to make predictions about some
images.
• The model's linear outputs, logits. Attach a softmax layer to convert the
logits to probabilities, which are easier to interpret.
• Here, the model has predicted the label for each image in the testing set.
Let's take a look at the first prediction:
• A prediction is an array of 10 numbers. They represent the model's
"confidence" that the image corresponds to each of the 10 different
articles of clothing. You can see which label has the highest confidence
value:
• So, the model is most confident that this image is an ankle boot, or
class_names[9]. Examining the test label shows that this classification is
correct:
Graph this to look at the full set of 10 class predictions.
Verify predictions
• With the model trained, you can use it to make predictions about some
images.
• Let's look at the 0th image, predictions, and prediction array. Correct
prediction labels are blue and incorrect prediction labels are red. The
number gives the percentage (out of 100) for the predicted label
Use the trained model
• Finally, use the trained model to make a prediction about a
single image.