{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":3649,"databundleVersionId":46718,"isSourceIdPinned":false,"sourceType":"competition"}],"dockerImageVersionId":30919,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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\nimport numpy as np # linear algebra\nimport 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\nimport os\nfor 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":{"iopub.status.busy":"2025-02-25T08:08:05.503739Z","iopub.execute_input":"2025-02-25T08:08:05.503924Z","iopub.status.idle":"2025-02-25T08:08:06.501655Z","shell.execute_reply.started":"2025-02-25T08:08:05.503905Z","shell.execute_reply":"2025-02-25T08:08:06.500982Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pip install py7zr","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:08:06.502415Z","iopub.execute_input":"2025-02-25T08:08:06.502839Z","iopub.status.idle":"2025-02-25T08:08:12.219560Z","shell.execute_reply.started":"2025-02-25T08:08:06.502807Z","shell.execute_reply":"2025-02-25T08:08:12.218638Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import py7zr\n\n\narchive =py7zr.SevenZipFile(\"/kaggle/input/cifar-10/train.7z\",mode='r')\narchive.extractall()\narchive.close()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:08:12.222906Z","iopub.execute_input":"2025-02-25T08:08:12.223164Z","iopub.status.idle":"2025-02-25T08:08:34.507493Z","shell.execute_reply.started":"2025-02-25T08:08:12.223142Z","shell.execute_reply":"2025-02-25T08:08:34.506784Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Importing Dependencies**","metadata":{}},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nfrom PIL import Image\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nfrom sklearn.model_selection import train_test_split","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:08:34.508659Z","iopub.execute_input":"2025-02-25T08:08:34.508950Z","iopub.status.idle":"2025-02-25T08:08:35.640551Z","shell.execute_reply.started":"2025-02-25T08:08:34.508923Z","shell.execute_reply":"2025-02-25T08:08:35.639688Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"filenames=os.listdir(\"/kaggle/working/train\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:08:57.719670Z","iopub.execute_input":"2025-02-25T08:08:57.720186Z","iopub.status.idle":"2025-02-25T08:08:57.747218Z","shell.execute_reply.started":"2025-02-25T08:08:57.720156Z","shell.execute_reply":"2025-02-25T08:08:57.746294Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"type(filenames)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:08:58.548446Z","iopub.execute_input":"2025-02-25T08:08:58.548669Z","iopub.status.idle":"2025-02-25T08:08:58.553690Z","shell.execute_reply.started":"2025-02-25T08:08:58.548650Z","shell.execute_reply":"2025-02-25T08:08:58.553104Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(filenames)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:08:59.129484Z","iopub.execute_input":"2025-02-25T08:08:59.129692Z","iopub.status.idle":"2025-02-25T08:08:59.134171Z","shell.execute_reply.started":"2025-02-25T08:08:59.129675Z","shell.execute_reply":"2025-02-25T08:08:59.133410Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(filenames[0:5])\nprint(filenames[-5:])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:00.664268Z","iopub.execute_input":"2025-02-25T08:09:00.664577Z","iopub.status.idle":"2025-02-25T08:09:00.668687Z","shell.execute_reply.started":"2025-02-25T08:09:00.664551Z","shell.execute_reply":"2025-02-25T08:09:00.667824Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Labels Processing","metadata":{}},{"cell_type":"code","source":"labeled_df =pd.read_csv(\"/kaggle/input/cifar-10/trainLabels.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:02.834350Z","iopub.execute_input":"2025-02-25T08:09:02.834599Z","iopub.status.idle":"2025-02-25T08:09:02.867052Z","shell.execute_reply.started":"2025-02-25T08:09:02.834579Z","shell.execute_reply":"2025-02-25T08:09:02.866378Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labeled_df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:03.885054Z","iopub.execute_input":"2025-02-25T08:09:03.885284Z","iopub.status.idle":"2025-02-25T08:09:03.890276Z","shell.execute_reply.started":"2025-02-25T08:09:03.885264Z","shell.execute_reply":"2025-02-25T08:09:03.889457Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labeled_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:04.836011Z","iopub.execute_input":"2025-02-25T08:09:04.836236Z","iopub.status.idle":"2025-02-25T08:09:04.855111Z","shell.execute_reply.started":"2025-02-25T08:09:04.836216Z","shell.execute_reply":"2025-02-25T08:09:04.854465Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labeled_df[labeled_df['id']==7796]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:05.817527Z","iopub.execute_input":"2025-02-25T08:09:05.817763Z","iopub.status.idle":"2025-02-25T08:09:05.829366Z","shell.execute_reply.started":"2025-02-25T08:09:05.817742Z","shell.execute_reply":"2025-02-25T08:09:05.828557Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labeled_df.tail(10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:07.458774Z","iopub.execute_input":"2025-02-25T08:09:07.459097Z","iopub.status.idle":"2025-02-25T08:09:07.466239Z","shell.execute_reply.started":"2025-02-25T08:09:07.459069Z","shell.execute_reply":"2025-02-25T08:09:07.465542Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labeled_df['label'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:07.774672Z","iopub.execute_input":"2025-02-25T08:09:07.774880Z","iopub.status.idle":"2025-02-25T08:09:07.787013Z","shell.execute_reply.started":"2025-02-25T08:09:07.774861Z","shell.execute_reply":"2025-02-25T08:09:07.786184Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"***Manually Encoding***","metadata":{}},{"cell_type":"code","source":"labeled_dictionary = {'airplane':0, 'automobile':1, 'bird':2, 'cat':3, 'deer':4, 'dog':5, 'frog':6, 'horse':7, 'ship':8, 'truck':9}\n\nlabels = [labeled_dictionary[i] for i in labeled_df['label']]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:09.460413Z","iopub.execute_input":"2025-02-25T08:09:09.460663Z","iopub.status.idle":"2025-02-25T08:09:09.471048Z","shell.execute_reply.started":"2025-02-25T08:09:09.460640Z","shell.execute_reply":"2025-02-25T08:09:09.470326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels[0:5]\nlabels[-5:]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:10.654683Z","iopub.execute_input":"2025-02-25T08:09:10.654945Z","iopub.status.idle":"2025-02-25T08:09:10.659636Z","shell.execute_reply.started":"2025-02-25T08:09:10.654923Z","shell.execute_reply":"2025-02-25T08:09:10.658954Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Displaying Sample images**","metadata":{}},{"cell_type":"code","source":"import cv2\nimport matplotlib.pyplot as plt\n\n# Load image\nimg = cv2.imread('/kaggle/working/train/7756.png')\n\n# Check if the image is loaded correctly\nif img is None:\n    print(\"Image not found or the path is incorrect.\")\nelse:\n    # Convert BGR to RGB\n    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n    # Display the image\n    plt.imshow(img_rgb)\n    plt.axis('off')  # Hide axis\n    plt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:12.380917Z","iopub.execute_input":"2025-02-25T08:09:12.381231Z","iopub.status.idle":"2025-02-25T08:09:12.851323Z","shell.execute_reply.started":"2025-02-25T08:09:12.381205Z","shell.execute_reply":"2025-02-25T08:09:12.850502Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import cv2\nimport matplotlib.pyplot as plt\n\n# Load image\nimg = cv2.imread('/kaggle/working/train/7156.png')\n\n# Check if the image is loaded correctly\nif img is None:\n    print(\"Image not found or the path is incorrect.\")\nelse:\n    # Convert BGR to RGB\n    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n    # Display the image\n    plt.imshow(img_rgb)\n    plt.axis('off')  # Hide axis\n    plt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:15.008608Z","iopub.execute_input":"2025-02-25T08:09:15.008921Z","iopub.status.idle":"2025-02-25T08:09:15.055022Z","shell.execute_reply.started":"2025-02-25T08:09:15.008893Z","shell.execute_reply":"2025-02-25T08:09:15.054296Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"id_list=list(labeled_df['id'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:15.366111Z","iopub.execute_input":"2025-02-25T08:09:15.366320Z","iopub.status.idle":"2025-02-25T08:09:15.373903Z","shell.execute_reply.started":"2025-02-25T08:09:15.366302Z","shell.execute_reply":"2025-02-25T08:09:15.373269Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"id_list[-5:]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:16.982165Z","iopub.execute_input":"2025-02-25T08:09:16.982463Z","iopub.status.idle":"2025-02-25T08:09:16.987376Z","shell.execute_reply.started":"2025-02-25T08:09:16.982435Z","shell.execute_reply":"2025-02-25T08:09:16.986415Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Image Processing**","metadata":{}},{"cell_type":"markdown","source":"**Converting Images Into Numpy Array**","metadata":{}},{"cell_type":"code","source":"train_data_folder='/kaggle/working/train/'\ndata=[]\nfor id in id_list:\n    image =Image.open(train_data_folder+str(id)+'.png')\n    image=np.array(image)\n    data.append(image)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:18.988425Z","iopub.execute_input":"2025-02-25T08:09:18.988669Z","iopub.status.idle":"2025-02-25T08:09:28.653540Z","shell.execute_reply.started":"2025-02-25T08:09:18.988648Z","shell.execute_reply":"2025-02-25T08:09:28.652880Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(data)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.654509Z","iopub.execute_input":"2025-02-25T08:09:28.654721Z","iopub.status.idle":"2025-02-25T08:09:28.659358Z","shell.execute_reply.started":"2025-02-25T08:09:28.654701Z","shell.execute_reply":"2025-02-25T08:09:28.658702Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"type(data[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.660672Z","iopub.execute_input":"2025-02-25T08:09:28.660909Z","iopub.status.idle":"2025-02-25T08:09:28.676026Z","shell.execute_reply.started":"2025-02-25T08:09:28.660891Z","shell.execute_reply":"2025-02-25T08:09:28.675357Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data[0].shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.677197Z","iopub.execute_input":"2025-02-25T08:09:28.677420Z","iopub.status.idle":"2025-02-25T08:09:28.690631Z","shell.execute_reply.started":"2025-02-25T08:09:28.677402Z","shell.execute_reply":"2025-02-25T08:09:28.689820Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.691527Z","iopub.execute_input":"2025-02-25T08:09:28.692054Z","iopub.status.idle":"2025-02-25T08:09:28.704453Z","shell.execute_reply.started":"2025-02-25T08:09:28.692024Z","shell.execute_reply":"2025-02-25T08:09:28.703855Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Covert image list and label list to numpy array**","metadata":{}},{"cell_type":"code","source":"X =np.array(data)\nY=np.array(labels)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.705225Z","iopub.execute_input":"2025-02-25T08:09:28.705538Z","iopub.status.idle":"2025-02-25T08:09:28.797775Z","shell.execute_reply.started":"2025-02-25T08:09:28.705508Z","shell.execute_reply":"2025-02-25T08:09:28.797114Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(X.shape)\nprint(Y.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.798434Z","iopub.execute_input":"2025-02-25T08:09:28.798635Z","iopub.status.idle":"2025-02-25T08:09:28.802445Z","shell.execute_reply.started":"2025-02-25T08:09:28.798617Z","shell.execute_reply":"2025-02-25T08:09:28.801638Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Train Test Split**","metadata":{}},{"cell_type":"code","source":"X_train,X_test,y_train,y_test =train_test_split(X,Y,test_size=0.2,random_state=2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.804331Z","iopub.execute_input":"2025-02-25T08:09:28.804531Z","iopub.status.idle":"2025-02-25T08:09:28.869852Z","shell.execute_reply.started":"2025-02-25T08:09:28.804514Z","shell.execute_reply":"2025-02-25T08:09:28.869185Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.870926Z","iopub.execute_input":"2025-02-25T08:09:28.871237Z","iopub.status.idle":"2025-02-25T08:09:28.875987Z","shell.execute_reply.started":"2025-02-25T08:09:28.871208Z","shell.execute_reply":"2025-02-25T08:09:28.875274Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.876794Z","iopub.execute_input":"2025-02-25T08:09:28.877105Z","iopub.status.idle":"2025-02-25T08:09:28.890797Z","shell.execute_reply.started":"2025-02-25T08:09:28.877084Z","shell.execute_reply":"2025-02-25T08:09:28.889938Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Scaling The Data**","metadata":{}},{"cell_type":"code","source":"x_train_scaled =X_train/255\nx_test_scaled=X_test/255","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:28.891617Z","iopub.execute_input":"2025-02-25T08:09:28.891893Z","iopub.status.idle":"2025-02-25T08:09:29.303156Z","shell.execute_reply.started":"2025-02-25T08:09:28.891866Z","shell.execute_reply":"2025-02-25T08:09:29.302228Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train_scaled","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:30.023826Z","iopub.execute_input":"2025-02-25T08:09:30.024127Z","iopub.status.idle":"2025-02-25T08:09:30.035660Z","shell.execute_reply.started":"2025-02-25T08:09:30.024101Z","shell.execute_reply":"2025-02-25T08:09:30.034628Z"},"scrolled":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:09:36.326141Z","iopub.execute_input":"2025-02-25T08:09:36.326419Z","iopub.status.idle":"2025-02-25T08:09:47.385096Z","shell.execute_reply.started":"2025-02-25T08:09:36.326397Z","shell.execute_reply":"2025-02-25T08:09:47.384427Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"EPOCHS=40","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:10:09.088763Z","iopub.execute_input":"2025-02-25T08:10:09.089333Z","iopub.status.idle":"2025-02-25T08:10:09.092856Z","shell.execute_reply.started":"2025-02-25T08:10:09.089304Z","shell.execute_reply":"2025-02-25T08:10:09.091999Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras import Sequential, models, layers\nfrom tensorflow.keras.layers import Dense, Dropout, Flatten\nfrom tensorflow.keras.layers import BatchNormalization\nfrom tensorflow.keras.models import load_model\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.applications.resnet50 import ResNet50\nfrom tensorflow.keras import optimizers\n     \n\nconvolutional_base = ResNet50(weights='imagenet', include_top=False, input_shape=(256,256,3))\nconvolutional_base.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:10:22.753867Z","iopub.execute_input":"2025-02-25T08:10:22.754205Z","iopub.status.idle":"2025-02-25T08:10:27.065526Z","shell.execute_reply.started":"2025-02-25T08:10:22.754175Z","shell.execute_reply":"2025-02-25T08:10:27.064685Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model2 = models.Sequential()\nmodel2.add(layers.UpSampling2D((2,2)))\nmodel2.add(layers.UpSampling2D((2,2)))\nmodel2.add(layers.UpSampling2D((2,2)))\nmodel2.add(convolutional_base)\nmodel2.add(layers.Flatten())\nmodel2.add(layers.BatchNormalization())\nmodel2.add(layers.Dense(128, activation='relu'))\nmodel2.add(layers.Dropout(0.5))\nmodel2.add(layers.BatchNormalization())\nmodel2.add(layers.Dense(64, activation='relu'))\nmodel2.add(layers.Dropout(0.5))\nmodel2.add(layers.BatchNormalization())\nmodel2.add(layers.Dense(10, activation='softmax'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:10:51.620956Z","iopub.execute_input":"2025-02-25T08:10:51.621308Z","iopub.status.idle":"2025-02-25T08:10:51.640665Z","shell.execute_reply.started":"2025-02-25T08:10:51.621280Z","shell.execute_reply":"2025-02-25T08:10:51.639879Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras import optimizers\n\noptimizer = tf.keras.optimizers.Adam(learning_rate=0.0001)\nmodel2.compile(\n    optimizer=optimizer, \n    loss='sparse_categorical_crossentropy', \n    metrics=['accuracy']\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:10:53.534571Z","iopub.execute_input":"2025-02-25T08:10:53.534883Z","iopub.status.idle":"2025-02-25T08:10:53.548447Z","shell.execute_reply.started":"2025-02-25T08:10:53.534854Z","shell.execute_reply":"2025-02-25T08:10:53.547611Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras.callbacks import ReduceLROnPlateau\n\nlr_scheduler = ReduceLROnPlateau(\n    monitor='val_loss', \n    factor=0.5, \n    patience=3, \n    verbose=1, \n    min_lr=1e-6\n)\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:10:55.297041Z","iopub.execute_input":"2025-02-25T08:10:55.297337Z","iopub.status.idle":"2025-02-25T08:10:55.302718Z","shell.execute_reply.started":"2025-02-25T08:10:55.297310Z","shell.execute_reply":"2025-02-25T08:10:55.302015Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras.callbacks import EarlyStopping\n\nearly_stop = EarlyStopping(monitor='val_loss', patience=5, restore_best_weights=True)\n\nhistory = model2.fit(\n    x_train_scaled, y_train,\n    validation_split=0.1,\n    epochs=40,\n    batch_size=32,\n\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-25T08:11:05.254237Z","iopub.execute_input":"2025-02-25T08:11:05.254523Z"},"scrolled":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_loss, test_acc = model2.evaluate(x_test_scaled, y_test)\nprint(\"Test Accuracy:\", test_acc)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model2.save('/kaggle/working/Resnet_model.h5')","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"history.history.keys()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"acc = history.history['accuracy']\nval_acc = history.history['val_accuracy']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"EPOCHS=40","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(15, 8))\nplt.subplot(1, 2, 1)\nplt.plot(range(EPOCHS), acc, label='Training Accuracy')\nplt.plot(range(EPOCHS), val_acc, label='Validation Accuracy')\nplt.legend(loc='lower right')\nplt.title('Training and Validation Accuracy')\n\nplt.subplot(1, 2, 2)\nplt.plot(range(EPOCHS), loss, label='Training Loss')\nplt.plot(range(EPOCHS), val_loss, label='Validation Loss')\nplt.legend(loc='upper right')\nplt.title('Training and Validation Loss')\nplt.show()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model2.predict(x_test_scaled)\npredicted_categories = tf.argmax(y_pred, axis=1)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Y_true = y_test ","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predicted_categories","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix,classification_report\ncm = confusion_matrix(Y_true,predicted_categories)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class_name = list(labeled_dictionary.keys())","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(classification_report(Y_true,predicted_categories,target_names=class_name))","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import seaborn as sns\nplt.figure(figsize=(12, 12))\nsns.heatmap(cm,annot=True,annot_kws={\"size\": 10})\n\nplt.xlabel('Predicted Class',fontsize = 20)\nplt.ylabel('Actual Class',fontsize = 20)\nplt.title('Image Recognition Confusion Matrix',fontsize = 25)\nplt.show()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}