{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8b143f02-e947-4683-ad23-d6b49525851f", "metadata": {}, "outputs": [], "source": [ "import os\n", "import numpy as np\n", "import seaborn as sns\n", "from keras.preprocessing.image import load_img, img_to_array\n", "from sklearn.metrics import accuracy_score, confusion_matrix" ] }, { "cell_type": "markdown", "id": "e5e9229c-2dca-478d-95b8-65c051e8970f", "metadata": {}, "source": [ "
Original pixel value:
\n",
" [120, 200, 255]
\n",
"Normalized pixel value (using rescale = 1/255):
\n",
" 120/255, 200/255, 255/255 = 0.47, 0.78, 1.0
Let's do that here:
\n", "\n", "Layers to add:
\n", "Early Stopping stops training when the model’s performance reaches a certain level or stops improving. The Early Stopping callback monitors a specific metric (like validation accuracy) during training and stops the training process if that metric stops improving for a specified number of epochs.
\n", "You specify:
\n", " The model.fit method is used to train a model on a dataset; it takes in data (often with labels) and adjusts the model's parameters to learn patterns in that data. It then goes through several training cycles (epochs), refining its understanding to make better predictions.
This method returns a History object that contains details about the training process for each epoch (Loss values for the training data, metric values (like accuracy) for the training data, validation loss and validation metrics if a validation set was provided).\n",
"This information is saved in .history.history' as a dictionary that can be used to visualize or analyze how the model performed during training.
We're going to plot 2 graphs: 1 for accuracy and 1 for loss.
" ] }, { "cell_type": "code", "execution_count": null, "id": "c79bac75-9bd3-4c18-9713-bef43c6971b4", "metadata": {}, "outputs": [], "source": [ "# Plot training & validation accuracy values\n", "plt.plot(history.history['accuracy'], label='Training Accuracy')\n", "plt.plot(history.history['val_accuracy'], label='Validation Accuracy')\n", "plt.title('Accuracy')\n", "plt.xlabel('Epoch')\n", "plt.ylabel('Accuracy')\n", "# Setting loc='best' tells Matplotlib to automatically place the legend in the location where it doesn't overlap with any\n", "# data points, aiming for the clearest layout.\n", "plt.legend(loc='best') \n", "plt.show()\n", "\n", "# Plot training & validation loss values\n", "plt.plot(history.history['loss'], label='Training Loss')\n", "plt.plot(history.history['val_loss'], label='Validation Loss')\n", "plt.title('Loss')\n", "plt.xlabel('Epoch')\n", "plt.ylabel('Loss')\n", "plt.legend(loc='best')\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "66971c3a-7bf3-4abc-a84e-b521f698bf3f", "metadata": {}, "source": [ "