{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":3649,"databundleVersionId":46718,"sourceType":"competition"}],"dockerImageVersionId":30699,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-05T19:01:39.995286Z","iopub.execute_input":"2024-05-05T19:01:39.996015Z","iopub.status.idle":"2024-05-05T19:01:41.958495Z","shell.execute_reply.started":"2024-05-05T19:01:39.995984Z","shell.execute_reply":"2024-05-05T19:01:41.957479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df = pd.read_csv('/kaggle/input/cifar-10/trainLabels.csv')\nlabels_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:41.962605Z","iopub.execute_input":"2024-05-05T19:01:41.963040Z","iopub.status.idle":"2024-05-05T19:01:42.009890Z","shell.execute_reply.started":"2024-05-05T19:01:41.963006Z","shell.execute_reply":"2024-05-05T19:01:42.008972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:42.011232Z","iopub.execute_input":"2024-05-05T19:01:42.012136Z","iopub.status.idle":"2024-05-05T19:01:42.030090Z","shell.execute_reply.started":"2024-05-05T19:01:42.012098Z","shell.execute_reply":"2024-05-05T19:01:42.028806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df[labels_df['id'] == 7796]","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:42.032612Z","iopub.execute_input":"2024-05-05T19:01:42.033529Z","iopub.status.idle":"2024-05-05T19:01:42.046695Z","shell.execute_reply.started":"2024-05-05T19:01:42.033494Z","shell.execute_reply":"2024-05-05T19:01:42.045730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:42.048294Z","iopub.execute_input":"2024-05-05T19:01:42.048660Z","iopub.status.idle":"2024-05-05T19:01:42.059288Z","shell.execute_reply.started":"2024-05-05T19:01:42.048628Z","shell.execute_reply":"2024-05-05T19:01:42.058281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.tail(10)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:42.060647Z","iopub.execute_input":"2024-05-05T19:01:42.061069Z","iopub.status.idle":"2024-05-05T19:01:42.073433Z","shell.execute_reply.started":"2024-05-05T19:01:42.061039Z","shell.execute_reply":"2024-05-05T19:01:42.072367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:42.075658Z","iopub.execute_input":"2024-05-05T19:01:42.076063Z","iopub.status.idle":"2024-05-05T19:01:42.098883Z","shell.execute_reply.started":"2024-05-05T19:01:42.076018Z","shell.execute_reply":"2024-05-05T19:01:42.097838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df['label']","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:42.100128Z","iopub.execute_input":"2024-05-05T19:01:42.100414Z","iopub.status.idle":"2024-05-05T19:01:42.108204Z","shell.execute_reply.started":"2024-05-05T19:01:42.100391Z","shell.execute_reply":"2024-05-05T19:01:42.107167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_dirctionary = {'airplane':0, 'automobile':1, 'bird':2, 'cat':3, 'deer':4, 'dog':5, 'frog':6, 'horse':7, 'ship':8, 'truck':9}\n\nlabels = [labels_dirctionary[i] for i in labels_df['label']]\n\nprint(labels[0:5])\nprint(labels[-5:])","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:42.109222Z","iopub.execute_input":"2024-05-05T19:01:42.109552Z","iopub.status.idle":"2024-05-05T19:01:42.132440Z","shell.execute_reply.started":"2024-05-05T19:01:42.109519Z","shell.execute_reply":"2024-05-05T19:01:42.131396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install py7zr","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:01:42.136692Z","iopub.execute_input":"2024-05-05T19:01:42.137032Z","iopub.status.idle":"2024-05-05T19:02:08.191851Z","shell.execute_reply.started":"2024-05-05T19:01:42.137004Z","shell.execute_reply":"2024-05-05T19:02:08.190739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import py7zr\n\n# Path to the .7z file\nfile_path = '/kaggle/input/cifar-10/train.7z'\n\n# Destination directory to extract the files\noutput_dir = '/kaggle/working/'\n\n# Extract the files\nwith py7zr.SevenZipFile(file_path, mode='r') as z:\n    z.extractall(output_dir)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:02:08.193331Z","iopub.execute_input":"2024-05-05T19:02:08.193708Z","iopub.status.idle":"2024-05-05T19:02:33.974884Z","shell.execute_reply.started":"2024-05-05T19:02:08.193669Z","shell.execute_reply":"2024-05-05T19:02:33.973877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import py7zr\n\n# Path to the .7z file\nfile_path = '/kaggle/input/cifar-10/test.7z'\n\n# Destination directory to extract the files\noutput_dir = '/kaggle/working/'\n\n# Extract the files\nwith py7zr.SevenZipFile(file_path, mode='r') as z:\n    z.extractall(output_dir)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:02:33.976446Z","iopub.execute_input":"2024-05-05T19:02:33.976751Z","iopub.status.idle":"2024-05-05T19:05:32.867015Z","shell.execute_reply.started":"2024-05-05T19:02:33.976725Z","shell.execute_reply":"2024-05-05T19:05:32.865956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# displaying sample image\nimport cv2\n\ndef cv2_imshow(image):\n    plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n    plt.axis('off')\n    plt.show()\n\nimg_path = '/kaggle/working/train/1.png'\nimg = cv2.imread(img_path)\n\nif img is not None:\n    cv2_imshow(img)\nelse:\n    print(f\"Unable to read image at {img_path}\")","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:32.868138Z","iopub.execute_input":"2024-05-05T19:05:32.868402Z","iopub.status.idle":"2024-05-05T19:05:33.102405Z","shell.execute_reply.started":"2024-05-05T19:05:32.868379Z","shell.execute_reply":"2024-05-05T19:05:33.101199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df[labels_df['id']==37186]","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:33.104557Z","iopub.execute_input":"2024-05-05T19:05:33.105423Z","iopub.status.idle":"2024-05-05T19:05:33.122825Z","shell.execute_reply.started":"2024-05-05T19:05:33.105376Z","shell.execute_reply":"2024-05-05T19:05:33.121747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_list = list(labels_df['id'])\nprint(id_list[0:5])\nprint(id_list[-5:])","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:33.124939Z","iopub.execute_input":"2024-05-05T19:05:33.125831Z","iopub.status.idle":"2024-05-05T19:05:33.149564Z","shell.execute_reply.started":"2024-05-05T19:05:33.125787Z","shell.execute_reply":"2024-05-05T19:05:33.148118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# convert images to numpy arrays\ntrain_data_folder = '/kaggle/working/train/'\ndata = []\n\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":"2024-05-05T19:05:33.152139Z","iopub.execute_input":"2024-05-05T19:05:33.153360Z","iopub.status.idle":"2024-05-05T19:05:42.317494Z","shell.execute_reply.started":"2024-05-05T19:05:33.153314Z","shell.execute_reply":"2024-05-05T19:05:42.316724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(data)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.318590Z","iopub.execute_input":"2024-05-05T19:05:42.318861Z","iopub.status.idle":"2024-05-05T19:05:42.324808Z","shell.execute_reply.started":"2024-05-05T19:05:42.318837Z","shell.execute_reply":"2024-05-05T19:05:42.323897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(data)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.326121Z","iopub.execute_input":"2024-05-05T19:05:42.326514Z","iopub.status.idle":"2024-05-05T19:05:42.335847Z","shell.execute_reply.started":"2024-05-05T19:05:42.326484Z","shell.execute_reply":"2024-05-05T19:05:42.334960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(data[0])","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.336956Z","iopub.execute_input":"2024-05-05T19:05:42.337326Z","iopub.status.idle":"2024-05-05T19:05:42.346940Z","shell.execute_reply.started":"2024-05-05T19:05:42.337303Z","shell.execute_reply":"2024-05-05T19:05:42.346210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[0].shape","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.347896Z","iopub.execute_input":"2024-05-05T19:05:42.348177Z","iopub.status.idle":"2024-05-05T19:05:42.358615Z","shell.execute_reply.started":"2024-05-05T19:05:42.348156Z","shell.execute_reply":"2024-05-05T19:05:42.357808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[0]","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.359600Z","iopub.execute_input":"2024-05-05T19:05:42.360076Z","iopub.status.idle":"2024-05-05T19:05:42.370826Z","shell.execute_reply.started":"2024-05-05T19:05:42.360052Z","shell.execute_reply":"2024-05-05T19:05:42.369937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# convert image list and label list to numpy arrays\nX = np.array(data)\nY = np.array(labels)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.371972Z","iopub.execute_input":"2024-05-05T19:05:42.372353Z","iopub.status.idle":"2024-05-05T19:05:42.467361Z","shell.execute_reply.started":"2024-05-05T19:05:42.372324Z","shell.execute_reply":"2024-05-05T19:05:42.466608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(X)\nprint(X.shape)\nprint(Y.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.468557Z","iopub.execute_input":"2024-05-05T19:05:42.468888Z","iopub.status.idle":"2024-05-05T19:05:42.474036Z","shell.execute_reply.started":"2024-05-05T19:05:42.468856Z","shell.execute_reply":"2024-05-05T19:05:42.473102Z"},"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)\nprint(X.shape, X_train.shape, X_test.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.475137Z","iopub.execute_input":"2024-05-05T19:05:42.475390Z","iopub.status.idle":"2024-05-05T19:05:42.541255Z","shell.execute_reply.started":"2024-05-05T19:05:42.475367Z","shell.execute_reply":"2024-05-05T19:05:42.540322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# scaling the data\n# 0 --> 0 , 255 --> 1\nX_train_scaled = X_train/255\nX_test_scaled = X_test/255","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.542566Z","iopub.execute_input":"2024-05-05T19:05:42.543005Z","iopub.status.idle":"2024-05-05T19:05:42.916678Z","shell.execute_reply.started":"2024-05-05T19:05:42.542972Z","shell.execute_reply":"2024-05-05T19:05:42.915889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_scaled","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.917737Z","iopub.execute_input":"2024-05-05T19:05:42.918035Z","iopub.status.idle":"2024-05-05T19:05:42.932196Z","shell.execute_reply.started":"2024-05-05T19:05:42.918005Z","shell.execute_reply":"2024-05-05T19:05:42.931389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:42.933229Z","iopub.execute_input":"2024-05-05T19:05:42.933519Z","iopub.status.idle":"2024-05-05T19:05:53.885974Z","shell.execute_reply.started":"2024-05-05T19:05:42.933495Z","shell.execute_reply":"2024-05-05T19:05:53.885146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_of_classes = 10\n\n# setting up the layers of neural networks\n\nmodel = keras.Sequential([\n    \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":"2024-05-05T19:05:53.892222Z","iopub.execute_input":"2024-05-05T19:05:53.892974Z","iopub.status.idle":"2024-05-05T19:05:54.582122Z","shell.execute_reply.started":"2024-05-05T19:05:53.892945Z","shell.execute_reply":"2024-05-05T19:05:54.581143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# compile the neural network\nmodel.compile(optimizer='adam',\n             loss='sparse_categorical_crossentropy',\n             metrics=['acc'])","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:54.583284Z","iopub.execute_input":"2024-05-05T19:05:54.583584Z","iopub.status.idle":"2024-05-05T19:05:54.596682Z","shell.execute_reply.started":"2024-05-05T19:05:54.583558Z","shell.execute_reply":"2024-05-05T19:05:54.595774Z"},"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)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:05:54.597703Z","iopub.execute_input":"2024-05-05T19:05:54.598033Z","iopub.status.idle":"2024-05-05T19:06:18.047086Z","shell.execute_reply.started":"2024-05-05T19:05:54.598009Z","shell.execute_reply":"2024-05-05T19:06:18.046183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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.applications.efficientnet import EfficientNetB0\nfrom tensorflow.keras import optimizers","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:06:18.048261Z","iopub.execute_input":"2024-05-05T19:06:18.048549Z","iopub.status.idle":"2024-05-05T19:06:18.058807Z","shell.execute_reply.started":"2024-05-05T19:06:18.048519Z","shell.execute_reply":"2024-05-05T19:06:18.057951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"convolutional_base = ResNet50(weights='imagenet', include_top=False, input_shape=(256,256,3))\nconvolutional_base.summary()","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:06:18.059975Z","iopub.execute_input":"2024-05-05T19:06:18.060307Z","iopub.status.idle":"2024-05-05T19:06:20.364842Z","shell.execute_reply.started":"2024-05-05T19:06:18.060275Z","shell.execute_reply":"2024-05-05T19:06:20.364002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_of_classes = 10\n\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":"2024-05-05T19:06:20.366021Z","iopub.execute_input":"2024-05-05T19:06:20.366301Z","iopub.status.idle":"2024-05-05T19:06:20.384897Z","shell.execute_reply.started":"2024-05-05T19:06:20.366276Z","shell.execute_reply":"2024-05-05T19:06:20.384095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=optimizers.RMSprop(learning_rate=2e-5), loss='sparse_categorical_crossentropy', metrics=['acc'])","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:06:20.386253Z","iopub.execute_input":"2024-05-05T19:06:20.386550Z","iopub.status.idle":"2024-05-05T19:06:20.415740Z","shell.execute_reply.started":"2024-05-05T19:06:20.386525Z","shell.execute_reply":"2024-05-05T19:06:20.414913Z"},"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":"2024-05-05T19:06:20.416747Z","iopub.execute_input":"2024-05-05T19:06:20.417028Z","iopub.status.idle":"2024-05-05T19:40:03.039114Z","shell.execute_reply.started":"2024-05-05T19:06:20.417006Z","shell.execute_reply":"2024-05-05T19:40:03.038228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loss, accuracy = model.evaluate(X_test_scaled, Y_test)\nprint('Test Accuracy =', accuracy)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:40:03.040594Z","iopub.execute_input":"2024-05-05T19:40:03.040890Z","iopub.status.idle":"2024-05-05T19:40:27.494971Z","shell.execute_reply.started":"2024-05-05T19:40:03.040864Z","shell.execute_reply":"2024-05-05T19:40:27.494146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h = history\n\n# plot the loss value\nplt.plot(h.history['loss'],label='train loss')\nplt.plot(h.history['val_loss'],label='validation loss')\nplt.legend()\nplt.show()\n\n# 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":"2024-05-05T19:40:27.496159Z","iopub.execute_input":"2024-05-05T19:40:27.496443Z","iopub.status.idle":"2024-05-05T19:40:27.930593Z","shell.execute_reply.started":"2024-05-05T19:40:27.496418Z","shell.execute_reply":"2024-05-05T19:40:27.929710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('/kaggle/working/resnet_trained_model.keras')","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:40:27.931722Z","iopub.execute_input":"2024-05-05T19:40:27.932022Z","iopub.status.idle":"2024-05-05T19:40:29.494298Z","shell.execute_reply.started":"2024-05-05T19:40:27.931996Z","shell.execute_reply":"2024-05-05T19:40:29.493384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"convolutional_base_model_1 = EfficientNetB0(weights='imagenet', include_top=False, input_shape=(256, 256, 3))\nconvolutional_base_model_1.summary()","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:40:29.495668Z","iopub.execute_input":"2024-05-05T19:40:29.496310Z","iopub.status.idle":"2024-05-05T19:40:31.360443Z","shell.execute_reply.started":"2024-05-05T19:40:29.496275Z","shell.execute_reply":"2024-05-05T19:40:31.359619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_of_classes = 10\n\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_model_1)\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":"2024-05-05T19:40:31.361674Z","iopub.execute_input":"2024-05-05T19:40:31.362216Z","iopub.status.idle":"2024-05-05T19:40:31.383212Z","shell.execute_reply.started":"2024-05-05T19:40:31.362183Z","shell.execute_reply":"2024-05-05T19:40:31.382371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=optimizers.RMSprop(learning_rate=2e-5), loss='sparse_categorical_crossentropy', metrics=['acc'])","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:40:31.384357Z","iopub.execute_input":"2024-05-05T19:40:31.384760Z","iopub.status.idle":"2024-05-05T19:40:31.400418Z","shell.execute_reply.started":"2024-05-05T19:40:31.384729Z","shell.execute_reply":"2024-05-05T19:40:31.399689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_model_1 = model.fit(X_train_scaled, Y_train, validation_split=0.1, epochs=10)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T19:40:31.401604Z","iopub.execute_input":"2024-05-05T19:40:31.402113Z","iopub.status.idle":"2024-05-05T20:07:15.958133Z","shell.execute_reply.started":"2024-05-05T19:40:31.402081Z","shell.execute_reply":"2024-05-05T20:07:15.957294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loss_model_1, accuracy_model_1 = model.evaluate(X_test_scaled, Y_test)\nprint('Test Accuracy =', accuracy_model_1)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T20:07:15.959619Z","iopub.execute_input":"2024-05-05T20:07:15.959941Z","iopub.status.idle":"2024-05-05T20:07:37.777512Z","shell.execute_reply.started":"2024-05-05T20:07:15.959886Z","shell.execute_reply":"2024-05-05T20:07:37.776511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h = history_model_1\n\n# plot the loss value\nplt.plot(h.history['loss'],label='train loss')\nplt.plot(h.history['val_loss'],label='validation loss')\nplt.legend()\nplt.show()\n\n# 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":"2024-05-05T20:07:37.778580Z","iopub.execute_input":"2024-05-05T20:07:37.778868Z","iopub.status.idle":"2024-05-05T20:07:38.253012Z","shell.execute_reply.started":"2024-05-05T20:07:37.778842Z","shell.execute_reply":"2024-05-05T20:07:38.252080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('/kaggle/working/efficientnet_trained_model.keras')","metadata":{"execution":{"iopub.status.busy":"2024-05-05T20:07:38.254138Z","iopub.execute_input":"2024-05-05T20:07:38.254410Z","iopub.status.idle":"2024-05-05T20:07:39.270380Z","shell.execute_reply.started":"2024-05-05T20:07:38.254386Z","shell.execute_reply":"2024-05-05T20:07:39.269284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications import MobileNet\nconvolutional_base_model_2 = MobileNet(weights='imagenet', include_top=False, input_shape=(256, 256, 3))\nconvolutional_base_model_2.summary()","metadata":{"execution":{"iopub.status.busy":"2024-05-05T20:10:03.635713Z","iopub.execute_input":"2024-05-05T20:10:03.636365Z","iopub.status.idle":"2024-05-05T20:10:04.420243Z","shell.execute_reply.started":"2024-05-05T20:10:03.636332Z","shell.execute_reply":"2024-05-05T20:10:04.419385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_of_classes = 10\n\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_model_2)\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":"2024-05-05T20:10:41.878467Z","iopub.execute_input":"2024-05-05T20:10:41.878838Z","iopub.status.idle":"2024-05-05T20:10:41.899086Z","shell.execute_reply.started":"2024-05-05T20:10:41.878807Z","shell.execute_reply":"2024-05-05T20:10:41.898179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=optimizers.RMSprop(learning_rate=2e-5), loss='sparse_categorical_crossentropy', metrics=['acc'])","metadata":{"execution":{"iopub.status.busy":"2024-05-05T20:10:46.881066Z","iopub.execute_input":"2024-05-05T20:10:46.881670Z","iopub.status.idle":"2024-05-05T20:10:46.890571Z","shell.execute_reply.started":"2024-05-05T20:10:46.881639Z","shell.execute_reply":"2024-05-05T20:10:46.889868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_model_2 = model.fit(X_train_scaled, Y_train, validation_split=0.1, epochs=10)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T20:10:50.312291Z","iopub.execute_input":"2024-05-05T20:10:50.312873Z","iopub.status.idle":"2024-05-05T20:27:19.047714Z","shell.execute_reply.started":"2024-05-05T20:10:50.312842Z","shell.execute_reply":"2024-05-05T20:27:19.046648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loss_model_2, accuracy_model_2 = model.evaluate(X_test_scaled, Y_test)\nprint('Test Accuracy =', accuracy_model_1)","metadata":{"execution":{"iopub.status.busy":"2024-05-05T20:27:30.289506Z","iopub.execute_input":"2024-05-05T20:27:30.289828Z","iopub.status.idle":"2024-05-05T20:27:36.639213Z","shell.execute_reply.started":"2024-05-05T20:27:30.289802Z","shell.execute_reply":"2024-05-05T20:27:36.638272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h = history_model_2\n\n# plot the loss value\nplt.plot(h.history['loss'],label='train loss')\nplt.plot(h.history['val_loss'],label='validation loss')\nplt.legend()\nplt.show()\n\n# 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":"2024-05-05T20:27:36.641575Z","iopub.execute_input":"2024-05-05T20:27:36.642236Z","iopub.status.idle":"2024-05-05T20:27:37.128690Z","shell.execute_reply.started":"2024-05-05T20:27:36.642200Z","shell.execute_reply":"2024-05-05T20:27:37.127775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('/kaggle/working/mobilenet_trained_model.keras')","metadata":{"execution":{"iopub.status.busy":"2024-05-05T20:27:37.129941Z","iopub.execute_input":"2024-05-05T20:27:37.130311Z","iopub.status.idle":"2024-05-05T20:27:37.699413Z","shell.execute_reply.started":"2024-05-05T20:27:37.130273Z","shell.execute_reply":"2024-05-05T20:27:37.698567Z"},"trusted":true},"execution_count":null,"outputs":[]}]}