{"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":"none","dataSources":[{"sourceId":65471,"databundleVersionId":7211464,"sourceType":"competition"}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport cv2\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport re\nimport glob\nimport random\n\nTRAIN_dir = '../input/arabic-letters-classification/Final_Arabic_Alpha_dataset/Final_Arabic_Alpha_dataset/train'\nTRAIN_imgs = [TRAIN_dir + i for i in os.listdir(TRAIN_dir)] \n\nTEST_dir = '../input/arabic-letters-classification/Final_Arabic_Alpha_dataset/Final_Arabic_Alpha_dataset/test'\nTEST_imgs = [TEST_dir + i for i in os.listdir(TEST_dir)]","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:01:34.584527Z","iopub.execute_input":"2023-12-23T16:01:34.585605Z","iopub.status.idle":"2023-12-23T16:01:36.026018Z","shell.execute_reply.started":"2023-12-23T16:01:34.585555Z","shell.execute_reply":"2023-12-23T16:01:36.02499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#to get the class labels outta the img path\ndef damnClass(path):\n    clsplit = re.split(r'/',path)[-2]\n    return clsplit\n\n#to get the chars. labels outta the img path\ndef coolChar(path):\n    charsplits = re.split(r'/', path)[-1]\n    charsplit = re.split(r'(?<=_)(.*?)(?=_)', charsplits)\n    return f\"{charsplit[1]}_{charsplit[3]}\"","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:01:38.32761Z","iopub.execute_input":"2023-12-23T16:01:38.328347Z","iopub.status.idle":"2023-12-23T16:01:38.335681Z","shell.execute_reply.started":"2023-12-23T16:01:38.328293Z","shell.execute_reply":"2023-12-23T16:01:38.333985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#to store the path and the label of the training img\npath_label_TRAIN = []\nfor img in glob.glob('/kaggle/input/arabic-letters-classification/Final_Arabic_Alpha_dataset/Final_Arabic_Alpha_dataset/train/*/*.png'):\n    cl = damnClass(img)\n    char = coolChar(img)\n    if cl is not None and char is not None:\n        path_label_TRAIN.append([img, cl, char])","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:01:41.02281Z","iopub.execute_input":"2023-12-23T16:01:41.024068Z","iopub.status.idle":"2023-12-23T16:01:45.309035Z","shell.execute_reply.started":"2023-12-23T16:01:41.024017Z","shell.execute_reply":"2023-12-23T16:01:45.307708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ahmods_train = pd.DataFrame(path_label_TRAIN, columns = ['Path','Class Label', 'Char. Label'])","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:01:48.774021Z","iopub.execute_input":"2023-12-23T16:01:48.774908Z","iopub.status.idle":"2023-12-23T16:01:48.799945Z","shell.execute_reply.started":"2023-12-23T16:01:48.774846Z","shell.execute_reply":"2023-12-23T16:01:48.798255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#some checks\nahmods_train.sample(7)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:01:51.556194Z","iopub.execute_input":"2023-12-23T16:01:51.556718Z","iopub.status.idle":"2023-12-23T16:01:51.590477Z","shell.execute_reply.started":"2023-12-23T16:01:51.556674Z","shell.execute_reply":"2023-12-23T16:01:51.589002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ahmods_train.head(7)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:01:55.15093Z","iopub.execute_input":"2023-12-23T16:01:55.151376Z","iopub.status.idle":"2023-12-23T16:01:55.164585Z","shell.execute_reply.started":"2023-12-23T16:01:55.151329Z","shell.execute_reply":"2023-12-23T16:01:55.163522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#same for test\npath_TEST = []\nfor img in glob.glob('/kaggle/input/arabic-letters-classification/Final_Arabic_Alpha_dataset/Final_Arabic_Alpha_dataset/test/*.png'):\n    path_TEST.append(img)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:01:57.919965Z","iopub.execute_input":"2023-12-23T16:01:57.920822Z","iopub.status.idle":"2023-12-23T16:01:57.974096Z","shell.execute_reply.started":"2023-12-23T16:01:57.920782Z","shell.execute_reply":"2023-12-23T16:01:57.973223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#converitng list to dataframe\nahmods_test = pd.DataFrame(path_TEST, columns = ['Path'])\nahmods_test['Label'] = 0 #initially","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:02:02.336158Z","iopub.execute_input":"2023-12-23T16:02:02.337701Z","iopub.status.idle":"2023-12-23T16:02:02.347623Z","shell.execute_reply.started":"2023-12-23T16:02:02.337636Z","shell.execute_reply":"2023-12-23T16:02:02.346606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ahmods_test.sample(7)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:02:04.759259Z","iopub.execute_input":"2023-12-23T16:02:04.75976Z","iopub.status.idle":"2023-12-23T16:02:04.776824Z","shell.execute_reply.started":"2023-12-23T16:02:04.759722Z","shell.execute_reply":"2023-12-23T16:02:04.775323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#give a glance to some letters\nfig, arr = plt.subplots(1, 10, figsize=(30, 6))\nunqLabels = set(ahmods_train['Char. Label'])\nfor i,char in enumerate(unqLabels):\n    sample = ahmods_train[ahmods_train['Char. Label'] == char].sample(1)\n    imgpath = sample['Path'].item()\n    X = cv2.imread(imgpath)\n    arr[i].imshow(X)\n    arr[i].text(0.5, 0.5, char, ha = 'center', va = 'center', color = 'white', backgroundcolor = 'black', fontsize = 9)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:02:12.467504Z","iopub.execute_input":"2023-12-23T16:02:12.467916Z","iopub.status.idle":"2023-12-23T16:02:14.438923Z","shell.execute_reply.started":"2023-12-23T16:02:12.467885Z","shell.execute_reply":"2023-12-23T16:02:14.437431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# to get the img out \ndef getonimg(path):\n    imgg = cv2.imread(path)\n    return imgg","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:02:22.759817Z","iopub.execute_input":"2023-12-23T16:02:22.760966Z","iopub.status.idle":"2023-12-23T16:02:22.765747Z","shell.execute_reply.started":"2023-12-23T16:02:22.760924Z","shell.execute_reply":"2023-12-23T16:02:22.764919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"no_of_xTRAINs = ahmods_train.shape[0]\nx_train = np.empty((no_of_xTRAINs, 32, 32, 1), dtype = np.uint8)\nfor i, path in enumerate((ahmods_train['Path'])):\n    x_train[i, :, :, :] = getonimg(path)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T12:14:17.052478Z","iopub.execute_input":"2023-12-23T12:14:17.053164Z","iopub.status.idle":"2023-12-23T12:14:17.090051Z","shell.execute_reply.started":"2023-12-23T12:14:17.053126Z","shell.execute_reply":"2023-12-23T12:14:17.088237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tr = '/kaggle/input/arabic-letters-classification/Final_Arabic_Alpha_dataset/Final_Arabic_Alpha_dataset/train/'\n\nclss = [os.path.join(tr, folder) for folder in os.listdir(tr) if os.path.isdir(os.path.join(tr, folder))]\nunq_dims_channels = set()\n\nfor cl in clss:\n    img_paths = [os.path.join(cl, img) for img in os.listdir(cl) if img.endswith('.png')]\n    for path in img_paths:\n        img = cv2.imread(path)\n        no_channels = img.shape[2]\n        original_dims = img.shape[:2]\n        unq_dims_channels.add((original_dims, no_channels))\n\nfor i in unq_dims_channels:\n    print(\"Original dimensions:\", i[0], \"| Number of channels:\", i[1])\n","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:02:31.857468Z","iopub.execute_input":"2023-12-23T16:02:31.858404Z","iopub.status.idle":"2023-12-23T16:05:27.350124Z","shell.execute_reply.started":"2023-12-23T16:02:31.858343Z","shell.execute_reply":"2023-12-23T16:05:27.348972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"newshape = (160, 160)\nno_of_xTRAINs = ahmods_train.shape[0]\nx_train = np.empty((no_of_xTRAINs, *newshape, 3), dtype = np.uint8)\nfor i, path in enumerate((ahmods_train['Path'])):\n    img = getonimg(path)\n    resized_img = cv2.resize(img, newshape)\n    x_train[i, :, :, :] = resized_img","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:05:35.311265Z","iopub.execute_input":"2023-12-23T16:05:35.311752Z","iopub.status.idle":"2023-12-23T16:06:41.731183Z","shell.execute_reply.started":"2023-12-23T16:05:35.311713Z","shell.execute_reply":"2023-12-23T16:06:41.728955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"figg = plt.figure(figsize=(20, 10))\nplt.title('a pretty train sample')\nplt.imshow(x_train[random.randint(1, 10000)])","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:06:49.998262Z","iopub.execute_input":"2023-12-23T16:06:49.998798Z","iopub.status.idle":"2023-12-23T16:06:50.449815Z","shell.execute_reply.started":"2023-12-23T16:06:49.998756Z","shell.execute_reply":"2023-12-23T16:06:50.448949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"no_of_xTESTs = ahmods_test.shape[0]\nx_test = np.empty((no_of_xTESTs, *newshape, 3), dtype = np.uint8)\nfor i, path in enumerate((ahmods_test['Path'])):\n    img = getonimg(path)\n    resized_img = cv2.resize(img, newshape)\n    x_test[i, :, :, :] = resized_img","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:07:02.513606Z","iopub.execute_input":"2023-12-23T16:07:02.514598Z","iopub.status.idle":"2023-12-23T16:07:51.261548Z","shell.execute_reply.started":"2023-12-23T16:07:02.514547Z","shell.execute_reply":"2023-12-23T16:07:51.260136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"figgg = plt.figure(figsize=(20, 10))\nplt.title('a pretty test sample')\nplt.imshow(x_test[random.randint(1, 100)])","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:08:09.856449Z","iopub.execute_input":"2023-12-23T16:08:09.85734Z","iopub.status.idle":"2023-12-23T16:08:10.293183Z","shell.execute_reply.started":"2023-12-23T16:08:09.857301Z","shell.execute_reply":"2023-12-23T16:08:10.292027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#to conver the char. labels to int ones\nfrom sklearn.preprocessing import LabelEncoder\nen = LabelEncoder()\ny_train = en.fit_transform(ahmods_train['Char. Label'])","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:08:16.154221Z","iopub.execute_input":"2023-12-23T16:08:16.154665Z","iopub.status.idle":"2023-12-23T16:08:17.48813Z","shell.execute_reply.started":"2023-12-23T16:08:16.154616Z","shell.execute_reply":"2023-12-23T16:08:17.486837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.utils import to_categorical  \ny_train = to_categorical(y_train, num_classes = 65)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:08:20.088198Z","iopub.execute_input":"2023-12-23T16:08:20.088649Z","iopub.status.idle":"2023-12-23T16:08:28.153322Z","shell.execute_reply.started":"2023-12-23T16:08:20.088612Z","shell.execute_reply":"2023-12-23T16:08:28.152118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sequential CNN\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D, BatchNormalization, Dropout, Dense, Flatten\nfrom tensorflow.keras.regularizers import l2\n\ndef AhmedNN(activation = 'relu', optimizer = 'adam', kernel_initializer = 'he_normal'):\n    kingModel = Sequential()\n\n    kingModel.add(Conv2D(32, (3, 3), padding = 'same', input_shape = (160, 160, 3), activation = activation, kernel_initializer = kernel_initializer))\n    kingModel.add(MaxPooling2D(2, 2))\n    kingModel.add(BatchNormalization())\n\n    kingModel.add(Conv2D(64, (3, 3), padding = 'same', activation = activation, kernel_initializer = kernel_initializer))\n    kingModel.add(MaxPooling2D(2, 2))\n    kingModel.add(Dropout(0.2))\n    kingModel.add(BatchNormalization())\n\n    kingModel.add(Flatten())\n\n    kingModel.add(Dense(32, activation = activation, kernel_initializer = kernel_initializer, kernel_regularizer = l2(0.01)))\n    kingModel.add(BatchNormalization())\n    kingModel.add(Dropout(0.2))\n\n    kingModel.add(Dense(65, activation = 'softmax'))\n\n    kingModel.compile(optimizer = optimizer, loss = 'categorical_crossentropy', metrics = ['accuracy'])\n    return kingModel","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:08:32.67014Z","iopub.execute_input":"2023-12-23T16:08:32.671009Z","iopub.status.idle":"2023-12-23T16:08:32.685846Z","shell.execute_reply.started":"2023-12-23T16:08:32.670968Z","shell.execute_reply":"2023-12-23T16:08:32.684383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kingModel = AhmedNN()                                                          \nkingModel.summary()  ","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:08:37.00901Z","iopub.execute_input":"2023-12-23T16:08:37.011039Z","iopub.status.idle":"2023-12-23T16:08:37.444274Z","shell.execute_reply.started":"2023-12-23T16:08:37.010971Z","shell.execute_reply":"2023-12-23T16:08:37.442985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# #to early stop in order to avoid overfitting\n# from keras.callbacks import EarlyStopping, Callback\n# handsup = EarlyStopping(monitor = 'val_loss', mode = 'auto', verbose = 1, patience = 8)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T13:04:43.835666Z","iopub.execute_input":"2023-12-23T13:04:43.836096Z","iopub.status.idle":"2023-12-23T13:04:43.843079Z","shell.execute_reply.started":"2023-12-23T13:04:43.836062Z","shell.execute_reply":"2023-12-23T13:04:43.841577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fittingbackup = kingModel.fit(x_train, y_train, validation_split = 0.2, epochs = 20, batch_size = 512, verbose = 1)\n# callbacks = [handsup],","metadata":{"execution":{"iopub.status.busy":"2023-12-23T16:08:42.549444Z","iopub.execute_input":"2023-12-23T16:08:42.550346Z","iopub.status.idle":"2023-12-23T21:48:08.383445Z","shell.execute_reply.started":"2023-12-23T16:08:42.550289Z","shell.execute_reply":"2023-12-23T21:48:08.379055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#my hot accuracy\nplt.plot(fittingbackup.history['accuracy'])\nplt.plot(fittingbackup.history['val_accuracy'])\nplt.title('The training & validation acc')\nplt.legend(['train', 'val'], loc='upper left')\nplt.ylabel('acc')\nplt.xlabel('epoch')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:48:15.481266Z","iopub.execute_input":"2023-12-23T21:48:15.482005Z","iopub.status.idle":"2023-12-23T21:48:15.924077Z","shell.execute_reply.started":"2023-12-23T21:48:15.481961Z","shell.execute_reply":"2023-12-23T21:48:15.922464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#same for loss..\nplt.plot(fittingbackup.history['loss'])\nplt.plot(fittingbackup.history['val_loss'])\nplt.title('The training & validation loss')\nplt.legend(['train', 'val'], loc='upper left')\nplt.ylabel('acc.')\nplt.xlabel('epoch')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:48:23.607786Z","iopub.execute_input":"2023-12-23T21:48:23.608312Z","iopub.status.idle":"2023-12-23T21:48:23.924671Z","shell.execute_reply.started":"2023-12-23T21:48:23.608272Z","shell.execute_reply":"2023-12-23T21:48:23.923484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#saving model weights\nimport joblib\n\nkingModel.save('IncomparableWork.h5')\n\nfinalpath = '/kaggle/working/IncomparableWork.pkl'\njoblib.dump(kingModel, finalpath)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:48:32.052382Z","iopub.execute_input":"2023-12-23T21:48:32.053169Z","iopub.status.idle":"2023-12-23T21:48:32.924623Z","shell.execute_reply.started":"2023-12-23T21:48:32.053013Z","shell.execute_reply":"2023-12-23T21:48:32.923137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#predictions & decoding\np = kingModel.predict(x_test)\nmmm = np.argmax(p, axis=1)\nmmm = en.inverse_transform(mmm)\nmmm[:7]","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:48:37.068119Z","iopub.execute_input":"2023-12-23T21:48:37.068706Z","iopub.status.idle":"2023-12-23T21:49:55.159002Z","shell.execute_reply.started":"2023-12-23T21:48:37.068658Z","shell.execute_reply":"2023-12-23T21:49:55.157611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(x_test)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:50:01.381824Z","iopub.execute_input":"2023-12-23T21:50:01.382515Z","iopub.status.idle":"2023-12-23T21:50:01.390639Z","shell.execute_reply.started":"2023-12-23T21:50:01.382477Z","shell.execute_reply":"2023-12-23T21:50:01.389451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plotting em up\nfig, upsidedown = plt.subplots(2, 2)\n\nfst_rnd = random.randint(1, 10640)\nupsidedown[0, 0].imshow(x_test[fst_rnd])\n\nsnd_rnd = random.randint(1, 10640)\nupsidedown[0, 1].imshow(x_test[snd_rnd])\n\ntrd_rnd = random.randint(1, 10640)\nupsidedown[1, 0].imshow(x_test[trd_rnd])\n\nfth_rnd = random.randint(1, 10640)\nupsidedown[1, 1].imshow(x_test[fth_rnd])\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:51:22.979734Z","iopub.execute_input":"2023-12-23T21:51:22.980273Z","iopub.status.idle":"2023-12-23T21:51:23.610665Z","shell.execute_reply.started":"2023-12-23T21:51:22.980236Z","shell.execute_reply":"2023-12-23T21:51:23.609107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ahmods_test['Label'] = mmm\nahmods_test.sample(7)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:51:30.679497Z","iopub.execute_input":"2023-12-23T21:51:30.680035Z","iopub.status.idle":"2023-12-23T21:51:30.710921Z","shell.execute_reply.started":"2023-12-23T21:51:30.679998Z","shell.execute_reply":"2023-12-23T21:51:30.709572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ahmods_test['Label'] = mmm\nahmods_test.head(7)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:51:33.890918Z","iopub.execute_input":"2023-12-23T21:51:33.891388Z","iopub.status.idle":"2023-12-23T21:51:33.904634Z","shell.execute_reply.started":"2023-12-23T21:51:33.891335Z","shell.execute_reply":"2023-12-23T21:51:33.903346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\ntest_imgs = tf.keras.utils.image_dataset_from_directory(TEST_dir, labels = None, label_mode = \"categorical\", shuffle = False, image_size = (160,160), batch_size = 512)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:51:39.699942Z","iopub.execute_input":"2023-12-23T21:51:39.700474Z","iopub.status.idle":"2023-12-23T21:51:46.016588Z","shell.execute_reply.started":"2023-12-23T21:51:39.700437Z","shell.execute_reply":"2023-12-23T21:51:46.015208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgs_li = os.listdir(TEST_dir)\nlabels_li = sorted(os.listdir(TRAIN_dir))","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:52:20.47982Z","iopub.execute_input":"2023-12-23T21:52:20.480271Z","iopub.status.idle":"2023-12-23T21:52:20.493657Z","shell.execute_reply.started":"2023-12-23T21:52:20.480227Z","shell.execute_reply":"2023-12-23T21:52:20.492306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = pd.DataFrame(columns=['ID','Label'], dtype=(np.int32,np.int32))\npreds_mod = np.argmax(p, 1)\nfor idx,img in enumerate(sorted(imgs_li)):\n    df2 = pd.DataFrame([[int(img.split(\".\")[0]), int(labels_li[preds_mod[idx]])]], columns=['ID','Label'])\n    preds = pd.concat([preds, df2])","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:53:02.579711Z","iopub.execute_input":"2023-12-23T21:53:02.580134Z","iopub.status.idle":"2023-12-23T21:53:09.889827Z","shell.execute_reply.started":"2023-12-23T21:53:02.580104Z","shell.execute_reply":"2023-12-23T21:53:09.888914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds.sort_values(by='ID', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:53:13.679079Z","iopub.execute_input":"2023-12-23T21:53:13.6805Z","iopub.status.idle":"2023-12-23T21:53:13.688839Z","shell.execute_reply.started":"2023-12-23T21:53:13.680444Z","shell.execute_reply":"2023-12-23T21:53:13.687407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:53:16.959679Z","iopub.execute_input":"2023-12-23T21:53:16.96084Z","iopub.status.idle":"2023-12-23T21:53:16.978322Z","shell.execute_reply.started":"2023-12-23T21:53:16.960796Z","shell.execute_reply":"2023-12-23T21:53:16.971989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds.to_csv('predsKingAhmed.csv', index=False, header=True) ","metadata":{"execution":{"iopub.status.busy":"2023-12-23T21:53:59.499889Z","iopub.execute_input":"2023-12-23T21:53:59.500402Z","iopub.status.idle":"2023-12-23T21:53:59.534392Z","shell.execute_reply.started":"2023-12-23T21:53:59.500347Z","shell.execute_reply":"2023-12-23T21:53:59.532982Z"},"trusted":true},"execution_count":null,"outputs":[]}]}