{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","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":30762,"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-09-05T10:03:56.543070Z","iopub.execute_input":"2024-09-05T10:03:56.543922Z","iopub.status.idle":"2024-09-05T10:03:57.519041Z","shell.execute_reply.started":"2024-09-05T10:03:56.543880Z","shell.execute_reply":"2024-09-05T10:03:57.518203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install py7zr","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:03:57.520949Z","iopub.execute_input":"2024-09-05T10:03:57.521525Z","iopub.status.idle":"2024-09-05T10:04:13.776664Z","shell.execute_reply.started":"2024-09-05T10:03:57.521480Z","shell.execute_reply":"2024-09-05T10:04:13.775642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import py7zr\n\narchive = py7zr.SevenZipFile('/kaggle/input/cifar-10/train.7z', mode='r')\narchive.extractall()     #archive.extractall(path='/content/Training Data')\narchive.close()","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:13.778231Z","iopub.execute_input":"2024-09-05T10:04:13.778662Z","iopub.status.idle":"2024-09-05T10:04:39.610677Z","shell.execute_reply.started":"2024-09-05T10:04:13.778614Z","shell.execute_reply":"2024-09-05T10:04:39.609808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:39.613167Z","iopub.execute_input":"2024-09-05T10:04:39.613558Z","iopub.status.idle":"2024-09-05T10:04:40.611786Z","shell.execute_reply.started":"2024-09-05T10:04:39.613512Z","shell.execute_reply":"2024-09-05T10:04:40.610619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames = os.listdir('train')","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.613364Z","iopub.execute_input":"2024-09-05T10:04:40.613733Z","iopub.status.idle":"2024-09-05T10:04:40.646238Z","shell.execute_reply.started":"2024-09-05T10:04:40.613698Z","shell.execute_reply":"2024-09-05T10:04:40.645538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(filenames)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.647659Z","iopub.execute_input":"2024-09-05T10:04:40.648040Z","iopub.status.idle":"2024-09-05T10:04:40.655222Z","shell.execute_reply.started":"2024-09-05T10:04:40.647999Z","shell.execute_reply":"2024-09-05T10:04:40.654358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(filenames)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.656506Z","iopub.execute_input":"2024-09-05T10:04:40.656873Z","iopub.status.idle":"2024-09-05T10:04:40.665862Z","shell.execute_reply.started":"2024-09-05T10:04:40.656832Z","shell.execute_reply":"2024-09-05T10:04:40.664963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(filenames[:10])\nprint(filenames[-10:])","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.667846Z","iopub.execute_input":"2024-09-05T10:04:40.668123Z","iopub.status.idle":"2024-09-05T10:04:40.675737Z","shell.execute_reply.started":"2024-09-05T10:04:40.668093Z","shell.execute_reply":"2024-09-05T10:04:40.674903Z"},"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":"2024-09-05T10:04:40.676796Z","iopub.execute_input":"2024-09-05T10:04:40.677088Z","iopub.status.idle":"2024-09-05T10:04:40.723543Z","shell.execute_reply.started":"2024-09-05T10:04:40.677057Z","shell.execute_reply":"2024-09-05T10:04:40.722632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.727969Z","iopub.execute_input":"2024-09-05T10:04:40.728230Z","iopub.status.idle":"2024-09-05T10:04:40.734053Z","shell.execute_reply.started":"2024-09-05T10:04:40.728202Z","shell.execute_reply":"2024-09-05T10:04:40.733093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.735151Z","iopub.execute_input":"2024-09-05T10:04:40.735446Z","iopub.status.idle":"2024-09-05T10:04:40.757354Z","shell.execute_reply.started":"2024-09-05T10:04:40.735416Z","shell.execute_reply":"2024-09-05T10:04:40.756504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.tail(10)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.758301Z","iopub.execute_input":"2024-09-05T10:04:40.758555Z","iopub.status.idle":"2024-09-05T10:04:40.767097Z","shell.execute_reply.started":"2024-09-05T10:04:40.758526Z","shell.execute_reply":"2024-09-05T10:04:40.766223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df[labels_df['id'] == 7796]","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.768184Z","iopub.execute_input":"2024-09-05T10:04:40.768489Z","iopub.status.idle":"2024-09-05T10:04:40.784215Z","shell.execute_reply.started":"2024-09-05T10:04:40.768458Z","shell.execute_reply":"2024-09-05T10:04:40.783337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.785212Z","iopub.execute_input":"2024-09-05T10:04:40.785497Z","iopub.status.idle":"2024-09-05T10:04:40.810571Z","shell.execute_reply.started":"2024-09-05T10:04:40.785468Z","shell.execute_reply":"2024-09-05T10:04:40.809683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df['label'].value_counts().plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:40.811889Z","iopub.execute_input":"2024-09-05T10:04:40.812610Z","iopub.status.idle":"2024-09-05T10:04:41.125394Z","shell.execute_reply.started":"2024-09-05T10:04:40.812561Z","shell.execute_reply":"2024-09-05T10:04:41.124416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df['label']","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:41.126509Z","iopub.execute_input":"2024-09-05T10:04:41.126813Z","iopub.status.idle":"2024-09-05T10:04:41.134940Z","shell.execute_reply.started":"2024-09-05T10:04:41.126781Z","shell.execute_reply":"2024-09-05T10:04:41.134036Z"},"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}\n\nlabels = [labels_dictionary[i] for i in labels_df['label']]","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:41.136236Z","iopub.execute_input":"2024-09-05T10:04:41.136584Z","iopub.status.idle":"2024-09-05T10:04:41.156075Z","shell.execute_reply.started":"2024-09-05T10:04:41.136551Z","shell.execute_reply":"2024-09-05T10:04:41.155236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(labels[0:5])\nprint(labels[-5:])","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:04:41.157185Z","iopub.execute_input":"2024-09-05T10:04:41.157552Z","iopub.status.idle":"2024-09-05T10:04:41.166142Z","shell.execute_reply.started":"2024-09-05T10:04:41.157521Z","shell.execute_reply":"2024-09-05T10:04:41.165318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\n# Load the image\nimg = cv2.imread('train/7796.png')\n\n# Convert the image from BGR (OpenCV format) to RGB (for displaying with matplotlib)\nimg_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n# Display the image using matplotlib\nplt.imshow(img_rgb)\nplt.axis('off')  # Hide axis\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:26.461841Z","iopub.execute_input":"2024-09-05T10:05:26.462248Z","iopub.status.idle":"2024-09-05T10:05:26.721132Z","shell.execute_reply.started":"2024-09-05T10:05:26.462211Z","shell.execute_reply":"2024-09-05T10:05:26.719808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# Load the image\nimg = cv2.imread('train/10.png')\n\n# Convert the image from BGR (OpenCV format) to RGB (for displaying with matplotlib)\nimg_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n# Display the image using matplotlib\nplt.imshow(img_rgb)\nplt.axis('off')  # Hide axis\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:29.982126Z","iopub.execute_input":"2024-09-05T10:05:29.982632Z","iopub.status.idle":"2024-09-05T10:05:30.061766Z","shell.execute_reply.started":"2024-09-05T10:05:29.982583Z","shell.execute_reply":"2024-09-05T10:05:30.060375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df[labels_df['id']== 10]","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:30.284620Z","iopub.execute_input":"2024-09-05T10:05:30.284955Z","iopub.status.idle":"2024-09-05T10:05:30.295308Z","shell.execute_reply.started":"2024-09-05T10:05:30.284921Z","shell.execute_reply":"2024-09-05T10:05:30.294130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:30.530886Z","iopub.execute_input":"2024-09-05T10:05:30.531583Z","iopub.status.idle":"2024-09-05T10:05:30.542691Z","shell.execute_reply.started":"2024-09-05T10:05:30.531525Z","shell.execute_reply":"2024-09-05T10:05:30.541680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_list = list(labels_df['id'])","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:30.773985Z","iopub.execute_input":"2024-09-05T10:05:30.774407Z","iopub.status.idle":"2024-09-05T10:05:30.786728Z","shell.execute_reply.started":"2024-09-05T10:05:30.774369Z","shell.execute_reply":"2024-09-05T10:05:30.785633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(id_list[0:5])\nprint(id_list[-5:])","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:31.020812Z","iopub.execute_input":"2024-09-05T10:05:31.021820Z","iopub.status.idle":"2024-09-05T10:05:31.027418Z","shell.execute_reply.started":"2024-09-05T10:05:31.021766Z","shell.execute_reply":"2024-09-05T10:05:31.026465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### image Processing","metadata":{}},{"cell_type":"code","source":"# convert images to numpy arrays\n\ntrain_data_folder = 'train/'\n\ndata = []\n\nfor id in id_list:\n\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-09-05T10:05:31.633304Z","iopub.execute_input":"2024-09-05T10:05:31.633709Z","iopub.status.idle":"2024-09-05T10:05:39.988178Z","shell.execute_reply.started":"2024-09-05T10:05:31.633672Z","shell.execute_reply":"2024-09-05T10:05:39.987244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(data)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:39.990014Z","iopub.execute_input":"2024-09-05T10:05:39.990369Z","iopub.status.idle":"2024-09-05T10:05:39.996002Z","shell.execute_reply.started":"2024-09-05T10:05:39.990333Z","shell.execute_reply":"2024-09-05T10:05:39.995151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(data)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:39.997472Z","iopub.execute_input":"2024-09-05T10:05:39.998079Z","iopub.status.idle":"2024-09-05T10:05:40.008420Z","shell.execute_reply.started":"2024-09-05T10:05:39.998032Z","shell.execute_reply":"2024-09-05T10:05:40.007593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(data[0])","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.010854Z","iopub.execute_input":"2024-09-05T10:05:40.011492Z","iopub.status.idle":"2024-09-05T10:05:40.021194Z","shell.execute_reply.started":"2024-09-05T10:05:40.011454Z","shell.execute_reply":"2024-09-05T10:05:40.020317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[0].shape","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.022332Z","iopub.execute_input":"2024-09-05T10:05:40.022625Z","iopub.status.idle":"2024-09-05T10:05:40.031651Z","shell.execute_reply.started":"2024-09-05T10:05:40.022595Z","shell.execute_reply":"2024-09-05T10:05:40.030777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[0]","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.032811Z","iopub.execute_input":"2024-09-05T10:05:40.033155Z","iopub.status.idle":"2024-09-05T10:05:40.043625Z","shell.execute_reply.started":"2024-09-05T10:05:40.033114Z","shell.execute_reply":"2024-09-05T10:05:40.042654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# convert image list and label list to numpy arrays\n\nX = np.array(data)\nY = np.array(labels)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.044823Z","iopub.execute_input":"2024-09-05T10:05:40.045160Z","iopub.status.idle":"2024-09-05T10:05:40.136246Z","shell.execute_reply.started":"2024-09-05T10:05:40.045120Z","shell.execute_reply":"2024-09-05T10:05:40.135426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(X)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.137440Z","iopub.execute_input":"2024-09-05T10:05:40.137772Z","iopub.status.idle":"2024-09-05T10:05:40.145203Z","shell.execute_reply.started":"2024-09-05T10:05:40.137739Z","shell.execute_reply":"2024-09-05T10:05:40.144291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X.shape)\nprint(Y.shape)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.146821Z","iopub.execute_input":"2024-09-05T10:05:40.147257Z","iopub.status.idle":"2024-09-05T10:05:40.155312Z","shell.execute_reply.started":"2024-09-05T10:05:40.147211Z","shell.execute_reply":"2024-09-05T10:05:40.154493Z"},"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":"2024-09-05T10:05:40.158367Z","iopub.execute_input":"2024-09-05T10:05:40.158827Z","iopub.status.idle":"2024-09-05T10:05:40.220035Z","shell.execute_reply.started":"2024-09-05T10:05:40.158791Z","shell.execute_reply":"2024-09-05T10:05:40.219244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X.shape, X_train.shape, X_test.shape)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.221124Z","iopub.execute_input":"2024-09-05T10:05:40.221420Z","iopub.status.idle":"2024-09-05T10:05:40.226350Z","shell.execute_reply.started":"2024-09-05T10:05:40.221390Z","shell.execute_reply":"2024-09-05T10:05:40.225456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# scaling the data\n\nX_train_scaled = X_train/255\n\nX_test_scaled = X_test/255","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.227442Z","iopub.execute_input":"2024-09-05T10:05:40.227747Z","iopub.status.idle":"2024-09-05T10:05:40.610915Z","shell.execute_reply.started":"2024-09-05T10:05:40.227695Z","shell.execute_reply":"2024-09-05T10:05:40.610095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train[0]","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.611960Z","iopub.execute_input":"2024-09-05T10:05:40.612242Z","iopub.status.idle":"2024-09-05T10:05:40.619222Z","shell.execute_reply.started":"2024-09-05T10:05:40.612211Z","shell.execute_reply":"2024-09-05T10:05:40.618236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:40.620309Z","iopub.execute_input":"2024-09-05T10:05:40.620597Z","iopub.status.idle":"2024-09-05T10:05:52.501014Z","shell.execute_reply.started":"2024-09-05T10:05:40.620567Z","shell.execute_reply":"2024-09-05T10:05:52.500181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_of_classes = 10\n\n# setting up the layers of Neural Network\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-09-05T10:05:52.502245Z","iopub.execute_input":"2024-09-05T10:05:52.502951Z","iopub.status.idle":"2024-09-05T10:05:53.430607Z","shell.execute_reply.started":"2024-09-05T10:05:52.502904Z","shell.execute_reply":"2024-09-05T10:05:53.429862Z"},"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-09-05T10:05:53.431879Z","iopub.execute_input":"2024-09-05T10:05:53.432585Z","iopub.status.idle":"2024-09-05T10:05:53.446076Z","shell.execute_reply.started":"2024-09-05T10:05:53.432537Z","shell.execute_reply":"2024-09-05T10:05:53.445327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# training the neural networka\nmodel.fit(X_train_scaled, Y_train, validation_split=0.1, epochs=10)","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:05:53.447372Z","iopub.execute_input":"2024-09-05T10:05:53.447743Z","iopub.status.idle":"2024-09-05T10:06:15.517285Z","shell.execute_reply.started":"2024-09-05T10:05:53.447699Z","shell.execute_reply":"2024-09-05T10:06:15.515763Z"},"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 import optimizers","metadata":{"execution":{"iopub.status.busy":"2024-09-05T10:06:15.518787Z","iopub.execute_input":"2024-09-05T10:06:15.519345Z","iopub.status.idle":"2024-09-05T10:06:15.533668Z","shell.execute_reply.started":"2024-09-05T10:06:15.519296Z","shell.execute_reply":"2024-09-05T10:06:15.532905Z"},"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-09-05T10:06:15.534642Z","iopub.execute_input":"2024-09-05T10:06:15.534933Z","iopub.status.idle":"2024-09-05T10:06:17.624717Z","shell.execute_reply.started":"2024-09-05T10:06:15.534903Z","shell.execute_reply":"2024-09-05T10:06:17.623787Z"},"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-09-05T10:06:17.625843Z","iopub.execute_input":"2024-09-05T10:06:17.626146Z","iopub.status.idle":"2024-09-05T10:06:17.650886Z","shell.execute_reply.started":"2024-09-05T10:06:17.626114Z","shell.execute_reply":"2024-09-05T10:06:17.650169Z"},"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-09-05T10:06:17.651914Z","iopub.execute_input":"2024-09-05T10:06:17.652170Z","iopub.status.idle":"2024-09-05T10:06:17.668659Z","shell.execute_reply.started":"2024-09-05T10:06:17.652141Z","shell.execute_reply":"2024-09-05T10:06:17.667769Z"},"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-09-05T10:06:17.669916Z","iopub.execute_input":"2024-09-05T10:06:17.670506Z","iopub.status.idle":"2024-09-05T11:13:24.015895Z","shell.execute_reply.started":"2024-09-05T10:06:17.670473Z","shell.execute_reply":"2024-09-05T11:13:24.014905Z"},"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-09-05T11:13:42.478390Z","iopub.execute_input":"2024-09-05T11:13:42.478822Z","iopub.status.idle":"2024-09-05T11:14:20.502648Z","shell.execute_reply.started":"2024-09-05T11:13:42.478781Z","shell.execute_reply":"2024-09-05T11:14:20.501688Z"},"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-09-05T11:14:20.504204Z","iopub.execute_input":"2024-09-05T11:14:20.504544Z","iopub.status.idle":"2024-09-05T11:14:20.980914Z","shell.execute_reply.started":"2024-09-05T11:14:20.504510Z","shell.execute_reply":"2024-09-05T11:14:20.979980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}