{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":13836,"databundleVersionId":1718836,"sourceType":"competition"}],"dockerImageVersionId":30732,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <center>**Cassava Leaves Disease Detection**</center>","metadata":{}},{"cell_type":"code","source":"# Import Statements\n\n# Data Configuration and Viz library Imports\nimport numpy as np  # For numerical operations.\nimport pandas as pd # For preprocessing and dataframing.\nimport seaborn as sns # For Data vizualisatons.\nimport matplotlib.pyplot as plt # For plotting graphs and data Viz.\n\n# Keras Imports\nfrom keras.models import Model, Sequential  # https://keras.io/api/models/model/\nfrom keras.layers import Dense, Input, Dropout, GlobalAveragePooling2D, Flatten, Conv2D, BatchNormalization, Activation, MaxPooling2D # https://keras.io/api/layers/\nfrom keras.optimizers import Adam, SGD, RMSprop # https://keras.io/api/optimizers/\n\n# Scikit Learn Imports\nfrom sklearn.metrics import confusion_matrix\nfrom sklearn.utils import shuffle\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score, classification_report\n\n# Open CV Import\nimport cv2 # library of programming functions mainly aimed at real-time computer vision\n\n# Tensorflow library Imports\nimport tensorflow as tf\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras import models, layers, optimizers\nfrom tensorflow.keras.applications.efficientnet import EfficientNetB3\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array\n\n# Other Imports\nfrom tqdm import tqdm # tqdm module allows for the generation of progress bars in Python.\nimport os             # For OS related operations and read write operations in the file system.\nimport json           # For reading the JSON file which store the labels for each indices of the catagory of leaves.\nimport warnings","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-06-15T16:21:44.539243Z","iopub.execute_input":"2024-06-15T16:21:44.539662Z","iopub.status.idle":"2024-06-15T16:21:44.549565Z","shell.execute_reply.started":"2024-06-15T16:21:44.539628Z","shell.execute_reply":"2024-06-15T16:21:44.548493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"warnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.559786Z","iopub.execute_input":"2024-06-15T15:55:17.560395Z","iopub.status.idle":"2024-06-15T15:55:17.564930Z","shell.execute_reply.started":"2024-06-15T15:55:17.560365Z","shell.execute_reply":"2024-06-15T15:55:17.564119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**The above statements are used to import all necessary libraries for various tasks performed in the analysis.**","metadata":{}},{"cell_type":"markdown","source":"**After the importing of all the required libraries, we create the DataFrame which is required to train the model.**","metadata":{}},{"cell_type":"code","source":"# Defining our Working Directory for reference of access.\nworking_directory = \"/kaggle/input/cassava-leaf-disease-classification/\"","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.566021Z","iopub.execute_input":"2024-06-15T15:55:17.566266Z","iopub.status.idle":"2024-06-15T15:55:17.575213Z","shell.execute_reply.started":"2024-06-15T15:55:17.566244Z","shell.execute_reply":"2024-06-15T15:55:17.574367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Contents of our Working Directory.\n_ = os.listdir(working_directory)\nfor i in _:\n    print((i).upper())","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.577949Z","iopub.execute_input":"2024-06-15T15:55:17.578306Z","iopub.status.idle":"2024-06-15T15:55:17.586304Z","shell.execute_reply.started":"2024-06-15T15:55:17.578274Z","shell.execute_reply":"2024-06-15T15:55:17.585431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Pandas DataFrame consisting the train.csv file.\ntraining_df = pd.read_csv(working_directory+\"train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.587207Z","iopub.execute_input":"2024-06-15T15:55:17.587486Z","iopub.status.idle":"2024-06-15T15:55:17.612096Z","shell.execute_reply.started":"2024-06-15T15:55:17.587455Z","shell.execute_reply":"2024-06-15T15:55:17.610984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"First 5 Rows of the Training DataFrame: \")\ndisplay(training_df.head(5))\n\nprint(\"\\n\")\n\nprint(\"Information regarding the DataFrame: \\n\")\nprint(training_df.info())","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.613551Z","iopub.execute_input":"2024-06-15T15:55:17.614251Z","iopub.status.idle":"2024-06-15T15:55:17.637029Z","shell.execute_reply.started":"2024-06-15T15:55:17.614225Z","shell.execute_reply":"2024-06-15T15:55:17.636169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**The images are encoded with the different diseases with numbers from 0 to 4 (i.e 5 catagories) these catagories are kept in a JSON file which we use and append to our training dataset Dataframe.**","metadata":{}},{"cell_type":"code","source":"json_label_map_file = open(working_directory + \"label_num_to_disease_map.json\")\nreal_labels = json.load(json_label_map_file)\nreal_labels = {int(k):v for k,v in real_labels.items()} # This line of code creates a Python dictionary which store the mapping \n                                                        # of numbers and their output class/type.","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.638102Z","iopub.execute_input":"2024-06-15T15:55:17.638366Z","iopub.status.idle":"2024-06-15T15:55:17.645020Z","shell.execute_reply.started":"2024-06-15T15:55:17.638343Z","shell.execute_reply":"2024-06-15T15:55:17.644181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"real_labels_list = list(real_labels.values()) # Storing the names of values in case this may be required in future for reference.\nreal_labels_list","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.646168Z","iopub.execute_input":"2024-06-15T15:55:17.646433Z","iopub.status.idle":"2024-06-15T15:55:17.653592Z","shell.execute_reply.started":"2024-06-15T15:55:17.646410Z","shell.execute_reply":"2024-06-15T15:55:17.652731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"real_labels","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.654862Z","iopub.execute_input":"2024-06-15T15:55:17.655158Z","iopub.status.idle":"2024-06-15T15:55:17.666763Z","shell.execute_reply.started":"2024-06-15T15:55:17.655134Z","shell.execute_reply":"2024-06-15T15:55:17.665916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_df['class_name'] = training_df.label.map(real_labels) # This appends a new column to the DataFrame using the real_label dictionary and the label column.","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.669182Z","iopub.execute_input":"2024-06-15T15:55:17.669456Z","iopub.status.idle":"2024-06-15T15:55:17.677513Z","shell.execute_reply.started":"2024-06-15T15:55:17.669426Z","shell.execute_reply":"2024-06-15T15:55:17.676838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking the appended new DataFrame.\ntraining_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.678528Z","iopub.execute_input":"2024-06-15T15:55:17.678835Z","iopub.status.idle":"2024-06-15T15:55:17.692532Z","shell.execute_reply.started":"2024-06-15T15:55:17.678811Z","shell.execute_reply":"2024-06-15T15:55:17.691444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking the Value counts of each type of label.\ncount_of_classes = training_df['class_name'].value_counts()\nprint(count_of_classes)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.693729Z","iopub.execute_input":"2024-06-15T15:55:17.694075Z","iopub.status.idle":"2024-06-15T15:55:17.704388Z","shell.execute_reply.started":"2024-06-15T15:55:17.694043Z","shell.execute_reply":"2024-06-15T15:55:17.703403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Percentage of rows belonging to each class.\nfor i in count_of_classes:\n    print(round(i/len(training_df)*100,2))","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.705552Z","iopub.execute_input":"2024-06-15T15:55:17.705842Z","iopub.status.idle":"2024-06-15T15:55:17.716594Z","shell.execute_reply.started":"2024-06-15T15:55:17.705818Z","shell.execute_reply":"2024-06-15T15:55:17.715707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pl = sns.countplot(y=\"class_name\",data=training_df)\npl.set(xlabel =\"Image Class\", ylabel = \"Count of Images / Entries\", title ='Image Class V/S Count')","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:17.717601Z","iopub.execute_input":"2024-06-15T15:55:17.717865Z","iopub.status.idle":"2024-06-15T15:55:18.059710Z","shell.execute_reply.started":"2024-06-15T15:55:17.717841Z","shell.execute_reply":"2024-06-15T15:55:18.058507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# A snippet which shows us the sample of each class from the train_images while refering the image_id from the training_data.\n# Label : Output Class\n#  0: 'Cassava Bacterial Blight (CBB)',\n#  1: 'Cassava Brown Streak Disease (CBSD)',\n#  2: 'Cassava Green Mottle (CGM)',\n#  3: 'Cassava Mosaic Disease (CMD)',\n#  4: 'Healthy'\n\nsample = training_df[training_df.label == 1].sample(9) # Change rhe label == {} to any integer in the above map to get images from that class.\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image_id, sample.label)):\n    plt.subplot(4, 3, ind + 1)\n    image = cv2.imread(os.path.join(working_directory + \"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":"2024-06-15T15:55:18.062103Z","iopub.execute_input":"2024-06-15T15:55:18.062465Z","iopub.status.idle":"2024-06-15T15:55:19.316961Z","shell.execute_reply.started":"2024-06-15T15:55:18.062434Z","shell.execute_reply":"2024-06-15T15:55:19.315649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_new  = training_df # Storing a copy of the dataframe for potentiall future reference.","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:19.318779Z","iopub.execute_input":"2024-06-15T15:55:19.319169Z","iopub.status.idle":"2024-06-15T15:55:19.323795Z","shell.execute_reply.started":"2024-06-15T15:55:19.319139Z","shell.execute_reply":"2024-06-15T15:55:19.322786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center><h2>Logistic Regression Implementation</h2></center>","metadata":{}},{"cell_type":"code","source":"# Define image size\nimg_size = (64, 64)\n\n# Function to load and preprocess images\ndef load_and_preprocess_image(img_path):\n    img = load_img(img_path, target_size = img_size)\n    img_array = img_to_array(img)\n    img_array = img_array / 255.0  # Normalize pixel values\n    return img_array\n\n# Load images and labels\nprint(\"Images loading..\")\nX = []\ny = []\nfor idx, row in training_df.iterrows():\n    img_path = os.path.join(working_directory, 'train_images', row['image_id'])\n    img_array = load_and_preprocess_image(img_path)\n    X.append(img_array)\n    y.append(row['label'])\nprint(\"images loaded...\")\n\nprint(\"Creating X and Y...\")\nX = np.array(X)\ny = np.array(y)\nprint(\"X and Y created...\")\n\n# Flatten the images for logistic regression\nX = X.reshape(X.shape[0], -1)\n\n# Split the data\nprint(\"splitting...\")\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)\nprint(\"splitted...\")","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:55:20.461427Z","iopub.execute_input":"2024-06-15T15:55:20.461822Z","iopub.status.idle":"2024-06-15T15:57:23.306040Z","shell.execute_reply.started":"2024-06-15T15:55:20.461793Z","shell.execute_reply":"2024-06-15T15:57:23.305070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define and train the logistic regression model\nprint(\"model creation...\")\nmodel = LogisticRegression(n_jobs = -1,max_iter = 150)\nprint(\"model created...\")\nprint(\"fitting...\")\nmodel.fit(X_train, y_train)\nprint(\"fitted...\")\n\nprint(\"evaluating...\")\n# Evaluate the model\ny_pred = model.predict(X_test)\naccuracy = accuracy_score(y_test, y_pred)\nreport = classification_report(y_test, y_pred)\n\nprint(f'Accuracy: {accuracy}')\nprint('Classification Report:')\nprint(report)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:21:58.281134Z","iopub.execute_input":"2024-06-15T16:21:58.281906Z","iopub.status.idle":"2024-06-15T16:23:56.986511Z","shell.execute_reply.started":"2024-06-15T16:21:58.281870Z","shell.execute_reply":"2024-06-15T16:23:56.984967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center><h2>CNN implementation using TensorFlow & Keras</h2></center>","metadata":{}},{"cell_type":"code","source":"Batch_size = 64\nimg_height, img_width = 256, 256","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:23.308164Z","iopub.execute_input":"2024-06-15T15:57:23.308869Z","iopub.status.idle":"2024-06-15T15:57:23.312945Z","shell.execute_reply.started":"2024-06-15T15:57:23.308831Z","shell.execute_reply":"2024-06-15T15:57:23.312033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_df['label'] = training_df['label'].astype('str') \n                                                # Stores the label integer as a string.(Changes them...) because otherwise we get\n                                                # TypeError: If class_mode=\"categorical\", y_col=\"label\" column values must be type string, list or tuple.","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:23.314228Z","iopub.execute_input":"2024-06-15T15:57:23.314584Z","iopub.status.idle":"2024-06-15T15:57:23.336044Z","shell.execute_reply.started":"2024-06-15T15:57:23.314550Z","shell.execute_reply":"2024-06-15T15:57:23.335158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Training images\ntrain_gen = ImageDataGenerator(\n    horizontal_flip = True,\n    vertical_flip = True,\n    validation_split = 0.2,\n)\n\ntrain_datagen = train_gen.flow_from_dataframe(\n    training_df,\n    directory = os.path.join(working_directory, \"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":"2024-06-15T15:57:23.338187Z","iopub.execute_input":"2024-06-15T15:57:23.338452Z","iopub.status.idle":"2024-06-15T15:57:48.721134Z","shell.execute_reply.started":"2024-06-15T15:57:23.338424Z","shell.execute_reply":"2024-06-15T15:57:48.720239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Validation images\nval_gen = ImageDataGenerator(\n    validation_split = 0.2\n)\n\nval_datagen = val_gen.flow_from_dataframe(\n    training_df,\n    directory = os.path.join(working_directory, \"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":"2024-06-15T15:57:48.722452Z","iopub.execute_input":"2024-06-15T15:57:48.723310Z","iopub.status.idle":"2024-06-15T15:57:49.096631Z","shell.execute_reply.started":"2024-06-15T15:57:48.723272Z","shell.execute_reply":"2024-06-15T15:57:49.095836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"Size of/Number of images in training set : {len(train_datagen)}\\nSize of/Number of images in validation set : {len(val_datagen)}\")","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:49.097707Z","iopub.execute_input":"2024-06-15T15:57:49.097970Z","iopub.status.idle":"2024-06-15T15:57:49.102946Z","shell.execute_reply.started":"2024-06-15T15:57:49.097947Z","shell.execute_reply":"2024-06-15T15:57:49.102045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img, label = next(train_datagen)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:49.104098Z","iopub.execute_input":"2024-06-15T15:57:49.104610Z","iopub.status.idle":"2024-06-15T15:57:49.499067Z","shell.execute_reply.started":"2024-06-15T15:57:49.104581Z","shell.execute_reply":"2024-06-15T15:57:49.497919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Steps_per_train = float(train_datagen.n) / train_datagen.batch_size\nSteps_per_val = float(val_datagen.n) / val_datagen.batch_size","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:49.500534Z","iopub.execute_input":"2024-06-15T15:57:49.501000Z","iopub.status.idle":"2024-06-15T15:57:49.506645Z","shell.execute_reply.started":"2024-06-15T15:57:49.500959Z","shell.execute_reply":"2024-06-15T15:57:49.505574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Steps_per_train, Steps_per_val","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:49.507609Z","iopub.execute_input":"2024-06-15T15:57:49.507904Z","iopub.status.idle":"2024-06-15T15:57:49.519952Z","shell.execute_reply.started":"2024-06-15T15:57:49.507879Z","shell.execute_reply":"2024-06-15T15:57:49.519048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def 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    optimizer = optimizers.Adam(learning_rate=1e-4)\n    \n    model.compile(optimizer=optimizer,\n                  loss=loss,\n                  metrics=[\"categorical_accuracy\"])\n    return model\n\nmodel = create_model()\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:49.522556Z","iopub.execute_input":"2024-06-15T15:57:49.522820Z","iopub.status.idle":"2024-06-15T15:57:52.482284Z","shell.execute_reply.started":"2024-06-15T15:57:49.522797Z","shell.execute_reply":"2024-06-15T15:57:52.481267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Build the model\nmodel.build((None))","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:52.483400Z","iopub.execute_input":"2024-06-15T15:57:52.483695Z","iopub.status.idle":"2024-06-15T15:57:52.488302Z","shell.execute_reply.started":"2024-06-15T15:57:52.483668Z","shell.execute_reply":"2024-06-15T15:57:52.487210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Our EfficientNet CNN has %d layers' %len(model.layers))","metadata":{},"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(\n    train_datagen,\n    steps_per_epoch=int(Steps_per_train),\n    epochs=5,\n    verbose =1,\n    validation_data=val_datagen,\n    validation_steps=int(Steps_per_val),\n    callbacks=[rlronp, estop]\n)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T15:57:52.489728Z","iopub.execute_input":"2024-06-15T15:57:52.490130Z","iopub.status.idle":"2024-06-15T16:13:19.361735Z","shell.execute_reply.started":"2024-06-15T15:57:52.490092Z","shell.execute_reply":"2024-06-15T16:13:19.360703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_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":"2024-06-15T16:13:19.363437Z","iopub.execute_input":"2024-06-15T16:13:19.363736Z","iopub.status.idle":"2024-06-15T16:13:19.773916Z","shell.execute_reply.started":"2024-06-15T16:13:19.363710Z","shell.execute_reply":"2024-06-15T16:13:19.772855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.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":"2024-06-15T16:13:19.775470Z","iopub.execute_input":"2024-06-15T16:13:19.775878Z","iopub.status.idle":"2024-06-15T16:13:20.216800Z","shell.execute_reply.started":"2024-06-15T16:13:19.775839Z","shell.execute_reply":"2024-06-15T16:13:20.215579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Reference :  <br>https://www.kaggle.com/code/muhammadibrahimqasmi/cracking-cassava-cnns-in-disease-detection#-Load--Dataset-\n<br>https://www.kaggle.com/code/maksymshkliarevskyi/cassava-leaf-disease-best-keras-cnn/notebook\n<br>https://www.youtube.com/watch?v=R7fKjr4gtSc\n<br>https://www.kaggle.com/code/maksymshkliarevskyi/cassava-leaf-disease-best-keras-cnn/notebook#Visualization-of-CNN-intermediate-activations\n<br>https://github.com/aswintechguy/Deep-Learning-Projects/blob/main/Cassava%20Leaf%20Disease%20Detection%20-%20Pytorch%20Image%20Classification/Cassava%20Leaf%20Disease%20Detection%20-%20Pytorch%20Tutorial.ipynb***","metadata":{}}]}