Dl Lab 7 Excuted
Dl Lab 7 Excuted
# Create a new model with the pre-trained VGG16 base and additional layers
model = Sequential([
vgg_base,
Flatten(),
Dense(256, activation='relu'),
Dense(10, activation='softmax')
])
1
plt.figure(figsize=(10, 10))
for i inrange(25):
plt.subplot(5, 5, i + 1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(test_images[i])
plt.xlabel(get_class_names()[test_labels[i][0]])
plt.show()
2
# Train the model
history = model.fit(train_images, train_labels, epochs=5, batch_size=64,
validation_data=(test_images, test_labels))
Epoch 1/5
782/782━━━━━━━━━━━━━━━━━━━━16s 15ms/step - accuracy: 0.1848 - loss:
2.2483 - val_accuracy: 0.3618 - val_loss: 1.9465
Epoch 2/5
782/782━━━━━━━━━━━━━━━━━━━━8s 11ms/step - accuracy: 0.3839 - loss:
1.8907 - val_accuracy: 0.4210 - val_loss: 1.7493
Epoch 3/5
782/782━━━━━━━━━━━━━━━━━━━━9s 12ms/step - accuracy: 0.4352 - loss:
1.7138 - val_accuracy: 0.4516 - val_loss: 1.6360
Epoch 4/5
782/782━━━━━━━━━━━━━━━━━━━━9s 10ms/step - accuracy: 0.4634 - loss:
1.6136 - val_accuracy: 0.4702 - val_loss: 1.5637
Epoch 5/5
782/782━━━━━━━━━━━━━━━━━━━━10s 11ms/step - accuracy: 0.4865 - loss:
1.5350 - val_accuracy: 0.4882 - val_loss: 1.5121
3
# Plot accuracy graph
plt.plot(history.history['accuracy'], label='Training Accuracy')
plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend()
plt.show()