{"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":"gpu","dataSources":[{"sourceId":3649,"databundleVersionId":46718,"sourceType":"competition"}],"dockerImageVersionId":30529,"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","execution":{"iopub.status.busy":"2023-08-05T03:00:21.570932Z","iopub.execute_input":"2023-08-05T03:00:21.571219Z","iopub.status.idle":"2023-08-05T03:00:21.587583Z","shell.execute_reply.started":"2023-08-05T03:00:21.571193Z","shell.execute_reply":"2023-08-05T03:00:21.584977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install py7zr","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:00:21.589239Z","iopub.execute_input":"2023-08-05T03:00:21.589897Z","iopub.status.idle":"2023-08-05T03:00:40.020137Z","shell.execute_reply.started":"2023-08-05T03:00:21.589865Z","shell.execute_reply":"2023-08-05T03:00:40.018939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import py7zr\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:00:40.022801Z","iopub.execute_input":"2023-08-05T03:00:40.023194Z","iopub.status.idle":"2023-08-05T03:00:40.201470Z","shell.execute_reply.started":"2023-08-05T03:00:40.023151Z","shell.execute_reply":"2023-08-05T03:00:40.200455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"archive = py7zr.SevenZipFile('/kaggle/input/cifar-10/train.7z',mode = 'r')\narchive.extractall()\narchive.close()","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:00:40.203065Z","iopub.execute_input":"2023-08-05T03:00:40.203446Z","iopub.status.idle":"2023-08-05T03:01:40.364426Z","shell.execute_reply.started":"2023-08-05T03:00:40.203388Z","shell.execute_reply":"2023-08-05T03:01:40.363362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:40.367732Z","iopub.execute_input":"2023-08-05T03:01:40.368192Z","iopub.status.idle":"2023-08-05T03:01:41.354177Z","shell.execute_reply.started":"2023-08-05T03:01:40.368155Z","shell.execute_reply":"2023-08-05T03:01:41.353012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Importing the 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\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:41.356201Z","iopub.execute_input":"2023-08-05T03:01:41.356851Z","iopub.status.idle":"2023-08-05T03:01:41.859818Z","shell.execute_reply.started":"2023-08-05T03:01:41.356809Z","shell.execute_reply":"2023-08-05T03:01:41.858704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames = os.listdir('/kaggle/working/train')","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:41.861601Z","iopub.execute_input":"2023-08-05T03:01:41.862291Z","iopub.status.idle":"2023-08-05T03:01:41.897599Z","shell.execute_reply.started":"2023-08-05T03:01:41.862252Z","shell.execute_reply":"2023-08-05T03:01:41.896733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(filenames)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:41.898982Z","iopub.execute_input":"2023-08-05T03:01:41.899320Z","iopub.status.idle":"2023-08-05T03:01:41.907340Z","shell.execute_reply.started":"2023-08-05T03:01:41.899290Z","shell.execute_reply":"2023-08-05T03:01:41.906129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(filenames[:5])","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:41.908958Z","iopub.execute_input":"2023-08-05T03:01:41.909326Z","iopub.status.idle":"2023-08-05T03:01:41.917222Z","shell.execute_reply.started":"2023-08-05T03:01:41.909280Z","shell.execute_reply":"2023-08-05T03:01:41.916354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Labels processing","metadata":{}},{"cell_type":"code","source":"labels_df = pd.read_csv('/kaggle/input/cifar-10/trainLabels.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:41.918384Z","iopub.execute_input":"2023-08-05T03:01:41.919233Z","iopub.status.idle":"2023-08-05T03:01:41.964594Z","shell.execute_reply.started":"2023-08-05T03:01:41.919201Z","shell.execute_reply":"2023-08-05T03:01:41.963707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:41.969296Z","iopub.execute_input":"2023-08-05T03:01:41.969637Z","iopub.status.idle":"2023-08-05T03:01:41.975382Z","shell.execute_reply.started":"2023-08-05T03:01:41.969613Z","shell.execute_reply":"2023-08-05T03:01:41.974480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:41.976532Z","iopub.execute_input":"2023-08-05T03:01:41.977163Z","iopub.status.idle":"2023-08-05T03:01:41.997118Z","shell.execute_reply.started":"2023-08-05T03:01:41.977130Z","shell.execute_reply":"2023-08-05T03:01:41.995604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.tail()","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:41.998666Z","iopub.execute_input":"2023-08-05T03:01:41.999277Z","iopub.status.idle":"2023-08-05T03:01:42.008802Z","shell.execute_reply.started":"2023-08-05T03:01:41.999240Z","shell.execute_reply":"2023-08-05T03:01:42.007686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.010380Z","iopub.execute_input":"2023-08-05T03:01:42.011258Z","iopub.status.idle":"2023-08-05T03:01:42.032382Z","shell.execute_reply.started":"2023-08-05T03:01:42.011169Z","shell.execute_reply":"2023-08-05T03:01:42.031471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dictionary = {'airplane':0,'automobile':1,'bird':2,'cat':3,'deer':4,'dog':5,'frog':6,'horse':7,'ship':8,'truck':9}\nlabels = [labels_dictionary[i] for i in labels_df['label']]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.034150Z","iopub.execute_input":"2023-08-05T03:01:42.034507Z","iopub.status.idle":"2023-08-05T03:01:42.051048Z","shell.execute_reply.started":"2023-08-05T03:01:42.034475Z","shell.execute_reply":"2023-08-05T03:01:42.049773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(labels[0:10])","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.052600Z","iopub.execute_input":"2023-08-05T03:01:42.052944Z","iopub.status.idle":"2023-08-05T03:01:42.063074Z","shell.execute_reply.started":"2023-08-05T03:01:42.052912Z","shell.execute_reply":"2023-08-05T03:01:42.061577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.head(10)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.064861Z","iopub.execute_input":"2023-08-05T03:01:42.065606Z","iopub.status.idle":"2023-08-05T03:01:42.077890Z","shell.execute_reply.started":"2023-08-05T03:01:42.065572Z","shell.execute_reply":"2023-08-05T03:01:42.076918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.tail(10)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.079236Z","iopub.execute_input":"2023-08-05T03:01:42.079841Z","iopub.status.idle":"2023-08-05T03:01:42.094025Z","shell.execute_reply.started":"2023-08-05T03:01:42.079808Z","shell.execute_reply":"2023-08-05T03:01:42.092968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames[:10]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.096072Z","iopub.execute_input":"2023-08-05T03:01:42.096448Z","iopub.status.idle":"2023-08-05T03:01:42.104999Z","shell.execute_reply.started":"2023-08-05T03:01:42.096392Z","shell.execute_reply":"2023-08-05T03:01:42.103738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Displaying sample images from train","metadata":{}},{"cell_type":"code","source":"import cv2\nimport matplotlib.pyplot as plt\n# from google.colab.patches import cv2_imshow\nimg = cv2.imread('/kaggle/working/train/1.png')\nplt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.106892Z","iopub.execute_input":"2023-08-05T03:01:42.107300Z","iopub.status.idle":"2023-08-05T03:01:42.598189Z","shell.execute_reply.started":"2023-08-05T03:01:42.107264Z","shell.execute_reply":"2023-08-05T03:01:42.597151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_list = list(labels_df['id'])\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.599881Z","iopub.execute_input":"2023-08-05T03:01:42.600275Z","iopub.status.idle":"2023-08-05T03:01:42.615330Z","shell.execute_reply.started":"2023-08-05T03:01:42.600239Z","shell.execute_reply":"2023-08-05T03:01:42.614384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_list[:5]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.616589Z","iopub.execute_input":"2023-08-05T03:01:42.616905Z","iopub.status.idle":"2023-08-05T03:01:42.635076Z","shell.execute_reply.started":"2023-08-05T03:01:42.616880Z","shell.execute_reply":"2023-08-05T03:01:42.633316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Converting images to numpy array","metadata":{}},{"cell_type":"code","source":"train_data_folder = '/kaggle/working/train/'","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.636267Z","iopub.execute_input":"2023-08-05T03:01:42.636630Z","iopub.status.idle":"2023-08-05T03:01:42.647623Z","shell.execute_reply.started":"2023-08-05T03:01:42.636593Z","shell.execute_reply":"2023-08-05T03:01:42.646164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = []\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":{"execution":{"iopub.status.busy":"2023-08-05T03:01:42.649363Z","iopub.execute_input":"2023-08-05T03:01:42.650042Z","iopub.status.idle":"2023-08-05T03:01:51.725975Z","shell.execute_reply.started":"2023-08-05T03:01:42.650007Z","shell.execute_reply":"2023-08-05T03:01:51.724977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[:1]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.727478Z","iopub.execute_input":"2023-08-05T03:01:51.727912Z","iopub.status.idle":"2023-08-05T03:01:51.737481Z","shell.execute_reply.started":"2023-08-05T03:01:51.727879Z","shell.execute_reply":"2023-08-05T03:01:51.736302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(data)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.739257Z","iopub.execute_input":"2023-08-05T03:01:51.739661Z","iopub.status.idle":"2023-08-05T03:01:51.749529Z","shell.execute_reply.started":"2023-08-05T03:01:51.739624Z","shell.execute_reply":"2023-08-05T03:01:51.747752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(data[0])","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.751489Z","iopub.execute_input":"2023-08-05T03:01:51.751869Z","iopub.status.idle":"2023-08-05T03:01:51.763188Z","shell.execute_reply.started":"2023-08-05T03:01:51.751832Z","shell.execute_reply":"2023-08-05T03:01:51.762089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[0].shape #red-green-blue ---- 3\n#     3    32*32 matrix","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.764725Z","iopub.execute_input":"2023-08-05T03:01:51.765389Z","iopub.status.idle":"2023-08-05T03:01:51.775597Z","shell.execute_reply.started":"2023-08-05T03:01:51.765329Z","shell.execute_reply":"2023-08-05T03:01:51.774360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[0]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.783816Z","iopub.execute_input":"2023-08-05T03:01:51.784114Z","iopub.status.idle":"2023-08-05T03:01:51.794595Z","shell.execute_reply.started":"2023-08-05T03:01:51.784087Z","shell.execute_reply":"2023-08-05T03:01:51.793172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#converting image list and label list to numpy array","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.796293Z","iopub.execute_input":"2023-08-05T03:01:51.797096Z","iopub.status.idle":"2023-08-05T03:01:51.805952Z","shell.execute_reply.started":"2023-08-05T03:01:51.797056Z","shell.execute_reply":"2023-08-05T03:01:51.804467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = np.array(data)\nY = np.array(labels)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.807793Z","iopub.execute_input":"2023-08-05T03:01:51.808525Z","iopub.status.idle":"2023-08-05T03:01:51.907562Z","shell.execute_reply.started":"2023-08-05T03:01:51.808487Z","shell.execute_reply":"2023-08-05T03:01:51.906546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(X)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.908967Z","iopub.execute_input":"2023-08-05T03:01:51.909343Z","iopub.status.idle":"2023-08-05T03:01:51.916161Z","shell.execute_reply.started":"2023-08-05T03:01:51.909307Z","shell.execute_reply":"2023-08-05T03:01:51.915200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X.shape)\nprint(Y.shape)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.917851Z","iopub.execute_input":"2023-08-05T03:01:51.918597Z","iopub.status.idle":"2023-08-05T03:01:51.927481Z","shell.execute_reply.started":"2023-08-05T03:01:51.918562Z","shell.execute_reply":"2023-08-05T03:01:51.926384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[1]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.929117Z","iopub.execute_input":"2023-08-05T03:01:51.929494Z","iopub.status.idle":"2023-08-05T03:01:51.940860Z","shell.execute_reply.started":"2023-08-05T03:01:51.929461Z","shell.execute_reply":"2023-08-05T03:01:51.939521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(labels)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.942571Z","iopub.execute_input":"2023-08-05T03:01:51.943365Z","iopub.status.idle":"2023-08-05T03:01:51.953080Z","shell.execute_reply.started":"2023-08-05T03:01:51.943323Z","shell.execute_reply":"2023-08-05T03:01:51.951946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels[1]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.955041Z","iopub.execute_input":"2023-08-05T03:01:51.956215Z","iopub.status.idle":"2023-08-05T03:01:51.965083Z","shell.execute_reply.started":"2023-08-05T03:01:51.956176Z","shell.execute_reply":"2023-08-05T03:01:51.963934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.966703Z","iopub.execute_input":"2023-08-05T03:01:51.967911Z","iopub.status.idle":"2023-08-05T03:01:51.976674Z","shell.execute_reply.started":"2023-08-05T03:01:51.967872Z","shell.execute_reply":"2023-08-05T03:01:51.975486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.978271Z","iopub.execute_input":"2023-08-05T03:01:51.979581Z","iopub.status.idle":"2023-08-05T03:01:51.990199Z","shell.execute_reply.started":"2023-08-05T03:01:51.979541Z","shell.execute_reply":"2023-08-05T03:01:51.988885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":{"execution":{"iopub.status.busy":"2023-08-05T03:01:51.992046Z","iopub.execute_input":"2023-08-05T03:01:51.992626Z","iopub.status.idle":"2023-08-05T03:01:52.057357Z","shell.execute_reply.started":"2023-08-05T03:01:51.992588Z","shell.execute_reply":"2023-08-05T03:01:52.056284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:52.059013Z","iopub.execute_input":"2023-08-05T03:01:52.059403Z","iopub.status.idle":"2023-08-05T03:01:52.066309Z","shell.execute_reply.started":"2023-08-05T03:01:52.059363Z","shell.execute_reply":"2023-08-05T03:01:52.065178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_train.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:52.068001Z","iopub.execute_input":"2023-08-05T03:01:52.068728Z","iopub.status.idle":"2023-08-05T03:01:52.079665Z","shell.execute_reply.started":"2023-08-05T03:01:52.068691Z","shell.execute_reply":"2023-08-05T03:01:52.078550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#scalling the data \n\nX_train_scaled = X_train / 255\nX_test_scaled = X_test/255","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:52.081664Z","iopub.execute_input":"2023-08-05T03:01:52.082197Z","iopub.status.idle":"2023-08-05T03:01:52.487426Z","shell.execute_reply.started":"2023-08-05T03:01:52.082162Z","shell.execute_reply":"2023-08-05T03:01:52.486325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_scaled[0]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:52.488962Z","iopub.execute_input":"2023-08-05T03:01:52.490718Z","iopub.status.idle":"2023-08-05T03:01:52.501378Z","shell.execute_reply.started":"2023-08-05T03:01:52.490678Z","shell.execute_reply":"2023-08-05T03:01:52.500154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#building the neural Network","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:52.503280Z","iopub.execute_input":"2023-08-05T03:01:52.503701Z","iopub.status.idle":"2023-08-05T03:01:52.509556Z","shell.execute_reply.started":"2023-08-05T03:01:52.503664Z","shell.execute_reply":"2023-08-05T03:01:52.508294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras ","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:01:52.510944Z","iopub.execute_input":"2023-08-05T03:01:52.511829Z","iopub.status.idle":"2023-08-05T03:02:00.563732Z","shell.execute_reply.started":"2023-08-05T03:01:52.511793Z","shell.execute_reply":"2023-08-05T03:02:00.562478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_of_classes = 10 \n#setting up the layers of neural network\nmodel = keras.Sequential([\n    keras.layers.Flatten(input_shape = (32,32,3)),\n    keras.layers.Dense(64,activation = 'relu'),\n    keras.layers.Dense(num_of_classes,activation = 'softmax')\n])","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:02:00.565143Z","iopub.execute_input":"2023-08-05T03:02:00.567987Z","iopub.status.idle":"2023-08-05T03:02:03.568888Z","shell.execute_reply.started":"2023-08-05T03:02:00.567951Z","shell.execute_reply":"2023-08-05T03:02:03.567882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#compiling the neural_network\nmodel.compile(optimizer = 'adam',\n             loss = 'sparse_categorical_crossentropy',\n             metrics = ['acc'])\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:02:03.570263Z","iopub.execute_input":"2023-08-05T03:02:03.570629Z","iopub.status.idle":"2023-08-05T03:02:03.599952Z","shell.execute_reply.started":"2023-08-05T03:02:03.570592Z","shell.execute_reply":"2023-08-05T03:02:03.595579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#training the neural network\nmodel.fit(X_train_scaled,Y_train,validation_split = 0.1,epochs=10)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:02:03.601714Z","iopub.execute_input":"2023-08-05T03:02:03.602067Z","iopub.status.idle":"2023-08-05T03:02:43.191679Z","shell.execute_reply.started":"2023-08-05T03:02:03.602036Z","shell.execute_reply":"2023-08-05T03:02:43.190576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***RESNET 50***","metadata":{}},{"cell_type":"code","source":"from tensorflow.keras import Sequential,models,layers\nfrom tensorflow.keras.layers import Dense,Dropout,Flatten\nfrom tensorflow.keras.models import load_model\nfrom tensorflow.keras.layers import BatchNormalization\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.applications.resnet50 import ResNet50\n\nfrom tensorflow.keras import optimizers","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:02:43.193091Z","iopub.execute_input":"2023-08-05T03:02:43.193738Z","iopub.status.idle":"2023-08-05T03:02:43.204220Z","shell.execute_reply.started":"2023-08-05T03:02:43.193697Z","shell.execute_reply":"2023-08-05T03:02:43.203144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"convolutional_base = ResNet50(weights='imagenet',include_top=False,input_shape=(256,256,3))","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:03:33.939811Z","iopub.execute_input":"2023-08-05T03:03:33.940180Z","iopub.status.idle":"2023-08-05T03:03:36.361805Z","shell.execute_reply.started":"2023-08-05T03:03:33.940152Z","shell.execute_reply":"2023-08-05T03:03:36.360723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"convolutional_base.summary()","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:06:25.057179Z","iopub.execute_input":"2023-08-05T03:06:25.057595Z","iopub.status.idle":"2023-08-05T03:06:25.479034Z","shell.execute_reply.started":"2023-08-05T03:06:25.057561Z","shell.execute_reply":"2023-08-05T03:06:25.478196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_of_classes = 10\nmodel = models.Sequential()\nmodel.add(layers.UpSampling2D((2,2)))\nmodel.add(layers.UpSampling2D((2,2)))\nmodel.add(layers.UpSampling2D((2,2)))\nmodel.add(convolutional_base)\nmodel.add(layers.Flatten())\nmodel.add(layers.BatchNormalization())\nmodel.add(layers.Dense(128,activation = 'relu'))\nmodel.add(layers.Dropout(0.5))\nmodel.add(layers.BatchNormalization())\nmodel.add(layers.Dense(64,activation = 'relu'))\nmodel.add(layers.Dropout(0.5))\nmodel.add(layers.BatchNormalization())\nmodel.add(layers.Dense(num_of_classes,activation = 'softmax'))","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:19:31.642838Z","iopub.execute_input":"2023-08-05T03:19:31.643275Z","iopub.status.idle":"2023-08-05T03:19:31.703772Z","shell.execute_reply.started":"2023-08-05T03:19:31.643242Z","shell.execute_reply":"2023-08-05T03:19:31.702757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer = optimizers.RMSprop(lr = 2e-5), loss ='sparse_categorical_crossentropy',metrics = ['acc'])","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:25:47.623134Z","iopub.execute_input":"2023-08-05T03:25:47.623573Z","iopub.status.idle":"2023-08-05T03:25:47.644485Z","shell.execute_reply.started":"2023-08-05T03:25:47.623541Z","shell.execute_reply":"2023-08-05T03:25:47.643470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(X_train_scaled,Y_train,validation_split=0.1,epochs = 10)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T03:26:50.184127Z","iopub.execute_input":"2023-08-05T03:26:50.184576Z","iopub.status.idle":"2023-08-05T04:07:26.927909Z","shell.execute_reply.started":"2023-08-05T03:26:50.184540Z","shell.execute_reply":"2023-08-05T04:07:26.926687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h = history \n#plot the loss function \nplt.plot(h.history['loss'],label = 'train loss')\nplt.plot(h.history['val_loss'],label = 'validation loss')\nplt.legend()\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:07:27.700628Z","iopub.execute_input":"2023-08-05T04:07:27.701050Z","iopub.status.idle":"2023-08-05T04:07:28.018467Z","shell.execute_reply.started":"2023-08-05T04:07:27.701012Z","shell.execute_reply":"2023-08-05T04:07:28.017424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plot the accuracy value\nplt.plot(h.history['acc'],label = 'train accuracy')\nplt.plot(h.history['val_acc'],label = 'validation accuracy')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:17:39.484732Z","iopub.execute_input":"2023-08-05T04:17:39.485117Z","iopub.status.idle":"2023-08-05T04:17:39.764369Z","shell.execute_reply.started":"2023-08-05T04:17:39.485084Z","shell.execute_reply":"2023-08-05T04:17:39.763363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(history)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:28:16.314678Z","iopub.execute_input":"2023-08-05T04:28:16.315087Z","iopub.status.idle":"2023-08-05T04:28:16.322233Z","shell.execute_reply.started":"2023-08-05T04:28:16.315056Z","shell.execute_reply":"2023-08-05T04:28:16.321251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(X_test_scaled)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:29:21.753443Z","iopub.execute_input":"2023-08-05T04:29:21.753828Z","iopub.status.idle":"2023-08-05T04:29:41.142910Z","shell.execute_reply.started":"2023-08-05T04:29:21.753799Z","shell.execute_reply":"2023-08-05T04:29:41.141903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:30:00.866958Z","iopub.execute_input":"2023-08-05T04:30:00.867534Z","iopub.status.idle":"2023-08-05T04:30:00.874533Z","shell.execute_reply.started":"2023-08-05T04:30:00.867501Z","shell.execute_reply":"2023-08-05T04:30:00.873525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(predictions)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:30:25.238556Z","iopub.execute_input":"2023-08-05T04:30:25.238934Z","iopub.status.idle":"2023-08-05T04:30:25.245388Z","shell.execute_reply.started":"2023-08-05T04:30:25.238904Z","shell.execute_reply":"2023-08-05T04:30:25.244355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions[0]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:30:44.099853Z","iopub.execute_input":"2023-08-05T04:30:44.100579Z","iopub.status.idle":"2023-08-05T04:30:44.108544Z","shell.execute_reply.started":"2023-08-05T04:30:44.100539Z","shell.execute_reply":"2023-08-05T04:30:44.107470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.argmax(predictions[0])","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:33:47.994348Z","iopub.execute_input":"2023-08-05T04:33:47.995344Z","iopub.status.idle":"2023-08-05T04:33:48.002065Z","shell.execute_reply.started":"2023-08-05T04:33:47.995310Z","shell.execute_reply":"2023-08-05T04:33:48.001012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_values_one = [np.argmax(i) for i in predictions]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:35:10.224001Z","iopub.execute_input":"2023-08-05T04:35:10.224433Z","iopub.status.idle":"2023-08-05T04:35:10.278585Z","shell.execute_reply.started":"2023-08-05T04:35:10.224382Z","shell.execute_reply":"2023-08-05T04:35:10.277461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(predicted_values_one)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:35:37.268822Z","iopub.execute_input":"2023-08-05T04:35:37.269199Z","iopub.status.idle":"2023-08-05T04:35:37.276032Z","shell.execute_reply.started":"2023-08-05T04:35:37.269166Z","shell.execute_reply":"2023-08-05T04:35:37.274982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np_array_predictions_one = np.array(predicted_values_one)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:37:36.453477Z","iopub.execute_input":"2023-08-05T04:37:36.453875Z","iopub.status.idle":"2023-08-05T04:37:36.459377Z","shell.execute_reply.started":"2023-08-05T04:37:36.453845Z","shell.execute_reply":"2023-08-05T04:37:36.458452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create an array of indices corresponding to the elements in the list\nindices = np.arange(len(np_array_predictions_one))\n\n# Use numpy's column_stack function to append the index column to the array\nnp_array_predictions_one_with_indez = np.column_stack((indices, np_array_predictions_one))","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:38:39.431704Z","iopub.execute_input":"2023-08-05T04:38:39.432127Z","iopub.status.idle":"2023-08-05T04:38:39.437427Z","shell.execute_reply.started":"2023-08-05T04:38:39.432096Z","shell.execute_reply":"2023-08-05T04:38:39.436485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np_array_predictions_one_with_indez","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:38:48.237314Z","iopub.execute_input":"2023-08-05T04:38:48.237716Z","iopub.status.idle":"2023-08-05T04:38:48.244872Z","shell.execute_reply.started":"2023-08-05T04:38:48.237679Z","shell.execute_reply":"2023-08-05T04:38:48.243856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_array = np_array_predictions_one_with_indez","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:39:04.622079Z","iopub.execute_input":"2023-08-05T04:39:04.622491Z","iopub.status.idle":"2023-08-05T04:39:04.627495Z","shell.execute_reply.started":"2023-08-05T04:39:04.622458Z","shell.execute_reply":"2023-08-05T04:39:04.626533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_array.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-05T04:42:44.008055Z","iopub.execute_input":"2023-08-05T04:42:44.008458Z","iopub.status.idle":"2023-08-05T04:42:44.014395Z","shell.execute_reply.started":"2023-08-05T04:42:44.008418Z","shell.execute_reply":"2023-08-05T04:42:44.013480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}