Dllab4
Dllab4
print(test_images.shape)
first_image = test_images[:1]
first_image = np.array(first_image, dtype='float')
pixels = first_image.reshape((28, 28))
plt.imshow(pixels, cmap='gray')
plt.show()
# Step 8: Plot the first 25 images from the training set with class
names
# Map class labels to corresponding digit names
class_names = ["T-shirt/top", "Trouser", "Pullover", "Dress", "Coat",
"Sandal", "Shirt", "Sneaker", "Bag", "Ankle boot"]
# Plot accuracy
plt.figure()
plt.plot(hist.history["accuracy"], label="Train Accuracy",
color="black")
plt.plot(hist.history["val_accuracy"], label="Validation Accuracy",
color="red", linestyle="dashed")
plt.title("Model Accuracy", color="darkred")
plt.xlabel("Train Accuracy")
plt.ylabel("Validation Accuracy")
plt.legend()
plt.show()
# Plot loss
plt.figure()
plt.plot(hist.history["loss"], label="Train Loss", color="black")
plt.plot(hist.history["val_loss"], label="Validation Loss",
color="red", linestyle="dashed")
plt.title("Model Loss", color="darkred")
plt.xlabel("Train Loss")
plt.ylabel("Validation Loss")
plt.legend()
plt.show()
=================================================================
Total params: 55050 (215.04 KB)
Trainable params: 55050 (215.04 KB)
Non-trainable params: 0 (0.00 Byte)
_________________________________________________________________
None
Epoch 1/5
1500/1500 [==============================] - 11s 6ms/step - loss:
0.5264 - accuracy: 0.8081 - val_loss: 0.4406 - val_accuracy: 0.8400
Epoch 2/5
1500/1500 [==============================] - 12s 8ms/step - loss:
0.3934 - accuracy: 0.8555 - val_loss: 0.4127 - val_accuracy: 0.8480
Epoch 3/5
1500/1500 [==============================] - 13s 9ms/step - loss:
0.3539 - accuracy: 0.8703 - val_loss: 0.3666 - val_accuracy: 0.8658
Epoch 4/5
1500/1500 [==============================] - 5s 3ms/step - loss:
0.3294 - accuracy: 0.8780 - val_loss: 0.3606 - val_accuracy: 0.8710
Epoch 5/5
1500/1500 [==============================] - 6s 4ms/step - loss:
0.3094 - accuracy: 0.8844 - val_loss: 0.3467 - val_accuracy: 0.8748
313/313 [==============================] - 1s 2ms/step - loss: 0.3758
- accuracy: 0.8671
1/1 [==============================] - 0s 102ms/step
[9 2 1 1 6]
(1, 784)