{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <center> 🌿 Cassava Disease Classification 🌿 </center>\n<center><img src  = \"https://media.istockphoto.com/photos/cassava-plant-tapioca-leaf-picture-id1074190342?k=6&m=1074190342&s=612x612&w=0&h=dZgP3KRT8-T9L30zvTMqHRiyatCsM1d54NwKon0Uk4g=\" height = 600 width = 600 ></center>","metadata":{}},{"cell_type":"markdown","source":"# Problem Statement\n\nThis competition is a Vision Based Classification Competition . Our task is to classify each cassava image into four disease categories or a fifth category indicating a healthy leaf. With our help, farmers may be able to quickly identify diseased plants, potentially saving their crops before they inflict irreparable damage. \n\nFor more information: https://www.kaggle.com/c/cassava-leaf-disease-classification/overview","metadata":{}},{"cell_type":"markdown","source":"# 📚 Loading Libraries 📚 ","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nfrom tensorflow.keras import layers,models\nfrom tensorflow.keras.optimizers import Adam\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.applications.densenet import DenseNet121\nimport warnings\nwarnings.simplefilter(\"ignore\")\nfrom PIL import Image\nfrom tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:43.859134Z","iopub.execute_input":"2022-02-23T07:47:43.859411Z","iopub.status.idle":"2022-02-23T07:47:48.953376Z","shell.execute_reply.started":"2022-02-23T07:47:43.859377Z","shell.execute_reply":"2022-02-23T07:47:48.952626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Importing Data","metadata":{}},{"cell_type":"code","source":"import os\nDir = '../input/cassava-leaf-disease-classification'\nos.listdir(Dir)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:48.954746Z","iopub.execute_input":"2022-02-23T07:47:48.954960Z","iopub.status.idle":"2022-02-23T07:47:48.966142Z","shell.execute_reply.started":"2022-02-23T07:47:48.954930Z","shell.execute_reply":"2022-02-23T07:47:48.965332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(os.listdir('../input/cassava-leaf-disease-classification/train_images')))","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:48.967333Z","iopub.execute_input":"2022-02-23T07:47:48.968139Z","iopub.status.idle":"2022-02-23T07:47:49.520501Z","shell.execute_reply.started":"2022-02-23T07:47:48.968103Z","shell.execute_reply":"2022-02-23T07:47:49.519776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(os.listdir('../input/cassava-leaf-disease-classification/test_images')))","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:49.522731Z","iopub.execute_input":"2022-02-23T07:47:49.523233Z","iopub.status.idle":"2022-02-23T07:47:49.533188Z","shell.execute_reply.started":"2022-02-23T07:47:49.523196Z","shell.execute_reply":"2022-02-23T07:47:49.532321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/cassava-leaf-disease-classification/train.csv')\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:49.534468Z","iopub.execute_input":"2022-02-23T07:47:49.534909Z","iopub.status.idle":"2022-02-23T07:47:49.575164Z","shell.execute_reply.started":"2022-02-23T07:47:49.534874Z","shell.execute_reply":"2022-02-23T07:47:49.574219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nsns.countplot(train_df['label'])","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:49.576706Z","iopub.execute_input":"2022-02-23T07:47:49.576991Z","iopub.status.idle":"2022-02-23T07:47:50.294802Z","shell.execute_reply.started":"2022-02-23T07:47:49.576953Z","shell.execute_reply":"2022-02-23T07:47:50.294148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see that there is imbalance in the data as we have more images of 3 category.","metadata":{}},{"cell_type":"code","source":"train_df['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:50.296121Z","iopub.execute_input":"2022-02-23T07:47:50.296374Z","iopub.status.idle":"2022-02-23T07:47:50.306798Z","shell.execute_reply.started":"2022-02-23T07:47:50.296328Z","shell.execute_reply":"2022-02-23T07:47:50.306092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.round((train_df['label'].value_counts()/len(train_df['label']))*100, 2)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:50.308313Z","iopub.execute_input":"2022-02-23T07:47:50.308790Z","iopub.status.idle":"2022-02-23T07:47:50.318453Z","shell.execute_reply.started":"2022-02-23T07:47:50.308752Z","shell.execute_reply":"2022-02-23T07:47:50.317592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_df)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:50.320077Z","iopub.execute_input":"2022-02-23T07:47:50.320369Z","iopub.status.idle":"2022-02-23T07:47:50.325209Z","shell.execute_reply.started":"2022-02-23T07:47:50.320314Z","shell.execute_reply":"2022-02-23T07:47:50.324541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nwith open('../input/cassava-leaf-disease-classification/label_num_to_disease_map.json') as file:\n    print(json.dumps(json.loads(file.read()), indent=4))","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:50.329247Z","iopub.execute_input":"2022-02-23T07:47:50.330077Z","iopub.status.idle":"2022-02-23T07:47:50.339372Z","shell.execute_reply.started":"2022-02-23T07:47:50.330039Z","shell.execute_reply":"2022-02-23T07:47:50.338399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Let's do some Exploratory Data Analysis","metadata":{}},{"cell_type":"code","source":"import cv2\nsample = train_df[train_df.label == 0].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image_id, sample.label)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/cassava-leaf-disease-classification/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:50.340495Z","iopub.execute_input":"2022-02-23T07:47:50.340840Z","iopub.status.idle":"2022-02-23T07:47:51.591720Z","shell.execute_reply.started":"2022-02-23T07:47:50.340800Z","shell.execute_reply":"2022-02-23T07:47:51.588997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Identification**:\n\nLook to see if leaves are drying and dying early. Look for angular spots on the leaves, and cut out small pieces of the leaf from the edge of the spots and place them in a drop of water. Look for bacterial streaming - the streaming appears as white streaks in the water. Look for dark brown to black streaks on the green part of the stem, and for the presence of sticky liquid. Look for browning in the vascular tissues, i.e., the water conducting tubes, after peeling the bark and splitting the stem.","metadata":{}},{"cell_type":"code","source":"sample = train_df[train_df.label == 1].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image_id, sample.label)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/cassava-leaf-disease-classification/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:51.592655Z","iopub.execute_input":"2022-02-23T07:47:51.592918Z","iopub.status.idle":"2022-02-23T07:47:52.755584Z","shell.execute_reply.started":"2022-02-23T07:47:51.592879Z","shell.execute_reply":"2022-02-23T07:47:52.751571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Identification**:\n\nLook for the yellow blotches along the veins from the midrib; these become patches as they join together. Look for occasional streaks on the stems, and dry brown root rots. Note that another virus disease, caused by Cassava mosaic virus (CMV), causes similar symptoms. However, CMV occurs on young expanding leaves, and causes leaf distortions","metadata":{}},{"cell_type":"code","source":"sample = train_df[train_df.label == 2].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image_id, sample.label)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/cassava-leaf-disease-classification/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:52.756733Z","iopub.execute_input":"2022-02-23T07:47:52.757435Z","iopub.status.idle":"2022-02-23T07:47:53.729088Z","shell.execute_reply.started":"2022-02-23T07:47:52.757399Z","shell.execute_reply":"2022-02-23T07:47:53.728489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Identification**:\n\nLook for yellow patterns on the leaves, from small dots to irregular patches of yellow and green. Look for leaf margins that are distorted. The plants may be stunted.","metadata":{}},{"cell_type":"code","source":"sample = train_df[train_df.label == 3].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (img_id, lab) in enumerate(zip(sample.image_id, sample.label)):\n    plt.subplot(3,3,ind+1)\n    image = cv2.imread(os.path.join(\"../input/cassava-leaf-disease-classification/train_images\", img_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:53.730114Z","iopub.execute_input":"2022-02-23T07:47:53.730669Z","iopub.status.idle":"2022-02-23T07:47:54.728372Z","shell.execute_reply.started":"2022-02-23T07:47:53.730630Z","shell.execute_reply":"2022-02-23T07:47:54.727732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Identification**:\n\nInfected leaves are white or pale yellow with pale green patches and will often be twisted, an unusual shape, and stunted. Cassava mosaic disease causes low yields.","metadata":{}},{"cell_type":"markdown","source":"Now let's see the **healthy leaves**.","metadata":{}},{"cell_type":"code","source":"sample = train_df[train_df.label == 4].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (img_id, lab) in enumerate(zip(sample.image_id, sample.label)):\n    plt.subplot(3,3,ind+1)\n    image = cv2.imread(os.path.join(\"../input/cassava-leaf-disease-classification/train_images\", img_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:54.729376Z","iopub.execute_input":"2022-02-23T07:47:54.729719Z","iopub.status.idle":"2022-02-23T07:47:55.757761Z","shell.execute_reply.started":"2022-02-23T07:47:54.729687Z","shell.execute_reply":"2022-02-23T07:47:55.755011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\ny_pred = [3] * len(train_df.label)\nprint(\"The baseline accuracy is {}\".format(accuracy_score(y_pred, train_df.label)))","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:55.759240Z","iopub.execute_input":"2022-02-23T07:47:55.759683Z","iopub.status.idle":"2022-02-23T07:47:55.898483Z","shell.execute_reply.started":"2022-02-23T07:47:55.759647Z","shell.execute_reply":"2022-02-23T07:47:55.897661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we saw that there are around 61% leaves of 3 category only.","metadata":{}},{"cell_type":"markdown","source":"# Model","metadata":{}},{"cell_type":"code","source":"Batch_size = 16\nimg_height, img_width = 300, 300","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:55.899985Z","iopub.execute_input":"2022-02-23T07:47:55.900257Z","iopub.status.idle":"2022-02-23T07:47:55.903872Z","shell.execute_reply.started":"2022-02-23T07:47:55.900220Z","shell.execute_reply":"2022-02-23T07:47:55.903188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['label'].dtype","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:55.905194Z","iopub.execute_input":"2022-02-23T07:47:55.905668Z","iopub.status.idle":"2022-02-23T07:47:55.914602Z","shell.execute_reply.started":"2022-02-23T07:47:55.905632Z","shell.execute_reply":"2022-02-23T07:47:55.913888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Augmentation","metadata":{}},{"cell_type":"code","source":"train_df['label'] = train_df['label'].astype('str')\ngen = ImageDataGenerator(\n    horizontal_flip = True,\n    vertical_flip = True,\n    validation_split = 0.2,\n)\n\ntrain_datagen = gen.flow_from_dataframe(\n    train_df,\n    directory = os.path.join(Dir, \"train_images\"),\n    batch_size = Batch_size,\n    target_size = (img_height, img_width),\n    subset = \"training\",\n    seed = 42,\n    x_col = \"image_id\",\n    y_col = \"label\",\n    class_mode = \"categorical\"\n)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:47:55.915749Z","iopub.execute_input":"2022-02-23T07:47:55.916492Z","iopub.status.idle":"2022-02-23T07:48:24.847662Z","shell.execute_reply.started":"2022-02-23T07:47:55.916397Z","shell.execute_reply":"2022-02-23T07:48:24.846869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 17118 training images.","metadata":{}},{"cell_type":"code","source":"val_gen = ImageDataGenerator(\n    validation_split = 0.2\n)\n\nval_datagen = val_gen.flow_from_dataframe(\n    train_df,\n    directory = os.path.join(Dir, \"train_images\"),\n    batch_size = Batch_size,\n    target_size = (img_height, img_width),\n    subset = \"validation\",\n    seed = 42,\n    x_col = \"image_id\",\n    y_col = \"label\",\n    class_mode = \"categorical\"\n)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:24.848789Z","iopub.execute_input":"2022-02-23T07:48:24.849648Z","iopub.status.idle":"2022-02-23T07:48:36.266094Z","shell.execute_reply.started":"2022-02-23T07:48:24.849606Z","shell.execute_reply":"2022-02-23T07:48:36.265356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 4279 validation images.","metadata":{}},{"cell_type":"code","source":"len(train_datagen), len(val_datagen)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:36.267377Z","iopub.execute_input":"2022-02-23T07:48:36.268072Z","iopub.status.idle":"2022-02-23T07:48:36.274253Z","shell.execute_reply.started":"2022-02-23T07:48:36.268034Z","shell.execute_reply":"2022-02-23T07:48:36.273398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Calculation**:\n\nThe length of training images is basically 21397 * 0.8 / 16 = 1070 as the generator returns the batches.\n\nSimilarly the length of validation images is 21397 * 0.2 / 16 = 268.","metadata":{}},{"cell_type":"code","source":"img, label = next(train_datagen)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:36.276635Z","iopub.execute_input":"2022-02-23T07:48:36.276954Z","iopub.status.idle":"2022-02-23T07:48:36.512997Z","shell.execute_reply.started":"2022-02-23T07:48:36.276916Z","shell.execute_reply":"2022-02-23T07:48:36.512271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"next() is used to get the next batch of images and labels.","metadata":{}},{"cell_type":"code","source":"label","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:36.514330Z","iopub.execute_input":"2022-02-23T07:48:36.514590Z","iopub.status.idle":"2022-02-23T07:48:36.521284Z","shell.execute_reply.started":"2022-02-23T07:48:36.514558Z","shell.execute_reply":"2022-02-23T07:48:36.520471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Steps_per_train = train_datagen.n / train_datagen.batch_size\nSteps_per_val = val_datagen.n / val_datagen.batch_size","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:36.522953Z","iopub.execute_input":"2022-02-23T07:48:36.523448Z","iopub.status.idle":"2022-02-23T07:48:36.528471Z","shell.execute_reply.started":"2022-02-23T07:48:36.523411Z","shell.execute_reply":"2022-02-23T07:48:36.527655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Steps_per_train, Steps_per_val","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:36.529834Z","iopub.execute_input":"2022-02-23T07:48:36.530405Z","iopub.status.idle":"2022-02-23T07:48:36.538044Z","shell.execute_reply.started":"2022-02-23T07:48:36.530284Z","shell.execute_reply":"2022-02-23T07:48:36.537392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I have tried out various models like:\n\n1. A CNN model with 3 convolution layers and the accuracy came out to be 61.65 which is near to the base accuracy only.\n2. A CNN model with 4 convolution layers and the accuracy came out to be 67.35 which is better than previous accuracy.\n3. A CNN model with 4 convolution layers with Dropout, Batch Normalization and the accuracy is 63.59.\n4. Tranfer Learning: I tried out various models like ResNet, DenseNet, VGG16, EfficientNet. Finally the maximum accuracy I got is through Efficient Net.","metadata":{}},{"cell_type":"markdown","source":"# Transfer Learning","metadata":{}},{"cell_type":"code","source":"from tensorflow.keras.applications.efficientnet import EfficientNetB3\ndef create_model():\n    model = models.Sequential()\n    model.add(EfficientNetB3(include_top = False, weights = 'imagenet',\n                             input_shape = (img_height, img_width, 3),  drop_connect_rate=0.3))\n    model.add(layers.GlobalAveragePooling2D())\n    model.add(layers.Flatten())\n    model.add(layers.Dense(256, activation = \"relu\"))\n    model.add(layers.Dropout(0.3))\n    model.add(layers.Dense(5, activation='softmax'))\n    \n    loss = tf.keras.losses.CategoricalCrossentropy(\n        label_smoothing=0.0001,\n        name='categorical_crossentropy'\n    )\n    model.compile(optimizer = Adam(lr = 1e-4),\n                  loss = loss,\n                  metrics = [\"categorical_accuracy\"])\n    return model\n\nmodel = create_model()\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:36.540231Z","iopub.execute_input":"2022-02-23T07:48:36.540823Z","iopub.status.idle":"2022-02-23T07:48:42.816266Z","shell.execute_reply.started":"2022-02-23T07:48:36.540788Z","shell.execute_reply":"2022-02-23T07:48:42.815579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.plot_model(model)","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:42.817590Z","iopub.execute_input":"2022-02-23T07:48:42.817823Z","iopub.status.idle":"2022-02-23T07:48:43.728235Z","shell.execute_reply.started":"2022-02-23T07:48:42.817790Z","shell.execute_reply":"2022-02-23T07:48:43.727493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rlronp=tf.keras.callbacks.ReduceLROnPlateau(monitor=\"val_loss\",\n                                            factor=0.2,\n                                            mode = \"min\",\n                                            min_lr=1e-6,\n                                            patience=2, \n                                            verbose=1)\n\nestop=tf.keras.callbacks.EarlyStopping(monitor=\"val_loss\", \n                                       mode= \"min\",\n                                       patience=3, \n                                       verbose=1,\n                                       restore_best_weights=True)\n\nhistory = model.fit_generator(\n    train_datagen,\n    steps_per_epoch = Steps_per_train,\n    epochs = 5,\n    validation_data = val_datagen,\n    validation_steps = Steps_per_val,\n    callbacks = [rlronp,estop]\n)\nmodel.save(\"Casava_Model\"+ \".h5\")","metadata":{"execution":{"iopub.status.busy":"2022-02-23T07:48:43.732681Z","iopub.execute_input":"2022-02-23T07:48:43.732893Z","iopub.status.idle":"2022-02-23T08:29:03.758989Z","shell.execute_reply.started":"2022-02-23T07:48:43.732868Z","shell.execute_reply":"2022-02-23T08:29:03.758263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plots between Accuracy and Loss","metadata":{}},{"cell_type":"code","source":"history.history.keys()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:29:03.760683Z","iopub.execute_input":"2022-02-23T08:29:03.761089Z","iopub.status.idle":"2022-02-23T08:29:03.774761Z","shell.execute_reply.started":"2022-02-23T08:29:03.761042Z","shell.execute_reply":"2022-02-23T08:29:03.767630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\ntrain_acc = history.history[\"categorical_accuracy\"]\nval_acc = history.history[\"val_categorical_accuracy\"]\nepochs = range(1, len(train_acc)+1)\nplt.plot(epochs, train_acc, \"bo\", label = \"Training Accuracy\")\nplt.plot(epochs, val_acc, \"b\", label = \"Validation Accuracy\")\nplt.title(\"Training and Validation Accuracy\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:29:03.776084Z","iopub.execute_input":"2022-02-23T08:29:03.777986Z","iopub.status.idle":"2022-02-23T08:29:04.123732Z","shell.execute_reply.started":"2022-02-23T08:29:03.777950Z","shell.execute_reply":"2022-02-23T08:29:04.122790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize=(8,6))\ntrain_loss = history.history[\"loss\"]\nval_loss = history.history[\"val_loss\"]\nepochs = range(1, len(train_loss)+1)\nplt.plot(epochs, train_loss, \"bo\", label = \"Training Loss\")\nplt.plot(epochs, val_loss, \"b\", label = \"Validation Loss\")\nplt.title(\"Training and Validation Loss\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-02-23T08:29:04.125133Z","iopub.execute_input":"2022-02-23T08:29:04.125399Z","iopub.status.idle":"2022-02-23T08:29:04.473386Z","shell.execute_reply.started":"2022-02-23T08:29:04.125336Z","shell.execute_reply":"2022-02-23T08:29:04.472554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"If you find my work helpful, please upvote! Open for criticism!!\n\nThank You!","metadata":{}}]}