{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":61938,"databundleVersionId":6698770,"sourceType":"competition"}],"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Importing Modules\n\nIn this section, we import the necessary Python modules for our dog breed identification project. These modules provide functionality for data visualization, numerical operations, data manipulation, file handling, image processing, and inline plotting.\n\n- **matplotlib.pyplot:** Used for creating visualizations and plotting graphs.\n- **numpy:** Essential for numerical operations and handling arrays.\n- **pandas:** A powerful library for data manipulation and analysis.\n- **os:** Provides a way to interact with the operating system, facilitating file and directory operations.\n- **random:** Used for generating random numbers or making random selections.\n- **cv2 (OpenCV):** A computer vision library for image processing tasks.\n- **%matplotlib inline:** A magic command in Jupyter Notebooks that enables inline plotting, ensuring that visualizations are displayed within the notebook itself.\n\nThese modules will play a crucial role in various aspects of our project, such as data exploration, preprocessing, and visualization.\n","metadata":{}},{"cell_type":"code","source":"# Importing modules\nfrom matplotlib import pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport os, random, cv2\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:34:06.201236Z","iopub.execute_input":"2023-11-24T06:34:06.201912Z","iopub.status.idle":"2023-11-24T06:34:06.696959Z","shell.execute_reply.started":"2023-11-24T06:34:06.201883Z","shell.execute_reply":"2023-11-24T06:34:06.696181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Checking Labels\n\nIn this section, we load the labels for our dog breed identification project. The labels are stored in a CSV file, and we use the `pd.read_csv` function from the Pandas library to read the data into a DataFrame.\n\n- **labels_df:** The DataFrame containing information about the dog breeds. It provides a quick overview of the dataset structure and the first few entries using the `head()` function.\n\nThis step is crucial for understanding the distribution of dog breeds in the dataset and getting insights into the data we will be working with.\n","metadata":{}},{"cell_type":"code","source":"# Let's check the labels\nlabels_df = pd.read_csv(\"/kaggle/input/dog-breed-identification-data/labels.csv\")\nlabels_df.head()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-24T06:34:54.389081Z","iopub.execute_input":"2023-11-24T06:34:54.389466Z","iopub.status.idle":"2023-11-24T06:34:54.426994Z","shell.execute_reply.started":"2023-11-24T06:34:54.389436Z","shell.execute_reply":"2023-11-24T06:34:54.426072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Encoding Labels\n\nIn this section, we encode the categorical labels of dog breeds into numerical values. This is a crucial step for preparing the data for machine learning models, as they typically require numerical inputs.\n\n- **labels_map:** A dictionary mapping each unique dog breed to a numerical label.\n- **inv_labels_map:** An inverse dictionary, mapping numerical labels back to their corresponding dog breeds.\n- **count:** A variable keeping track of the total number of unique labels.\n\nThe code iterates through the labels in the DataFrame and assigns a unique numerical label to each distinct dog breed. The resulting `labels_map` and `inv_labels_map` provide a convenient way to convert between categorical and numerical representations of the labels.\n\nUnderstanding and encoding labels is fundamental for training machine learning models on this classification task.\n","metadata":{}},{"cell_type":"code","source":"# Let's encode the labels\nlabels_map = {}\ninv_labels_map = {}\ncount = 0\nfor label in labels_df['breed']:\n  if(label in labels_map):\n    continue\n  \n  labels_map[label] = count\n  inv_labels_map[count] = label\n  \n  count = count + 1\n\nprint(\"Label Map: \", labels_map)\nprint(\"No. of Labels are: \", count)","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:35:32.008328Z","iopub.execute_input":"2023-11-24T06:35:32.009299Z","iopub.status.idle":"2023-11-24T06:35:32.021669Z","shell.execute_reply.started":"2023-11-24T06:35:32.009254Z","shell.execute_reply":"2023-11-24T06:35:32.020436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Class Distribution Analysis\n\nIn this section, we analyze the distribution of classes (dog breeds) within our dataset. Understanding the class distribution is crucial for addressing potential biases and imbalances in the data, which can impact the performance of our machine learning model.\n\n- **labels_count:** A dictionary storing the count of occurrences for each dog breed in the dataset.\n\nThe provided bar chart visualizes the distribution of dog breeds, with the x-axis representing individual breeds and the y-axis representing the frequency of each breed in the dataset. This visualization helps us identify any imbalances and informs decisions on potential strategies for handling class imbalances during model training.\n","metadata":{}},{"cell_type":"code","source":"# Let's check the distribution of the classes we have\n\nlabels_count = {}\nfor label in labels_df['breed']:\n  if(label in labels_count):\n    labels_count[label] = labels_count[label] + 1\n  else:\n    labels_count[label] = 0\nprint(labels_count)\nplt.figure(figsize=(30,10))\nplt.bar(list(labels_count.keys()), list(labels_count.values()),width=0.6)\nplt.xticks(rotation = 90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:35:50.439810Z","iopub.execute_input":"2023-11-24T06:35:50.440557Z","iopub.status.idle":"2023-11-24T06:35:51.797392Z","shell.execute_reply.started":"2023-11-24T06:35:50.440523Z","shell.execute_reply":"2023-11-24T06:35:51.796474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Exploring a Random Image\n\nIn this section, we randomly select an image from the training dataset and explore its properties.\n\n- **kaggle_train_path:** The path to the training dataset containing dog images.\n\nThe code snippet does the following:\n\n1. Uses `os.path.join` to create the full path to a randomly chosen image in the training dataset.\n2. Extracts the image ID and corresponding label from the image filename using the provided `labels_df`.\n3. Prints the label of the selected image.\n4. Loads and displays the image using Matplotlib.\n5. Prints the shape of the image, indicating its dimensions (height, width, and channels).\n6. Prints the maximum and minimum pixel values in the image.\n\nThis exploration is essential for gaining insights into the structure and characteristics of the images in our dataset.\n","metadata":{}},{"cell_type":"code","source":"kaggle_train_path = \"/kaggle/input/dog-breed-identification-data/train\"\n\n# Use os.path.join to create the full path to the image\nexample_img = random.choice(os.listdir(kaggle_train_path))\nimg_id = example_img[:-4]  # Remove the file extension to get the image ID\nimg_label = labels_df.loc[labels_df['id'] == img_id]['breed'].all()\n\n# Print the label\nprint(\"Label:\", img_label)\n\n# Load the image using the full path\nexample_img = plt.imread(os.path.join(kaggle_train_path, example_img))\n\n# Display the image\nplt.grid(False)\nplt.imshow(example_img)\n\n# Print the shape of the image\nprint(\"Shape of the image is:\", example_img.shape)\n\n# Print the maximum and minimum pixel values\nprint(\"Max:\", example_img.max(), \", Min:\", example_img.min())","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:51:55.834111Z","iopub.execute_input":"2023-11-24T06:51:55.834778Z","iopub.status.idle":"2023-11-24T06:51:56.185824Z","shell.execute_reply.started":"2023-11-24T06:51:55.834744Z","shell.execute_reply":"2023-11-24T06:51:56.184946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Initializing Training Data\n\nIn this section, we initialize empty lists `x_train` and `y_train` to store the training data.\n\n- **x_train:** An empty list to store the input images (features) for the training set.\n- **y_train:** An empty list to store the corresponding labels for the training set.\n\nThese lists will be populated with image data and labels as we process the training dataset for training our machine learning model.\n","metadata":{}},{"cell_type":"code","source":"\nx_train = []\ny_train = []","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:52:56.282431Z","iopub.execute_input":"2023-11-24T06:52:56.282790Z","iopub.status.idle":"2023-11-24T06:52:56.287608Z","shell.execute_reply.started":"2023-11-24T06:52:56.282760Z","shell.execute_reply":"2023-11-24T06:52:56.286612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data Loading and Preprocessing\n\nIn this section, we load and preprocess the training data.\n\nThe code snippet does the following:\n\n- Iterates through each row in the `labels_df` DataFrame, where `ids` represents the image ID and `label` is the corresponding dog breed.\n- Constructs the full path to the image using the image ID.\n- Reads the image using OpenCV (`cv2.imread`) and resizes it to a consistent size (224x224).\n- Initializes a target array of zeros with a length of 120 (the number of unique labels/classes).\n- Appends the resized image to the `x_train` list.\n- Encodes the target label using a one-hot encoding approach and appends it to the `y_train` list.\n\nThis process prepares the training data for use in training a machine learning model.\n","metadata":{}},{"cell_type":"code","source":"\nfor ids, label in labels_df.values:\n  img_path = \"/kaggle/input/dog-breed-identification-data/train/\"+ids+\".jpg\"\n  img = cv2.imread(img_path)\n  target = np.zeros(120)\n  x_train.append(np.array(cv2.resize(img,(224,224))))\n  target[labels_map[label]] = 1\n  y_train.append(target)","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:53:13.805189Z","iopub.execute_input":"2023-11-24T06:53:13.805896Z","iopub.status.idle":"2023-11-24T06:54:17.629666Z","shell.execute_reply.started":"2023-11-24T06:53:13.805866Z","shell.execute_reply":"2023-11-24T06:54:17.628859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Converting Lists to Numpy Arrays and Normalization\n\nIn this section, we convert the lists `x_train` and `y_train` into NumPy arrays and normalize the image data.\n\nThe code snippet does the following:\n\n- Converts `y_train` and `x_train` lists into NumPy arrays.\n- Normalizes the image data by dividing the pixel values by 255, ensuring that the values are in the range [0, 1].\n- Prints the length, shape, and data type of the resulting arrays.\n\nNormalizing the image data is a common practice in machine learning to ensure that all features have a similar scale, which can improve the training process and model convergence.\n","metadata":{}},{"cell_type":"code","source":"\n# Converting lists into numpy arrays\n# Our training set is divided by 255 to normalize the image data\n\ny_train = np.array(y_train, np.uint8)\nx_train = np.array(x_train, np.float16) / 255.\nprint(len(x_train), len(y_train), x_train.shape, y_train.shape)\nlength = len(x_train)","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:55:10.902893Z","iopub.execute_input":"2023-11-24T06:55:10.903263Z","iopub.status.idle":"2023-11-24T06:55:38.737511Z","shell.execute_reply.started":"2023-11-24T06:55:10.903237Z","shell.execute_reply":"2023-11-24T06:55:38.736485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Splitting the Dataset\n\nIn this section, we split the dataset into training, validation, and test sets.\n\nThe code snippet does the following:\n\n- Calculates the index (`test_split`) to split the dataset into a training set (80%) and a combined validation and test set (20%).\n- Prints the size of the training set plus the combined validation and test set.\n- Further splits the dataset into training, validation, and test sets.\n- Prints the sizes of the training, validation, and test sets.\n\nDividing the dataset into these sets is essential for training and evaluating the machine learning model, ensuring that it generalizes well to unseen data.\n","metadata":{}},{"cell_type":"code","source":"# Splitting the data into Training, Validation and Test set\n\ntest_split = int(length*0.8)\nprint(\"Training set + Validation set: \", test_split)\nx_train, x_test, y_train, y_test = x_train[:test_split], x_train[test_split:], y_train[:test_split], y_train[test_split:]\n\nvalid_split = int(length*0.6)\nprint(\"Training set: \", valid_split)\nx_train, x_valid, y_train, y_valid = x_train[:valid_split], x_train[valid_split:], y_train[:valid_split], y_train[valid_split:]\n\nprint(\"Validation set: \", str(test_split - valid_split))\nprint(\"Test set: \", str(length - test_split))","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:55:52.046375Z","iopub.execute_input":"2023-11-24T06:55:52.046733Z","iopub.status.idle":"2023-11-24T06:55:52.054036Z","shell.execute_reply.started":"2023-11-24T06:55:52.046704Z","shell.execute_reply":"2023-11-24T06:55:52.053033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Dataset Information\n\nIn this section, we print information about the current state of the dataset.\n\n- **length:** The number of samples in the training set.\n- **image_shape:** The shape of each image in the dataset, indicating its dimensions and channels.\n\nUnderstanding the size and shape of the dataset is crucial for configuring and building the machine learning model.\n","metadata":{}},{"cell_type":"code","source":"image_shape = x_train.shape\nlength = len(x_train)\nprint(length, image_shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:57:18.375330Z","iopub.execute_input":"2023-11-24T06:57:18.376111Z","iopub.status.idle":"2023-11-24T06:57:18.380925Z","shell.execute_reply.started":"2023-11-24T06:57:18.376080Z","shell.execute_reply":"2023-11-24T06:57:18.379918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Importing TensorFlow and Keras Modules\n\nIn this section, we import the necessary modules from TensorFlow and Keras for building and training our neural network model.\n\n- **tensorflow (tf):** The deep learning library that provides high-level abstractions for building and training models.\n- **tensorflow.keras.layers:** Various layers used to construct neural network architectures, including BatchNormalization, Conv2D, MaxPooling2D, Dense, Dropout, Flatten, Activation, and GlobalAveragePooling2D.\n- **tensorflow.python.keras:** The Keras API integrated into TensorFlow.\n- **tensorflow.keras.optimizers:** Optimizers, such as Adam, for configuring the training process.\n\nThese modules are essential for defining the architecture of our neural network model.\n","metadata":{}},{"cell_type":"code","source":"# Importing\nimport tensorflow as tf\nfrom tensorflow.keras.layers import BatchNormalization, Conv2D, MaxPooling2D, Dense, Dropout, Flatten, Activation, GlobalAveragePooling2D\nfrom tensorflow.python.keras import Model, Sequential, optimizers\nfrom tensorflow.keras.optimizers import Adam\n\n# from keras.layers import Conv2D, MaxPooling2D\n# from keras.layers import Dropout, Flatten, Dense, Activation\n# from keras.models import Sequential\n# from keras.layers.normalization import BatchNormalization","metadata":{"execution":{"iopub.status.busy":"2023-11-24T07:01:29.362509Z","iopub.execute_input":"2023-11-24T07:01:29.362903Z","iopub.status.idle":"2023-11-24T07:01:29.368928Z","shell.execute_reply.started":"2023-11-24T07:01:29.362874Z","shell.execute_reply":"2023-11-24T07:01:29.368052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## GPU Availability Check (optional)\n\nIn this section, we check whether a GPU is available for training our model using TensorFlow.\n\nThe code snippet uses `tf.test.gpu_device_name()` to check the presence of a GPU. If a GPU is available, the function will return the name of the GPU; otherwise, it will return an empty string.\n\nThis check is important for leveraging the computational power of a GPU, which can significantly accelerate the training process of deep learning models.\n","metadata":{}},{"cell_type":"code","source":"# To cross-check whether the instance is on GPU or not \ntf.test.gpu_device_name()","metadata":{"execution":{"iopub.status.busy":"2023-11-24T06:58:46.310945Z","iopub.execute_input":"2023-11-24T06:58:46.311587Z","iopub.status.idle":"2023-11-24T06:58:48.244637Z","shell.execute_reply.started":"2023-11-24T06:58:46.311552Z","shell.execute_reply":"2023-11-24T06:58:48.243530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## CNN Model Architecture\n\nIn this section, we define the architecture of our Convolutional Neural Network (CNN) model using TensorFlow and Keras.\n\n- **num_classes:** The number of classes in the classification task.\n\nThe model architecture consists of several layers:\n\n1. **Batch Normalization:** Applied to the input layer.\n2. **Convolutional Layers:** Successive layers with increasing filter sizes and depth, using the ReLU activation function.\n3. **MaxPooling Layers:** Applied after each convolutional layer to downsample the spatial dimensions.\n4. **Global Average Pooling:** Reduces the spatial dimensions to a single value per feature map.\n5. **Dense Layer:** The output layer with softmax activation, producing probabilities for each class.\n\nThe model's summary, displaying layer types, output shapes, and parameters, is printed to provide an overview of the network structure.\n","metadata":{}},{"cell_type":"code","source":"# The architecture of the CNN Model\nfrom tensorflow.keras.layers import BatchNormalization, Conv2D, MaxPooling2D, Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\n\nnum_classes = 120  # Replace 10 with the actual number of classes in your task\n\nmodel = Sequential()\nmodel.add(BatchNormalization(input_shape=(224, 224, 3)))\nmodel.add(Conv2D(filters=16, kernel_size=3, kernel_initializer='he_normal', activation='relu'))\nmodel.add(MaxPooling2D(pool_size=2))\nmodel.add(BatchNormalization())\n\nmodel.add(Conv2D(filters=32, kernel_size=3, kernel_initializer='he_normal', activation='relu'))\nmodel.add(MaxPooling2D(pool_size=2))\nmodel.add(BatchNormalization())\n\nmodel.add(Conv2D(filters=64, kernel_size=3, kernel_initializer='he_normal', activation='relu'))\nmodel.add(MaxPooling2D(pool_size=2))\nmodel.add(BatchNormalization())\n\nmodel.add(Conv2D(filters=128, kernel_size=3, kernel_initializer='he_normal', activation='relu'))\nmodel.add(MaxPooling2D(pool_size=2))\nmodel.add(BatchNormalization())\n\nmodel.add(Conv2D(filters=256, kernel_size=3, kernel_initializer='he_normal', activation='relu'))\nmodel.add(MaxPooling2D(pool_size=2))\nmodel.add(BatchNormalization())\n\nmodel.add(GlobalAveragePooling2D())\n\nmodel.add(Dense(num_classes, activation='softmax'))\n\nmodel.build(input_shape=(224, 224, 3))  # Adjust input_shape as per your actual input size\n\nmodel.summary()\n","metadata":{"execution":{"iopub.status.busy":"2023-11-24T07:01:41.444082Z","iopub.execute_input":"2023-11-24T07:01:41.444935Z","iopub.status.idle":"2023-11-24T07:01:41.657199Z","shell.execute_reply.started":"2023-11-24T07:01:41.444899Z","shell.execute_reply":"2023-11-24T07:01:41.656224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Hyperparameters Configuration\n\nIn this section, we set up hyperparameters for training our CNN model.\n\n- **batch_size:** The number of samples processed in a single batch during training.\n- **epochs:** The number of times the entire dataset is passed through the model during training.\n- **learning_rate:** The step size at which the optimizer adjusts the model weights during training.\n- **num_classes:** The number of classes in the classification task.\n\nAdjusting these hyperparameters can have a significant impact on the model's training and performance, and fine-tuning may be necessary to achieve optimal results.\n","metadata":{}},{"cell_type":"code","source":"# Setting up some hyperparameters\n\nbatch_size = 128\nepochs = 20\nlearning_rate = 0.001\nnum_classes = 120","metadata":{"execution":{"iopub.status.busy":"2023-11-24T07:01:46.971781Z","iopub.execute_input":"2023-11-24T07:01:46.972665Z","iopub.status.idle":"2023-11-24T07:01:46.976417Z","shell.execute_reply.started":"2023-11-24T07:01:46.972629Z","shell.execute_reply":"2023-11-24T07:01:46.975596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Model Training\n\nIn this section, we train the defined CNN model using the specified hyperparameters and training data.\n\n- **optimizer (Adam):** The optimization algorithm used to update the model weights during training.\n- **loss:** The loss function used for optimizing the model.\n- **metrics:** Additional metrics, such as accuracy, used for evaluating the model during training.\n\nThe `fit` method is called on the model with the training data (`x_train` and `y_train`) and validation data (`x_valid` and `y_valid`). The training progress, including the loss and accuracy on both the training and validation sets, is displayed for each epoch.\n\nAdjustments to hyperparameters and model architecture may be necessary based on the training progress and performance metrics.\n","metadata":{}},{"cell_type":"code","source":"# Training the model\nfrom tensorflow.keras.optimizers import Adam\n\nopt = Adam(learning_rate=learning_rate)\n\nmodel.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy'])\nm = model.fit(x_train, y_train, validation_data=(x_valid, y_valid),\n              batch_size=batch_size, verbose=2, epochs=epochs, shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2023-11-24T07:02:04.659231Z","iopub.execute_input":"2023-11-24T07:02:04.660117Z","iopub.status.idle":"2023-11-24T07:04:17.014295Z","shell.execute_reply.started":"2023-11-24T07:02:04.660083Z","shell.execute_reply":"2023-11-24T07:04:17.013401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Model Evaluation on Test Set\n\nIn this section, we evaluate the trained CNN model on the test set.\n\n- The `evaluate` method is used to obtain performance metrics, including loss and accuracy, on the test set (`x_test` and `y_test`).\n- The results are stored in the `scores` variable.\n- The accuracy on the test set is then printed.\n\nEvaluating the model on a separate test set helps assess its generalization performance on unseen data.\n","metadata":{}},{"cell_type":"code","source":"# Running the model on test set\n\nscores = model.evaluate(x_test, y_test, verbose = 1)\nprint(scores[1])","metadata":{"execution":{"iopub.status.busy":"2023-11-24T07:06:51.367653Z","iopub.execute_input":"2023-11-24T07:06:51.368441Z","iopub.status.idle":"2023-11-24T07:06:56.179798Z","shell.execute_reply.started":"2023-11-24T07:06:51.368403Z","shell.execute_reply":"2023-11-24T07:06:56.178781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Training Loss Visualization\n\nIn this section, we visualize the training and validation loss over epochs.\n\n- The code uses Matplotlib to plot the training loss (`loss`) and validation loss (`val_loss`) recorded during the training process.\n- The x-axis represents the epochs, while the y-axis represents the corresponding loss values.\n- The visualization provides insights into the model's convergence and helps identify potential issues such as overfitting or underfitting.\n\nAnalyzing the loss graph can guide further adjustments to the model architecture or hyperparameters for improved performance.\n","metadata":{}},{"cell_type":"code","source":"\n# Graph of loss per epoch\n\nplt.plot(m.history['loss'])\nplt.plot(m.history['val_loss'])\nplt.xlabel(\"epoch\", fontsize = \"16\")\nplt.ylabel(\"loss/validation_loss\", fontsize = \"16\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-24T07:07:16.636995Z","iopub.execute_input":"2023-11-24T07:07:16.637929Z","iopub.status.idle":"2023-11-24T07:07:16.914752Z","shell.execute_reply.started":"2023-11-24T07:07:16.637897Z","shell.execute_reply":"2023-11-24T07:07:16.913758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Training Accuracy Visualization\n\nIn this section, we visualize the training and validation accuracy over epochs.\n\n- The code uses Matplotlib to plot the training accuracy (`accuracy`) and validation accuracy (`val_accuracy`) recorded during the training process.\n- The x-axis represents the epochs, while the y-axis represents the corresponding accuracy values.\n- The visualization provides insights into the model's learning progress and its ability to generalize to unseen data.\n\nAnalyzing the accuracy graph can help in assessing the model's performance and making informed decisions for further refinement.\n","metadata":{}},{"cell_type":"code","source":"# Graph of accuracy per epoch\nplt.plot(m.history['accuracy'])  # use 'accuracy' instead of 'acc'\nplt.plot(m.history['val_accuracy'])  # use 'val_accuracy' instead of 'val_acc'\nplt.xlabel(\"epoch\", fontsize=\"16\")\nplt.ylabel(\"accuracy/validation_accuracy\", fontsize=\"16\")\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-11-24T07:08:36.595366Z","iopub.execute_input":"2023-11-24T07:08:36.595766Z","iopub.status.idle":"2023-11-24T07:08:36.849601Z","shell.execute_reply.started":"2023-11-24T07:08:36.595737Z","shell.execute_reply":"2023-11-24T07:08:36.848702Z"},"trusted":true},"execution_count":null,"outputs":[]}]}