{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.11.13","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,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true},"colab":{"authorship_tag":"ABX9TyPp4slqmXje578TlwxQdhzX","collapsed_sections":["qHQuMV6VWYru","Ud6hFF4rnhQK","DOoaGBDk-FU_","VhtYg63_32mi","yZr22WSb4Kb8","W_9dK6Iw5EXZ","hW66EaXA4vnR","QdVw64766el6","4Qld_YmJ7gky"],"mount_file_id":"13qXN8EhvE9O327l14hTImH-1F15ZlMU-","provenance":[]},"papermill":{"default_parameters":{},"duration":1395.421572,"end_time":"2024-04-07T20:50:14.817947","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2024-04-07T20:26:59.396375","version":"2.5.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Mount Drive","metadata":{"id":"qHQuMV6VWYru","papermill":{"duration":0.017174,"end_time":"2024-04-07T20:27:02.045808","exception":false,"start_time":"2024-04-07T20:27:02.028634","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# from google.colab import drive\n# drive.mount(\"/content/drive\")","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:10:30.336179Z","iopub.execute_input":"2025-09-27T16:10:30.336473Z","iopub.status.idle":"2025-09-27T16:10:30.339902Z","shell.execute_reply.started":"2025-09-27T16:10:30.336455Z","shell.execute_reply":"2025-09-27T16:10:30.339154Z"},"executionInfo":{"elapsed":3617,"status":"ok","timestamp":1671903293198,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"zt98eHYUWV-2","outputId":"1c6b1f00-d6a3-4563-8d21-dd6617872a47","papermill":{"duration":0.023531,"end_time":"2024-04-07T20:27:02.086115","exception":false,"start_time":"2024-04-07T20:27:02.062584","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Importing Packages","metadata":{"id":"Ud6hFF4rnhQK","papermill":{"duration":0.027215,"end_time":"2024-04-07T20:27:02.130740","exception":false,"start_time":"2024-04-07T20:27:02.103525","status":"completed"},"tags":[]}},{"cell_type":"code","source":"!pip install py7zr","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:10:30.341037Z","iopub.execute_input":"2025-09-27T16:10:30.341287Z","iopub.status.idle":"2025-09-27T16:10:35.849611Z","shell.execute_reply.started":"2025-09-27T16:10:30.341260Z","shell.execute_reply":"2025-09-27T16:10:35.848886Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Fetching Dataset\nimport pandas as pd\nimport py7zr\n\n# Reading Image\nimport os\nimport cv2 as cv\nimport matplotlib.pyplot as plt\n\n# Scaling Features\nfrom sklearn.preprocessing import MinMaxScaler\n\n# Binarizing Output\nfrom sklearn.preprocessing import LabelBinarizer\n\n# Spliting Train & Test Set\nfrom sklearn.model_selection import train_test_split\n\n# Image Augmentation\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\n\n# Creating and Training Model\nfrom tensorflow.keras import layers, models\nfrom tensorflow.keras.callbacks import EarlyStopping\nfrom tensorflow.keras.applications import ResNet50, ResNet152\n\n# Evaluating Model\nfrom sklearn.metrics import (classification_report, multilabel_confusion_matrix, confusion_matrix)\nimport seaborn as sb\nimport matplotlib.pyplot as plt\n\n# Making Predictions\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2025-09-27T18:31:40.347764Z","iopub.execute_input":"2025-09-27T18:31:40.348661Z","iopub.status.idle":"2025-09-27T18:31:40.354075Z","shell.execute_reply.started":"2025-09-27T18:31:40.348621Z","shell.execute_reply":"2025-09-27T18:31:40.353532Z"},"id":"RfU8VXwvngn0","papermill":{"duration":13.863858,"end_time":"2024-04-07T20:27:16.011295","exception":false,"start_time":"2024-04-07T20:27:02.147437","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Fetching Dataset","metadata":{"id":"DOoaGBDk-FU_","papermill":{"duration":0.016727,"end_time":"2024-04-07T20:27:16.045558","exception":false,"start_time":"2024-04-07T20:27:16.028831","status":"completed"},"tags":[]}},{"cell_type":"code","source":"dataset_archive_dir = '/kaggle/input/cifar-10/'\ndataset_train = pd.read_csv(dataset_archive_dir + \"trainLabels.csv\")\ndataset_test = pd.read_csv(dataset_archive_dir + \"sampleSubmission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:10:48.833332Z","iopub.execute_input":"2025-09-27T16:10:48.833801Z","iopub.status.idle":"2025-09-27T16:10:48.970233Z","shell.execute_reply.started":"2025-09-27T16:10:48.833771Z","shell.execute_reply":"2025-09-27T16:10:48.969430Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_archive_dir = dataset_archive_dir + 'train.7z'\ntest_archive_dir = dataset_archive_dir + 'test.7z'\n\ndataset_output_dir = '/kaggle/working/cifar/'\ntrain_dataset_dir = dataset_output_dir + 'train/'\ntest_dataset_dir = dataset_output_dir + 'test/'\n\n# os.makedirs(train_dataset_dir, exist_ok=True)\n# os.makedirs(test_dataset_dir, exist_ok=True)\nos.makedirs(dataset_output_dir, exist_ok=True)\n\nwith py7zr.SevenZipFile(train_archive_dir, mode='r') as archive:\n    archive.extractall(path=dataset_output_dir)\n\nprint(f\"Successfully extracted '{train_archive_dir}' to '{dataset_output_dir}'\")\n\nwith py7zr.SevenZipFile(test_archive_dir, mode='r') as archive:\n    archive.extractall(path=dataset_output_dir)\n\nprint(f\"Successfully extracted '{test_archive_dir}' to '{dataset_output_dir}'\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:10:48.972228Z","iopub.execute_input":"2025-09-27T16:10:48.972481Z","iopub.status.idle":"2025-09-27T16:13:06.294609Z","shell.execute_reply.started":"2025-09-27T16:10:48.972464Z","shell.execute_reply":"2025-09-27T16:13:06.293940Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dataset_train","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:06.295275Z","iopub.execute_input":"2025-09-27T16:13:06.295518Z","iopub.status.idle":"2025-09-27T16:13:06.318762Z","shell.execute_reply.started":"2025-09-27T16:13:06.295497Z","shell.execute_reply":"2025-09-27T16:13:06.318197Z"},"papermill":{"duration":0.034506,"end_time":"2024-04-07T20:27:16.393709","exception":false,"start_time":"2024-04-07T20:27:16.359203","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dataset_test","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:06.319703Z","iopub.execute_input":"2025-09-27T16:13:06.319959Z","iopub.status.idle":"2025-09-27T16:13:06.327393Z","shell.execute_reply.started":"2025-09-27T16:13:06.319934Z","shell.execute_reply":"2025-09-27T16:13:06.326744Z"},"papermill":{"duration":0.030548,"end_time":"2024-04-07T20:27:16.487306","exception":false,"start_time":"2024-04-07T20:27:16.456758","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train = dataset_train.loc[:, 'id'].values\nX_test = dataset_test.loc[:, 'id'].values\ny_train = dataset_train.loc[:, 'label'].values\ny_test = dataset_test.loc[:, 'label'].values","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:13:06.328443Z","iopub.execute_input":"2025-09-27T16:13:06.328851Z","iopub.status.idle":"2025-09-27T16:13:06.339972Z","shell.execute_reply.started":"2025-09-27T16:13:06.328833Z","shell.execute_reply":"2025-09-27T16:13:06.339360Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:06.340939Z","iopub.execute_input":"2025-09-27T16:13:06.341194Z","iopub.status.idle":"2025-09-27T16:13:06.352055Z","shell.execute_reply.started":"2025-09-27T16:13:06.341175Z","shell.execute_reply":"2025-09-27T16:13:06.351501Z"},"papermill":{"duration":0.025766,"end_time":"2024-04-07T20:27:35.303712","exception":false,"start_time":"2024-04-07T20:27:35.277946","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_test","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:06.352974Z","iopub.execute_input":"2025-09-27T16:13:06.353274Z","iopub.status.idle":"2025-09-27T16:13:06.363903Z","shell.execute_reply.started":"2025-09-27T16:13:06.353251Z","shell.execute_reply":"2025-09-27T16:13:06.363123Z"},"papermill":{"duration":0.026128,"end_time":"2024-04-07T20:27:35.347223","exception":false,"start_time":"2024-04-07T20:27:35.321095","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:06.366634Z","iopub.execute_input":"2025-09-27T16:13:06.366888Z","iopub.status.idle":"2025-09-27T16:13:06.376007Z","shell.execute_reply.started":"2025-09-27T16:13:06.366873Z","shell.execute_reply":"2025-09-27T16:13:06.375386Z"},"papermill":{"duration":0.02646,"end_time":"2024-04-07T20:27:35.391291","exception":false,"start_time":"2024-04-07T20:27:35.364831","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:13:06.376645Z","iopub.execute_input":"2025-09-27T16:13:06.376884Z","iopub.status.idle":"2025-09-27T16:13:06.387494Z","shell.execute_reply.started":"2025-09-27T16:13:06.376864Z","shell.execute_reply":"2025-09-27T16:13:06.386894Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(X_train.shape)\nprint(X_test.shape)\nprint(y_train.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:06.388186Z","iopub.execute_input":"2025-09-27T16:13:06.388409Z","iopub.status.idle":"2025-09-27T16:13:06.397932Z","shell.execute_reply.started":"2025-09-27T16:13:06.388387Z","shell.execute_reply":"2025-09-27T16:13:06.397258Z"},"executionInfo":{"elapsed":43,"status":"ok","timestamp":1671903293915,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"d3RIocGkmY7a","outputId":"f04ca66c-a98e-4542-8723-319185e5eb5f","papermill":{"duration":0.02525,"end_time":"2024-04-07T20:27:35.434872","exception":false,"start_time":"2024-04-07T20:27:35.409622","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Reading & Preprocessing Image","metadata":{"id":"OC7pi_STnmM_","papermill":{"duration":0.018052,"end_time":"2024-04-07T20:27:35.520608","exception":false,"start_time":"2024-04-07T20:27:35.502556","status":"completed"},"tags":[]}},{"cell_type":"code","source":"IMG_SIZE = 32 # Same Height and Width is being used\nx_train_data = np.empty((len(X_train), IMG_SIZE, IMG_SIZE, 3), dtype = np.int64)\nx_test_data = np.empty((len(X_test), IMG_SIZE, IMG_SIZE, 3), dtype = np.int64)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:06.398747Z","iopub.execute_input":"2025-09-27T16:13:06.398995Z","iopub.status.idle":"2025-09-27T16:13:06.408999Z","shell.execute_reply.started":"2025-09-27T16:13:06.398973Z","shell.execute_reply":"2025-09-27T16:13:06.408272Z"},"id":"3LKOqFRYnGbZ","papermill":{"duration":0.025145,"end_time":"2024-04-07T20:27:35.563554","exception":false,"start_time":"2024-04-07T20:27:35.538409","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(x_train_data.shape)\nprint(x_test_data.shape)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:06.409745Z","iopub.execute_input":"2025-09-27T16:13:06.409984Z","iopub.status.idle":"2025-09-27T16:13:06.420904Z","shell.execute_reply.started":"2025-09-27T16:13:06.409969Z","shell.execute_reply":"2025-09-27T16:13:06.420188Z"},"executionInfo":{"elapsed":34,"status":"ok","timestamp":1671903293917,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"Ni0FKIEgn237","outputId":"f7326934-6e1f-49d1-a0cb-4e3266851426","papermill":{"duration":0.06676,"end_time":"2024-04-07T20:27:35.648210","exception":false,"start_time":"2024-04-07T20:27:35.581450","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i, img_path in enumerate(X_train):\n    img = cv.imread(train_dataset_dir + str(img_path) + '.png')\n    img_rs = cv.resize(img, dsize = (IMG_SIZE, IMG_SIZE))\n    # img_gray = cv.cvtColor(img_rs, cv.COLOR_BGR2GRAY)\n    # ret, candidate_threshold = cv.threshold(img_gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)\n    x_train_data[i] = img_rs","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:13:06.421640Z","iopub.execute_input":"2025-09-27T16:13:06.421939Z","iopub.status.idle":"2025-09-27T16:13:11.246527Z","shell.execute_reply.started":"2025-09-27T16:13:06.421916Z","shell.execute_reply":"2025-09-27T16:13:11.245944Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i, img_path in enumerate(X_test):\n    img = cv.imread(test_dataset_dir + str(img_path) + '.png')\n    img_rs = cv.resize(img, dsize = (IMG_SIZE, IMG_SIZE))\n    # img_gray = cv.cvtColor(img_rs, cv.COLOR_BGR2GRAY)\n    # ret, candidate_threshold = cv.threshold(img_gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)\n    x_test_data[i] = img_rs","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:13:11.247267Z","iopub.execute_input":"2025-09-27T16:13:11.247529Z","iopub.status.idle":"2025-09-27T16:13:40.882652Z","shell.execute_reply.started":"2025-09-27T16:13:11.247507Z","shell.execute_reply":"2025-09-27T16:13:40.881813Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(x_train_data[1])","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:40.883466Z","iopub.execute_input":"2025-09-27T16:13:40.883687Z","iopub.status.idle":"2025-09-27T16:13:41.121320Z","shell.execute_reply.started":"2025-09-27T16:13:40.883670Z","shell.execute_reply":"2025-09-27T16:13:41.120715Z"},"id":"n2E7m-iKqjCn","papermill":{"duration":0.21951,"end_time":"2024-04-07T20:34:27.300834","exception":false,"start_time":"2024-04-07T20:34:27.081324","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(x_test_data[1])","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.121991Z","iopub.execute_input":"2025-09-27T16:13:41.122229Z","iopub.status.idle":"2025-09-27T16:13:41.255753Z","shell.execute_reply.started":"2025-09-27T16:13:41.122213Z","shell.execute_reply":"2025-09-27T16:13:41.255187Z"},"papermill":{"duration":0.193655,"end_time":"2024-04-07T20:34:27.739678","exception":false,"start_time":"2024-04-07T20:34:27.546023","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(x_train_data[0][0])","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.256372Z","iopub.execute_input":"2025-09-27T16:13:41.256549Z","iopub.status.idle":"2025-09-27T16:13:41.261064Z","shell.execute_reply.started":"2025-09-27T16:13:41.256528Z","shell.execute_reply":"2025-09-27T16:13:41.260470Z"},"papermill":{"duration":0.026938,"end_time":"2024-04-07T20:34:27.785727","exception":false,"start_time":"2024-04-07T20:34:27.758789","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(x_test_data[0][0])","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.261788Z","iopub.execute_input":"2025-09-27T16:13:41.262022Z","iopub.status.idle":"2025-09-27T16:13:41.272818Z","shell.execute_reply.started":"2025-09-27T16:13:41.262000Z","shell.execute_reply":"2025-09-27T16:13:41.272102Z"},"papermill":{"duration":0.02685,"end_time":"2024-04-07T20:34:27.831774","exception":false,"start_time":"2024-04-07T20:34:27.804924","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train = np.reshape(x_train_data, (X_train.shape[0], IMG_SIZE * IMG_SIZE, 3))\nX_test = np.reshape(x_test_data, (X_test.shape[0], IMG_SIZE * IMG_SIZE, 3))","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.273509Z","iopub.execute_input":"2025-09-27T16:13:41.273707Z","iopub.status.idle":"2025-09-27T16:13:41.283075Z","shell.execute_reply.started":"2025-09-27T16:13:41.273693Z","shell.execute_reply":"2025-09-27T16:13:41.282523Z"},"id":"qHatxo9Jn6kC","papermill":{"duration":0.026501,"end_time":"2024-04-07T20:34:27.879250","exception":false,"start_time":"2024-04-07T20:34:27.852749","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(X_train.shape)\nprint(X_test.shape)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.283718Z","iopub.execute_input":"2025-09-27T16:13:41.283937Z","iopub.status.idle":"2025-09-27T16:13:41.294620Z","shell.execute_reply.started":"2025-09-27T16:13:41.283922Z","shell.execute_reply":"2025-09-27T16:13:41.293911Z"},"executionInfo":{"elapsed":209,"status":"ok","timestamp":1671908771631,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"96_UEjVEn8yy","outputId":"c9d36c98-1bff-49dd-f61b-4b7f15cbf62e","papermill":{"duration":0.026362,"end_time":"2024-04-07T20:34:27.924803","exception":false,"start_time":"2024-04-07T20:34:27.898441","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Scaling Features","metadata":{"id":"VhtYg63_32mi","papermill":{"duration":0.024261,"end_time":"2024-04-07T20:34:27.970945","exception":false,"start_time":"2024-04-07T20:34:27.946684","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# sc = MinMaxScaler()\n# X_train = sc.fit_transform(X_train)\n# X_test = sc.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.295401Z","iopub.execute_input":"2025-09-27T16:13:41.296033Z","iopub.status.idle":"2025-09-27T16:13:41.305514Z","shell.execute_reply.started":"2025-09-27T16:13:41.296010Z","shell.execute_reply":"2025-09-27T16:13:41.304878Z"},"id":"2HSHvUQx3pVm","papermill":{"duration":0.683096,"end_time":"2024-04-07T20:34:28.681217","exception":false,"start_time":"2024-04-07T20:34:27.998121","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.306098Z","iopub.execute_input":"2025-09-27T16:13:41.306394Z","iopub.status.idle":"2025-09-27T16:13:41.318750Z","shell.execute_reply.started":"2025-09-27T16:13:41.306370Z","shell.execute_reply":"2025-09-27T16:13:41.318080Z"},"executionInfo":{"elapsed":203,"status":"ok","timestamp":1671908771633,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"jSj6M9SO5W1m","outputId":"875d5c1c-13e1-4509-85a9-5b505412fb91","papermill":{"duration":0.028483,"end_time":"2024-04-07T20:34:28.729649","exception":false,"start_time":"2024-04-07T20:34:28.701166","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_test","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.319527Z","iopub.execute_input":"2025-09-27T16:13:41.320316Z","iopub.status.idle":"2025-09-27T16:13:41.330208Z","shell.execute_reply.started":"2025-09-27T16:13:41.320293Z","shell.execute_reply":"2025-09-27T16:13:41.329570Z"},"papermill":{"duration":0.028121,"end_time":"2024-04-07T20:34:28.777338","exception":false,"start_time":"2024-04-07T20:34:28.749217","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Binarizing Output","metadata":{"id":"yZr22WSb4Kb8","papermill":{"duration":0.019328,"end_time":"2024-04-07T20:34:28.816481","exception":false,"start_time":"2024-04-07T20:34:28.797153","status":"completed"},"tags":[]}},{"cell_type":"code","source":"lb = LabelBinarizer()\ny_train = lb.fit_transform(y_train)\ny_test = lb.transform(y_test)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.330940Z","iopub.execute_input":"2025-09-27T16:13:41.331611Z","iopub.status.idle":"2025-09-27T16:13:41.843895Z","shell.execute_reply.started":"2025-09-27T16:13:41.331593Z","shell.execute_reply":"2025-09-27T16:13:41.843044Z"},"id":"vJsFgQUSK8wL","papermill":{"duration":0.038709,"end_time":"2024-04-07T20:34:28.874699","exception":false,"start_time":"2024-04-07T20:34:28.835990","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:13:41.844749Z","iopub.execute_input":"2025-09-27T16:13:41.845010Z","iopub.status.idle":"2025-09-27T16:13:41.850301Z","shell.execute_reply.started":"2025-09-27T16:13:41.844983Z","shell.execute_reply":"2025-09-27T16:13:41.849519Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:13:41.854342Z","iopub.execute_input":"2025-09-27T16:13:41.854669Z","iopub.status.idle":"2025-09-27T16:13:41.862478Z","shell.execute_reply.started":"2025-09-27T16:13:41.854652Z","shell.execute_reply":"2025-09-27T16:13:41.861831Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(y_train.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.863217Z","iopub.execute_input":"2025-09-27T16:13:41.863469Z","iopub.status.idle":"2025-09-27T16:13:41.873870Z","shell.execute_reply.started":"2025-09-27T16:13:41.863453Z","shell.execute_reply":"2025-09-27T16:13:41.873195Z"},"executionInfo":{"elapsed":129,"status":"ok","timestamp":1671908771634,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"sNh6r-dsLCCI","outputId":"0b6b9e16-92ac-4d08-8eb9-68e1fd13a2c0","papermill":{"duration":0.026798,"end_time":"2024-04-07T20:34:28.921277","exception":false,"start_time":"2024-04-07T20:34:28.894479","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Spliting Train & Test Set\n","metadata":{"id":"W_9dK6Iw5EXZ","papermill":{"duration":0.019563,"end_time":"2024-04-07T20:34:28.960771","exception":false,"start_time":"2024-04-07T20:34:28.941208","status":"completed"},"tags":[]}},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, train_size = 0.9, random_state = 45, stratify = y_train)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:41.874661Z","iopub.execute_input":"2025-09-27T16:13:41.874844Z","iopub.status.idle":"2025-09-27T16:13:42.598023Z","shell.execute_reply.started":"2025-09-27T16:13:41.874829Z","shell.execute_reply":"2025-09-27T16:13:42.597241Z"},"id":"ARtvOrWsWImO","papermill":{"duration":0.175416,"end_time":"2024-04-07T20:34:29.156152","exception":false,"start_time":"2024-04-07T20:34:28.980736","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(X_train.shape, X_val.shape, y_train.shape, y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:42.598986Z","iopub.execute_input":"2025-09-27T16:13:42.599291Z","iopub.status.idle":"2025-09-27T16:13:42.603834Z","shell.execute_reply.started":"2025-09-27T16:13:42.599269Z","shell.execute_reply":"2025-09-27T16:13:42.602981Z"},"executionInfo":{"elapsed":200,"status":"ok","timestamp":1671908772395,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"zUaoqtZC8LW5","outputId":"69ae0bba-ca64-40b7-8179-033bafd69b9b","papermill":{"duration":0.027727,"end_time":"2024-04-07T20:34:29.204285","exception":false,"start_time":"2024-04-07T20:34:29.176558","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train = X_train.reshape(-1, IMG_SIZE, IMG_SIZE, 3)\nX_val = X_val.reshape(-1, IMG_SIZE, IMG_SIZE, 3)\nX_test = X_test.reshape(-1, IMG_SIZE, IMG_SIZE, 3)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:42.604710Z","iopub.execute_input":"2025-09-27T16:13:42.604978Z","iopub.status.idle":"2025-09-27T16:13:42.614442Z","shell.execute_reply.started":"2025-09-27T16:13:42.604952Z","shell.execute_reply":"2025-09-27T16:13:42.613819Z"},"executionInfo":{"elapsed":200,"status":"ok","timestamp":1671908772398,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"qydb7AVI_s4C","outputId":"1fae866b-e96e-4f03-dc1d-1e44fcc55d0b","papermill":{"duration":0.02706,"end_time":"2024-04-07T20:34:29.251410","exception":false,"start_time":"2024-04-07T20:34:29.224350","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(X_train.shape)\nprint(X_val.shape)\nprint(X_test.shape)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:42.614989Z","iopub.execute_input":"2025-09-27T16:13:42.615249Z","iopub.status.idle":"2025-09-27T16:13:42.626111Z","shell.execute_reply.started":"2025-09-27T16:13:42.615233Z","shell.execute_reply":"2025-09-27T16:13:42.625538Z"},"executionInfo":{"elapsed":193,"status":"ok","timestamp":1671908772399,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"RyXlO3S3_2uA","outputId":"69d566ec-0fb7-4749-dbed-3cb3e43bb029","papermill":{"duration":0.027098,"end_time":"2024-04-07T20:34:29.298265","exception":false,"start_time":"2024-04-07T20:34:29.271167","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(X_train[45])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T16:13:42.626833Z","iopub.execute_input":"2025-09-27T16:13:42.627280Z","iopub.status.idle":"2025-09-27T16:13:42.780884Z","shell.execute_reply.started":"2025-09-27T16:13:42.627264Z","shell.execute_reply":"2025-09-27T16:13:42.780180Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Image Augmentation","metadata":{"papermill":{"duration":0.019702,"end_time":"2024-04-07T20:34:29.337794","exception":false,"start_time":"2024-04-07T20:34:29.318092","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# Define ImageDataGenerator\ndatagen = ImageDataGenerator(\n    rotation_range = 10,\n    zoom_range = 0.1,\n    shear_range = 0.5,\n    cval = 0.0,\n    fill_mode = 'constant')","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:42.781598Z","iopub.execute_input":"2025-09-27T16:13:42.781844Z","iopub.status.idle":"2025-09-27T16:13:42.786103Z","shell.execute_reply.started":"2025-09-27T16:13:42.781791Z","shell.execute_reply":"2025-09-27T16:13:42.785356Z"},"papermill":{"duration":0.026726,"end_time":"2024-04-07T20:34:29.384347","exception":false,"start_time":"2024-04-07T20:34:29.357621","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Generate augmented data\nbatch_size = 32\ntrain_generator = datagen.flow(X_train, y_train, batch_size = batch_size, shuffle = False)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:42.786985Z","iopub.execute_input":"2025-09-27T16:13:42.787324Z","iopub.status.idle":"2025-09-27T16:13:43.032738Z","shell.execute_reply.started":"2025-09-27T16:13:42.787301Z","shell.execute_reply":"2025-09-27T16:13:43.032179Z"},"papermill":{"duration":0.10158,"end_time":"2024-04-07T20:34:29.507218","exception":false,"start_time":"2024-04-07T20:34:29.405638","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train_generator)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:43.033350Z","iopub.execute_input":"2025-09-27T16:13:43.033589Z","iopub.status.idle":"2025-09-27T16:13:43.038584Z","shell.execute_reply.started":"2025-09-27T16:13:43.033569Z","shell.execute_reply":"2025-09-27T16:13:43.037885Z"},"papermill":{"duration":0.028971,"end_time":"2024-04-07T20:34:29.556878","exception":false,"start_time":"2024-04-07T20:34:29.527907","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Creating and Training a CNN Model\n","metadata":{"id":"hW66EaXA4vnR","papermill":{"duration":0.01998,"end_time":"2024-04-07T20:34:29.596856","exception":false,"start_time":"2024-04-07T20:34:29.576876","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# Load the pre-trained model\nresnet152 = ResNet152(weights='imagenet', input_shape=(IMG_SIZE*5, IMG_SIZE*5, 3), include_top=False)\n\n# Freeze the weights of the pre-trained layers\nfor layer in resnet152.layers:\n    layer.trainable = False\n\n# Add your custom layers to the top of the pre-trained model\nmodel = models.Sequential(name = 'CIFAR-10-Object-Recognition')\nmodel.add(layers.Input((IMG_SIZE, IMG_SIZE, 3)))\nmodel.add(layers.UpSampling2D(size=(5, 5)))\nmodel.add(resnet152)\nmodel.add(layers.Flatten())\nmodel.add(layers.Dense(units=1024, activation='relu'))\nmodel.add(layers.Dense(units=512, activation='relu'))\nmodel.add(layers.Dense(units=10, activation='softmax'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:26:54.181709Z","iopub.execute_input":"2025-09-27T18:26:54.181934Z","iopub.status.idle":"2025-09-27T18:26:57.097167Z","shell.execute_reply.started":"2025-09-27T18:26:54.181917Z","shell.execute_reply":"2025-09-27T18:26:57.096607Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:49.469939Z","iopub.execute_input":"2025-09-27T16:13:49.470272Z","iopub.status.idle":"2025-09-27T16:13:49.500788Z","shell.execute_reply.started":"2025-09-27T16:13:49.470243Z","shell.execute_reply":"2025-09-27T16:13:49.500280Z"},"executionInfo":{"elapsed":182,"status":"ok","timestamp":1671908772400,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"ATyz_NHT0GBM","outputId":"890a905b-9c65-4546-9fde-376c6943fcc7","papermill":{"duration":0.061242,"end_time":"2024-04-07T20:34:30.566107","exception":false,"start_time":"2024-04-07T20:34:30.504865","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"epochs = 100\nacc_callback = EarlyStopping(monitor = 'val_accuracy', verbose = 1, patience = 10, mode = 'max', restore_best_weights = True, start_from_epoch = 15)\nloss_callback = EarlyStopping(monitor = 'val_loss', verbose = 1, patience = 10, mode = 'min', restore_best_weights = True, start_from_epoch = 15)","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:13:49.501436Z","iopub.execute_input":"2025-09-27T16:13:49.501633Z","iopub.status.idle":"2025-09-27T16:13:49.505748Z","shell.execute_reply.started":"2025-09-27T16:13:49.501618Z","shell.execute_reply":"2025-09-27T16:13:49.504973Z"},"papermill":{"duration":0.029601,"end_time":"2024-04-07T20:34:30.617722","exception":false,"start_time":"2024-04-07T20:34:30.588121","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:14:50.931353Z","iopub.execute_input":"2025-09-27T16:14:50.931644Z","iopub.status.idle":"2025-09-27T16:14:50.941511Z","shell.execute_reply.started":"2025-09-27T16:14:50.931622Z","shell.execute_reply":"2025-09-27T16:14:50.940698Z"},"id":"KyFKGexVET4M","papermill":{"duration":0.041613,"end_time":"2024-04-07T20:34:30.681602","exception":false,"start_time":"2024-04-07T20:34:30.639989","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"history  = model.fit(train_generator, validation_data = (X_val, y_val), epochs = epochs, callbacks = [acc_callback, loss_callback])","metadata":{"execution":{"iopub.status.busy":"2025-09-27T16:14:50.942775Z","iopub.execute_input":"2025-09-27T16:14:50.943501Z","iopub.status.idle":"2025-09-27T18:02:27.275527Z","shell.execute_reply.started":"2025-09-27T16:14:50.943474Z","shell.execute_reply":"2025-09-27T18:02:27.274700Z"},"executionInfo":{"elapsed":327825,"status":"ok","timestamp":1671909100151,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"358VdnTrAD0A","outputId":"5501bbcd-7abf-4ccc-ab7f-546908b96607","papermill":{"duration":901.890319,"end_time":"2024-04-07T20:49:32.594066","exception":false,"start_time":"2024-04-07T20:34:30.703747","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Evaluating the CNN model\n","metadata":{"id":"QdVw64766el6","papermill":{"duration":1.239041,"end_time":"2024-04-07T20:49:35.124934","exception":false,"start_time":"2024-04-07T20:49:33.885893","status":"completed"},"tags":[]}},{"cell_type":"code","source":"history_test = model.evaluate(X_val, y_val)","metadata":{"executionInfo":{"elapsed":1140,"status":"ok","timestamp":1671909101264,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"XejIje1UAHZK","outputId":"61a89cb1-38fb-441e-f9c6-3231b926e839","papermill":{"duration":2.454773,"end_time":"2024-04-07T20:49:38.831419","exception":false,"start_time":"2024-04-07T20:49:36.376646","status":"completed"},"tags":[],"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:02:27.277217Z","iopub.execute_input":"2025-09-27T18:02:27.277543Z","iopub.status.idle":"2025-09-27T18:02:51.019048Z","shell.execute_reply.started":"2025-09-27T18:02:27.277525Z","shell.execute_reply":"2025-09-27T18:02:51.018361Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_predicted = model.predict(X_test)","metadata":{"executionInfo":{"elapsed":949,"status":"ok","timestamp":1671909102195,"user":{"displayName":"1578_Avishek Chowdhury","userId":"14734427622886483691"},"user_tz":-360},"id":"oLpa4hLFAP1L","outputId":"db3875dc-b298-40c2-9ec7-ce9ab3f5a651","papermill":{"duration":2.929654,"end_time":"2024-04-07T20:49:45.416736","exception":false,"start_time":"2024-04-07T20:49:42.487082","status":"completed"},"tags":[],"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:02:51.020059Z","iopub.execute_input":"2025-09-27T18:02:51.020273Z","iopub.status.idle":"2025-09-27T18:26:44.240078Z","shell.execute_reply.started":"2025-09-27T18:02:51.020256Z","shell.execute_reply":"2025-09-27T18:26:44.239474Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_predicted","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:26:44.242357Z","iopub.execute_input":"2025-09-27T18:26:44.242552Z","iopub.status.idle":"2025-09-27T18:26:44.247763Z","shell.execute_reply.started":"2025-09-27T18:26:44.242538Z","shell.execute_reply":"2025-09-27T18:26:44.247060Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# y_test_labels = lb.inverse_transform(y_test)\ny_predicted_labels = lb.inverse_transform(y_predicted)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:26:44.248673Z","iopub.execute_input":"2025-09-27T18:26:44.248963Z","iopub.status.idle":"2025-09-27T18:26:44.288854Z","shell.execute_reply.started":"2025-09-27T18:26:44.248946Z","shell.execute_reply":"2025-09-27T18:26:44.288356Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_predicted_labels","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:26:44.289699Z","iopub.execute_input":"2025-09-27T18:26:44.289948Z","iopub.status.idle":"2025-09-27T18:26:44.294259Z","shell.execute_reply.started":"2025-09-27T18:26:44.289927Z","shell.execute_reply":"2025-09-27T18:26:44.293662Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dataset_test['label'] = y_predicted_labels\ndataset_test","metadata":{"papermill":{"duration":1.267615,"end_time":"2024-04-07T20:49:55.483635","exception":false,"start_time":"2024-04-07T20:49:54.216020","status":"completed"},"tags":[],"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:26:44.294892Z","iopub.execute_input":"2025-09-27T18:26:44.295163Z","iopub.status.idle":"2025-09-27T18:26:44.353027Z","shell.execute_reply.started":"2025-09-27T18:26:44.295123Z","shell.execute_reply":"2025-09-27T18:26:44.352466Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!rm -rf /kaggle/working/*","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:26:44.353730Z","iopub.execute_input":"2025-09-27T18:26:44.353993Z","iopub.status.idle":"2025-09-27T18:26:53.932294Z","shell.execute_reply.started":"2025-09-27T18:26:44.353975Z","shell.execute_reply":"2025-09-27T18:26:53.931214Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dataset_test.to_csv('submission.csv', index = False)","metadata":{"papermill":{"duration":1.390992,"end_time":"2024-04-07T20:50:08.283896","exception":false,"start_time":"2024-04-07T20:50:06.892904","status":"completed"},"tags":[],"trusted":true,"execution":{"iopub.status.busy":"2025-09-27T18:26:53.933679Z","iopub.execute_input":"2025-09-27T18:26:53.934300Z","iopub.status.idle":"2025-09-27T18:26:54.179284Z","shell.execute_reply.started":"2025-09-27T18:26:53.934270Z","shell.execute_reply":"2025-09-27T18:26:54.178699Z"}},"outputs":[],"execution_count":null}]}