{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\n# import numpy as np # linear algebra\n# import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n# import os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport PIL\nimport PIL.Image\nimport tensorflow as tf\nimport pathlib\nimport matplotlib.pyplot as plt\nfrom glob import glob\nimport sys\nimport sklearn.metrics as metrics\nfrom sklearn.metrics import accuracy_score,classification_report,confusion_matrix\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:51:29.412772Z","iopub.execute_input":"2022-07-19T10:51:29.413272Z","iopub.status.idle":"2022-07-19T10:51:29.421746Z","shell.execute_reply.started":"2022-07-19T10:51:29.413241Z","shell.execute_reply":"2022-07-19T10:51:29.420196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_path = \"../input/paddy-disease-classification/train_images\"\ntesting_path = \"../input/paddy-disease-classification/test_images\"","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:26:26.689906Z","iopub.execute_input":"2022-07-19T10:26:26.690729Z","iopub.status.idle":"2022-07-19T10:26:26.696415Z","shell.execute_reply.started":"2022-07-19T10:26:26.690693Z","shell.execute_reply":"2022-07-19T10:26:26.695043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_count = len(list(pathlib.Path(training_path).glob('*/*.jpg')))\nprint(image_count)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:09:49.348108Z","iopub.execute_input":"2022-07-19T10:09:49.348506Z","iopub.status.idle":"2022-07-19T10:09:50.228037Z","shell.execute_reply.started":"2022-07-19T10:09:49.348476Z","shell.execute_reply":"2022-07-19T10:09:50.226719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data = tf.keras.utils.image_dataset_from_directory(\n    training_path,\n    validation_split = 0.1,\n    seed = 48,\n    subset='training',\n    label_mode='categorical',\n)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:09:55.680910Z","iopub.execute_input":"2022-07-19T10:09:55.681665Z","iopub.status.idle":"2022-07-19T10:10:02.841713Z","shell.execute_reply.started":"2022-07-19T10:09:55.681631Z","shell.execute_reply":"2022-07-19T10:10:02.840362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"validation_data = tf.keras.utils.image_dataset_from_directory(\n    training_path,\n    validation_split = 0.1,\n    seed = 48,\n    subset='validation',\n    label_mode='categorical',\n)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:10:02.844143Z","iopub.execute_input":"2022-07-19T10:10:02.845323Z","iopub.status.idle":"2022-07-19T10:10:04.722249Z","shell.execute_reply.started":"2022-07-19T10:10:02.845275Z","shell.execute_reply":"2022-07-19T10:10:04.720948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data.class_names","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:28:46.746104Z","iopub.execute_input":"2022-07-19T10:28:46.747722Z","iopub.status.idle":"2022-07-19T10:28:46.760611Z","shell.execute_reply.started":"2022-07-19T10:28:46.747657Z","shell.execute_reply":"2022-07-19T10:28:46.759234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Model Creation**","metadata":{}},{"cell_type":"code","source":"base_model = tf.keras.applications.inception_resnet_v2.InceptionResNetV2(\n    include_top=False, \n    weights = 'imagenet',\n    input_shape = (256, 256, 3) )","metadata":{"execution":{"iopub.status.busy":"2022-07-18T12:38:56.135008Z","iopub.execute_input":"2022-07-18T12:38:56.135395Z","iopub.status.idle":"2022-07-18T12:39:04.253282Z","shell.execute_reply.started":"2022-07-18T12:38:56.135364Z","shell.execute_reply":"2022-07-18T12:39:04.251988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model.trainable = False","metadata":{"execution":{"iopub.status.busy":"2022-07-18T12:39:06.701756Z","iopub.execute_input":"2022-07-18T12:39:06.702226Z","iopub.status.idle":"2022-07-18T12:39:06.745495Z","shell.execute_reply.started":"2022-07-18T12:39:06.702177Z","shell.execute_reply":"2022-07-18T12:39:06.744327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_augmentation = tf.keras.Sequential([\n    tf.keras.layers.RandomFlip(\"horizontal\"),\n    tf.keras.layers.RandomRotation(0.1),\n    tf.keras.layers.RandomTranslation(height_factor = 0.1, width_factor = 0.1),\n    tf.keras.layers.RandomContrast(factor = 0.1)]\n)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T12:40:25.926623Z","iopub.execute_input":"2022-07-18T12:40:25.927252Z","iopub.status.idle":"2022-07-18T12:40:25.953079Z","shell.execute_reply.started":"2022-07-18T12:40:25.927219Z","shell.execute_reply":"2022-07-18T12:40:25.951956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction_layer = tf.keras.layers.Dense(10, activation = \"softmax\")","metadata":{"execution":{"iopub.status.busy":"2022-07-18T12:40:32.657624Z","iopub.execute_input":"2022-07-18T12:40:32.658024Z","iopub.status.idle":"2022-07-18T12:40:32.664940Z","shell.execute_reply.started":"2022-07-18T12:40:32.657996Z","shell.execute_reply":"2022-07-18T12:40:32.663517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install -U keras keras-applications","metadata":{"execution":{"iopub.status.busy":"2022-07-17T01:15:01.786511Z","iopub.execute_input":"2022-07-17T01:15:01.786912Z","iopub.status.idle":"2022-07-17T01:15:01.793222Z","shell.execute_reply.started":"2022-07-17T01:15:01.786883Z","shell.execute_reply":"2022-07-17T01:15:01.791364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-07-17T01:00:47.482654Z","iopub.execute_input":"2022-07-17T01:00:47.483529Z","iopub.status.idle":"2022-07-17T01:00:47.490633Z","shell.execute_reply.started":"2022-07-17T01:00:47.483485Z","shell.execute_reply":"2022-07-17T01:00:47.489627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inputs = tf.keras.Input((256, 256, 3))\nx = data_augmentation(inputs)\n\nx = tf.keras.applications.inception_resnet_v2.preprocess_input(x)\nx = base_model(x, training = False)\nx = tf.keras.layers.Flatten()(x)\n\nx = tf.keras.layers.Dense(128, activation='relu')(x)\nx = tf.keras.layers.Dropout(0.1)(x)\nx = tf.keras.layers.BatchNormalization()(x)\n\nx = tf.keras.layers.Dense(64, activation='relu')(x)\nx = tf.keras.layers.Dropout(0.2)(x)\n\noutputs = prediction_layer(x)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T12:42:52.026982Z","iopub.execute_input":"2022-07-18T12:42:52.027428Z","iopub.status.idle":"2022-07-18T12:42:54.198936Z","shell.execute_reply.started":"2022-07-18T12:42:52.027381Z","shell.execute_reply":"2022-07-18T12:42:54.197613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.Model(inputs=inputs, outputs=outputs)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Training 1**","metadata":{}},{"cell_type":"code","source":"\nmodel.compile(\n  loss=tf.keras.losses.CategoricalCrossentropy(),\n  optimizer=tf.keras.optimizers.RMSprop(),\n  metrics=['accuracy']\n)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T12:45:08.477365Z","iopub.execute_input":"2022-07-18T12:45:08.478134Z","iopub.status.idle":"2022-07-18T12:45:08.511599Z","shell.execute_reply.started":"2022-07-18T12:45:08.478105Z","shell.execute_reply":"2022-07-18T12:45:08.510520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stop = tf.keras.callbacks.EarlyStopping(monitor='val_accuracy', patience=8, mode='auto', restore_best_weights=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T12:45:15.396238Z","iopub.execute_input":"2022-07-18T12:45:15.396794Z","iopub.status.idle":"2022-07-18T12:45:15.402809Z","shell.execute_reply.started":"2022-07-18T12:45:15.396742Z","shell.execute_reply":"2022-07-18T12:45:15.401511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# tf.config.run_functions_eagerly(True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-16T23:25:11.243140Z","iopub.execute_input":"2022-07-16T23:25:11.243954Z","iopub.status.idle":"2022-07-16T23:25:11.250339Z","shell.execute_reply.started":"2022-07-16T23:25:11.243907Z","shell.execute_reply":"2022-07-16T23:25:11.248921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_history = model.fit(training_data, validation_data = validation_data, batch_size = 32, epochs = 100, callbacks=[early_stop])","metadata":{"execution":{"iopub.status.busy":"2022-07-18T12:45:26.169226Z","iopub.execute_input":"2022-07-18T12:45:26.169594Z","iopub.status.idle":"2022-07-18T14:21:39.899691Z","shell.execute_reply.started":"2022-07-18T12:45:26.169565Z","shell.execute_reply":"2022-07-18T14:21:39.898386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save(\"resIncep.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-07-18T14:33:53.024876Z","iopub.execute_input":"2022-07-18T14:33:53.025605Z","iopub.status.idle":"2022-07-18T14:33:54.630531Z","shell.execute_reply.started":"2022-07-18T14:33:53.025574Z","shell.execute_reply":"2022-07-18T14:33:54.629293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Loading Saved Model**","metadata":{}},{"cell_type":"code","source":"loaded_model = tf.keras.models.load_model('../input/paddy-disease-premodel/resIncep.h5')","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:15:51.427728Z","iopub.execute_input":"2022-07-19T10:15:51.428262Z","iopub.status.idle":"2022-07-19T10:16:03.632879Z","shell.execute_reply.started":"2022-07-19T10:15:51.428233Z","shell.execute_reply":"2022-07-19T10:16:03.631621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loaded_model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:16:10.973566Z","iopub.execute_input":"2022-07-19T10:16:10.973973Z","iopub.status.idle":"2022-07-19T10:16:11.022176Z","shell.execute_reply.started":"2022-07-19T10:16:10.973925Z","shell.execute_reply":"2022-07-19T10:16:11.020485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Verification**","metadata":{}},{"cell_type":"code","source":"result2 = loaded_model.evaluate(training_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:43:02.061348Z","iopub.execute_input":"2022-07-19T10:43:02.061759Z","iopub.status.idle":"2022-07-19T10:44:27.892009Z","shell.execute_reply.started":"2022-07-19T10:43:02.061728Z","shell.execute_reply":"2022-07-19T10:44:27.890710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"Loss: {result2[0]}\")\nprint(f\"Accuracy: {result2[1] * 100}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:44:54.404375Z","iopub.execute_input":"2022-07-19T10:44:54.405002Z","iopub.status.idle":"2022-07-19T10:44:54.415087Z","shell.execute_reply.started":"2022-07-19T10:44:54.404954Z","shell.execute_reply":"2022-07-19T10:44:54.413704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result3 = loaded_model.evaluate(validation_data)\nprint(f\"Loss: {result3[0]}\")\nprint(f\"Accuracy: {result3[1] * 100}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:45:24.612177Z","iopub.execute_input":"2022-07-19T10:45:24.612571Z","iopub.status.idle":"2022-07-19T10:45:32.186857Z","shell.execute_reply.started":"2022-07-19T10:45:24.612540Z","shell.execute_reply":"2022-07-19T10:45:32.185369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Submission**","metadata":{}},{"cell_type":"code","source":"testing_data = tf.keras.utils.image_dataset_from_directory(\n    testing_path,\n    seed = 48,\n    labels = None,\n    shuffle = False\n)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:49:07.035247Z","iopub.execute_input":"2022-07-19T10:49:07.035679Z","iopub.status.idle":"2022-07-19T10:49:08.019699Z","shell.execute_reply.started":"2022-07-19T10:49:07.035633Z","shell.execute_reply":"2022-07-19T10:49:08.018344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = loaded_model.predict(testing_data)\npredictions.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:49:50.424869Z","iopub.execute_input":"2022-07-19T10:49:50.425882Z","iopub.status.idle":"2022-07-19T10:50:08.626408Z","shell.execute_reply.started":"2022-07-19T10:49:50.425834Z","shell.execute_reply":"2022-07-19T10:50:08.625080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss = pd.read_csv('../input/paddy-disease-classification/sample_submission.csv')\nss['label'] = np.argmax(predictions, axis=-1)\nss['label'] = ss['label'].replace([0,1,2,3,4,5,6,7,8,9], training_data.class_names)\nss.to_csv(\"Submission.csv\",index=False)\nss.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-19T10:53:07.245924Z","iopub.execute_input":"2022-07-19T10:53:07.246353Z","iopub.status.idle":"2022-07-19T10:53:07.284660Z","shell.execute_reply.started":"2022-07-19T10:53:07.246323Z","shell.execute_reply":"2022-07-19T10:53:07.283265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Training2**","metadata":{}},{"cell_type":"code","source":"\nloaded_model.compile(\n  loss=tf.keras.losses.CategoricalCrossentropy(),\n  optimizer=tf.keras.optimizers.RMSprop(learning_rate = 0.0001),\n  metrics=['accuracy']\n)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T12:18:54.503634Z","iopub.execute_input":"2022-07-19T12:18:54.504774Z","iopub.status.idle":"2022-07-19T12:18:54.552578Z","shell.execute_reply.started":"2022-07-19T12:18:54.504719Z","shell.execute_reply":"2022-07-19T12:18:54.551199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# early_stop = tf.keras.callbacks.EarlyStopping(monitor='accuracy', patience=10, min_delta = 0.001, mode='auto', restore_best_weights=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T12:56:58.976160Z","iopub.execute_input":"2022-07-19T12:56:58.976535Z","iopub.status.idle":"2022-07-19T12:56:58.984857Z","shell.execute_reply.started":"2022-07-19T12:56:58.976506Z","shell.execute_reply":"2022-07-19T12:56:58.983212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checkpoint_1 = tf.keras.callbacks.ModelCheckpoint(filepath = 'best_weights.hdf5',\n                                  save_best_only = True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-19T12:58:03.759447Z","iopub.execute_input":"2022-07-19T12:58:03.759803Z","iopub.status.idle":"2022-07-19T12:58:03.768229Z","shell.execute_reply.started":"2022-07-19T12:58:03.759774Z","shell.execute_reply":"2022-07-19T12:58:03.767061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_history = loaded_model.fit(training_data, validation_data = validation_data, batch_size = 32, epochs = 100, callbacks=[checkpoint_1, early_stop])","metadata":{"execution":{"iopub.status.busy":"2022-07-19T12:58:25.108088Z","iopub.execute_input":"2022-07-19T12:58:25.108481Z","iopub.status.idle":"2022-07-19T13:25:53.420042Z","shell.execute_reply.started":"2022-07-19T12:58:25.108436Z","shell.execute_reply":"2022-07-19T13:25:53.418666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loaded_model2 = tf.keras.models.load_model('./best_weights.hdf5')","metadata":{"execution":{"iopub.status.busy":"2022-07-19T13:34:32.358787Z","iopub.execute_input":"2022-07-19T13:34:32.360084Z","iopub.status.idle":"2022-07-19T13:34:40.677391Z","shell.execute_reply.started":"2022-07-19T13:34:32.360040Z","shell.execute_reply":"2022-07-19T13:34:40.676062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checkpoint_2 = tf.keras.callbacks.ModelCheckpoint(filepath = 'best_weights2.hdf5',\n                                  save_best_only = True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-19T13:34:43.348367Z","iopub.execute_input":"2022-07-19T13:34:43.348737Z","iopub.status.idle":"2022-07-19T13:34:43.355751Z","shell.execute_reply.started":"2022-07-19T13:34:43.348708Z","shell.execute_reply":"2022-07-19T13:34:43.354384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loaded_model2.compile(\n  loss=tf.keras.losses.CategoricalCrossentropy(),\n  optimizer=tf.keras.optimizers.RMSprop(learning_rate = 0.0001),\n  metrics=['accuracy']\n)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T13:36:07.712833Z","iopub.execute_input":"2022-07-19T13:36:07.713476Z","iopub.status.idle":"2022-07-19T13:36:07.740394Z","shell.execute_reply.started":"2022-07-19T13:36:07.713441Z","shell.execute_reply":"2022-07-19T13:36:07.738994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_history = loaded_model2.fit(training_data, validation_data = validation_data, batch_size = 32, epochs = 100, callbacks=[checkpoint_2])","metadata":{"execution":{"iopub.status.busy":"2022-07-19T13:36:09.166893Z","iopub.execute_input":"2022-07-19T13:36:09.167302Z","iopub.status.idle":"2022-07-19T15:29:40.295082Z","shell.execute_reply.started":"2022-07-19T13:36:09.167272Z","shell.execute_reply":"2022-07-19T15:29:40.293680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result4 = loaded_model2.evaluate(validation_data)\nprint(f\"Loss: {result4[0]}\")\nprint(f\"Accuracy: {result4[1] * 100}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T15:31:44.651435Z","iopub.execute_input":"2022-07-19T15:31:44.651826Z","iopub.status.idle":"2022-07-19T15:31:50.236059Z","shell.execute_reply.started":"2022-07-19T15:31:44.651787Z","shell.execute_reply":"2022-07-19T15:31:50.234816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Plotting**","metadata":{}},{"cell_type":"code","source":"#PLotting the graph between epochs loss for loss and val_loss\n\nsns.lineplot(x = range(len(model_history.history[\"loss\"])), y = model_history.history[\"loss\"], label = \"Training\")\nsns.lineplot(x = range(len(model_history.history[\"loss\"])), y = model_history.history[\"val_loss\"], label = \"Validation\")\nplt.ylabel(\"Loss\")\nplt.xlabel(\"Epochs\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:14:59.345614Z","iopub.execute_input":"2022-07-19T20:14:59.346120Z","iopub.status.idle":"2022-07-19T20:14:59.658251Z","shell.execute_reply.started":"2022-07-19T20:14:59.346072Z","shell.execute_reply":"2022-07-19T20:14:59.657026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#PLotting the graph between epochs loss for accuracy and val_accuracy\n\nsns.lineplot(x = range(len(model_history.history[\"loss\"])), y = model_history.history[\"accuracy\"], label = \"Training\")\nsns.lineplot(x = range(len(model_history.history[\"loss\"])), y = model_history.history[\"val_accuracy\"], label = \"Validation\")\nplt.ylabel(\"Loss\")\nplt.xlabel(\"Epochs\")\nplt.legend(loc = \"lower right\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:14:59.717738Z","iopub.execute_input":"2022-07-19T20:14:59.718099Z","iopub.status.idle":"2022-07-19T20:15:00.014424Z","shell.execute_reply.started":"2022-07-19T20:14:59.718069Z","shell.execute_reply":"2022-07-19T20:15:00.013067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Submission**","metadata":{}},{"cell_type":"code","source":"loaded_model3 = tf.keras.models.load_model('./best_weights2.hdf5')","metadata":{"execution":{"iopub.status.busy":"2022-07-19T15:32:37.859550Z","iopub.execute_input":"2022-07-19T15:32:37.860058Z","iopub.status.idle":"2022-07-19T15:32:46.450697Z","shell.execute_reply.started":"2022-07-19T15:32:37.859967Z","shell.execute_reply":"2022-07-19T15:32:46.449413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result5 = loaded_model3.evaluate(validation_data)\nprint(f\"Loss: {result5[0]}\")\nprint(f\"Accuracy: {result5[1] * 100}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T15:33:11.094089Z","iopub.execute_input":"2022-07-19T15:33:11.094448Z","iopub.status.idle":"2022-07-19T15:33:20.423625Z","shell.execute_reply.started":"2022-07-19T15:33:11.094419Z","shell.execute_reply":"2022-07-19T15:33:20.422413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions2 = loaded_model2.predict(testing_data)\npredictions2.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-19T15:34:13.709811Z","iopub.execute_input":"2022-07-19T15:34:13.710228Z","iopub.status.idle":"2022-07-19T15:34:31.194387Z","shell.execute_reply.started":"2022-07-19T15:34:13.710197Z","shell.execute_reply":"2022-07-19T15:34:31.193065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions3 = loaded_model3.predict(testing_data)\npredictions3.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-19T15:34:31.197063Z","iopub.execute_input":"2022-07-19T15:34:31.197766Z","iopub.status.idle":"2022-07-19T15:34:48.664359Z","shell.execute_reply.started":"2022-07-19T15:34:31.197597Z","shell.execute_reply":"2022-07-19T15:34:48.663183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss = pd.read_csv('../input/paddy-disease-classification/sample_submission.csv')\nss['label'] = np.argmax(predictions2, axis=-1)\nss['label'] = ss['label'].replace([0,1,2,3,4,5,6,7,8,9], training_data.class_names)\nss.to_csv(\"Submission2.csv\",index=False)\nss.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-19T15:35:59.915766Z","iopub.execute_input":"2022-07-19T15:35:59.916152Z","iopub.status.idle":"2022-07-19T15:35:59.952722Z","shell.execute_reply.started":"2022-07-19T15:35:59.916123Z","shell.execute_reply":"2022-07-19T15:35:59.951645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss = pd.read_csv('../input/paddy-disease-classification/sample_submission.csv')\nss['label'] = np.argmax(predictions3, axis=-1)\nss['label'] = ss['label'].replace([0,1,2,3,4,5,6,7,8,9], training_data.class_names)\nss.to_csv(\"Submission3.csv\",index=False)\nss.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-19T15:36:43.447444Z","iopub.execute_input":"2022-07-19T15:36:43.447911Z","iopub.status.idle":"2022-07-19T15:36:43.478207Z","shell.execute_reply.started":"2022-07-19T15:36:43.447882Z","shell.execute_reply":"2022-07-19T15:36:43.476799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Training3**","metadata":{}},{"cell_type":"code","source":"checkpoint_4 = tf.keras.callbacks.ModelCheckpoint(filepath = 'best_weights4.hdf5',\n                                  save_best_only = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:16:40.392976Z","iopub.execute_input":"2022-07-19T20:16:40.393496Z","iopub.status.idle":"2022-07-19T20:16:40.398968Z","shell.execute_reply.started":"2022-07-19T20:16:40.393467Z","shell.execute_reply":"2022-07-19T20:16:40.397718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nloaded_model4.compile(\n  loss=tf.keras.losses.CategoricalCrossentropy(),\n  optimizer=tf.keras.optimizers.RMSprop(learning_rate = 0.0005),\n  metrics=['accuracy']\n)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:17:04.044120Z","iopub.execute_input":"2022-07-19T20:17:04.044521Z","iopub.status.idle":"2022-07-19T20:17:04.072207Z","shell.execute_reply.started":"2022-07-19T20:17:04.044490Z","shell.execute_reply":"2022-07-19T20:17:04.070819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_history = loaded_model4.fit(training_data, validation_data = validation_data, batch_size = 32, epochs = 50, callbacks=[checkpoint_4])","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:17:25.386767Z","iopub.execute_input":"2022-07-19T20:17:25.387305Z","iopub.status.idle":"2022-07-19T21:11:34.644687Z","shell.execute_reply.started":"2022-07-19T20:17:25.387273Z","shell.execute_reply":"2022-07-19T21:11:34.643306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result5 = loaded_model3.evaluate(validation_data)\nprint(f\"Loss: {result5[0]}\")\nprint(f\"Accuracy: {result5[1] * 100}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:11:27.461211Z","iopub.execute_input":"2022-07-19T20:11:27.461688Z","iopub.status.idle":"2022-07-19T20:11:37.728775Z","shell.execute_reply.started":"2022-07-19T20:11:27.461639Z","shell.execute_reply":"2022-07-19T20:11:37.727375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# result5 = loaded_model2.evaluate(validation_data)\nprint(f\"Loss: {result4[0]}\")\nprint(f\"Accuracy: {result4[1] * 100}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:12:02.416230Z","iopub.execute_input":"2022-07-19T20:12:02.416659Z","iopub.status.idle":"2022-07-19T20:12:02.429095Z","shell.execute_reply.started":"2022-07-19T20:12:02.416625Z","shell.execute_reply":"2022-07-19T20:12:02.427644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loaded_model4 = tf.keras.models.load_model('./best_weights3.hdf5')","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:13:07.330824Z","iopub.execute_input":"2022-07-19T20:13:07.331303Z","iopub.status.idle":"2022-07-19T20:13:16.309343Z","shell.execute_reply.started":"2022-07-19T20:13:07.331245Z","shell.execute_reply":"2022-07-19T20:13:16.308067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result6 = loaded_model4.evaluate(validation_data)\nprint(f\"Loss: {result6[0]}\")\nprint(f\"Accuracy: {result6[1] * 100}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:13:47.897556Z","iopub.execute_input":"2022-07-19T20:13:47.898009Z","iopub.status.idle":"2022-07-19T20:13:57.382044Z","shell.execute_reply.started":"2022-07-19T20:13:47.897966Z","shell.execute_reply":"2022-07-19T20:13:57.380704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}