{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"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\n# import numpy as np # linear algebra\n# import 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\n# import os\n# for 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-10-18T22:35:19.764216Z","iopub.execute_input":"2023-10-18T22:35:19.764549Z","iopub.status.idle":"2023-10-18T22:35:19.79283Z","shell.execute_reply.started":"2023-10-18T22:35:19.764522Z","shell.execute_reply":"2023-10-18T22:35:19.792035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#During submission internet is disabled. Hence install this package manually\n!pip install -qU ../input/for-pydicom/python_gdcm-3.0.22-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ../input/for-pydicom/pylibjpeg-1.4.0-py3-none-any.whl --find-links frozen_packages --no-index","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:01:28.277563Z","iopub.execute_input":"2023-10-30T05:01:28.277831Z","iopub.status.idle":"2023-10-30T05:01:43.924699Z","shell.execute_reply.started":"2023-10-30T05:01:28.277807Z","shell.execute_reply":"2023-10-30T05:01:43.923505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport pydicom as dicom\nimport glob\nimport nibabel as nib\nimport os\nimport cv2\nfrom tqdm import tqdm\nimport tensorflow as tf\nimport tensorflow.keras.layers as tfl\nfrom tensorflow.keras import backend as K\nfrom sklearn.model_selection import StratifiedKFold\nfrom tensorflow.keras.preprocessing.image import load_img, img_to_array\nfrom tensorflow.keras.applications import EfficientNetB0\nimport keras\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Flatten\nfrom keras.layers import Conv2D, MaxPooling2D\nfrom keras.utils import to_categorical\nfrom keras.preprocessing import image\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\n","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:02:16.37735Z","iopub.execute_input":"2023-10-30T05:02:16.378154Z","iopub.status.idle":"2023-10-30T05:02:32.28605Z","shell.execute_reply.started":"2023-10-30T05:02:16.378117Z","shell.execute_reply":"2023-10-30T05:02:32.28515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_dir = r'/kaggle/input/rsna-2022-cervical-spine-fracture-detection'\ntrain_images = os.path.join(base_dir,'train_images')\ntest_images = os.path.join(base_dir,'test_images')\nsegmentation_data = r'/kaggle/input/rsna-cervical-fracture-segmentations-npy/npy_segmentations'\ntrain_data = pd.read_csv(os.path.join(base_dir,'train.csv'))\nsegmentation_meta_data = pd.read_csv(r'/kaggle/input/rsna-cervical-fracture-segmentation-metadata/meta_segmentation.csv')\n","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:02:38.929803Z","iopub.execute_input":"2023-10-30T05:02:38.930506Z","iopub.status.idle":"2023-10-30T05:02:39.170435Z","shell.execute_reply.started":"2023-10-30T05:02:38.93047Z","shell.execute_reply":"2023-10-30T05:02:39.169348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segmentation_meta_data.shape","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:02:42.729931Z","iopub.execute_input":"2023-10-30T05:02:42.730329Z","iopub.status.idle":"2023-10-30T05:02:42.737792Z","shell.execute_reply.started":"2023-10-30T05:02:42.730296Z","shell.execute_reply":"2023-10-30T05:02:42.736823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segmentation_meta_data.columns","metadata":{"execution":{"iopub.status.busy":"2023-10-20T04:09:21.291622Z","iopub.execute_input":"2023-10-20T04:09:21.292405Z","iopub.status.idle":"2023-10-20T04:09:21.298269Z","shell.execute_reply.started":"2023-10-20T04:09:21.292347Z","shell.execute_reply":"2023-10-20T04:09:21.297468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns = ['StudyInstanceUID','SOPInstanceUID','C1','C2','C3','C4','C5','C6','C7']","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:02:46.722146Z","iopub.execute_input":"2023-10-30T05:02:46.72287Z","iopub.status.idle":"2023-10-30T05:02:46.727201Z","shell.execute_reply.started":"2023-10-30T05:02:46.722835Z","shell.execute_reply":"2023-10-30T05:02:46.72624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"seg_labels = segmentation_meta_data[columns]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:02:49.745856Z","iopub.execute_input":"2023-10-30T05:02:49.746654Z","iopub.status.idle":"2023-10-30T05:02:49.773772Z","shell.execute_reply.started":"2023-10-30T05:02:49.746615Z","shell.execute_reply":"2023-10-30T05:02:49.772713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"seg_labels.head(2)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:02:53.434403Z","iopub.execute_input":"2023-10-30T05:02:53.434793Z","iopub.status.idle":"2023-10-30T05:02:53.451629Z","shell.execute_reply.started":"2023-10-30T05:02:53.434761Z","shell.execute_reply":"2023-10-30T05:02:53.450413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Get Slice instance number\nseg_labels.loc[:,'slice'] = seg_labels['SOPInstanceUID'].apply(lambda x:x.split('.')[-1:][0])","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:03:19.703021Z","iopub.execute_input":"2023-10-30T05:03:19.7038Z","iopub.status.idle":"2023-10-30T05:03:19.738515Z","shell.execute_reply.started":"2023-10-30T05:03:19.703753Z","shell.execute_reply":"2023-10-30T05:03:19.737413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_dicom(path):\n    '''Function to load and transform DICOM images'''\n    img=dicom.dcmread(path)\n    img.PhotometricInterpretation = 'YBR_FULL'\n    data=img.pixel_array\n    data=data-np.min(data)\n    if np.max(data) != 0:\n        data=data/np.max(data)\n    data=(data*255).astype(np.uint8)        \n    return cv2.cvtColor(data.reshape(512, 512), cv2.COLOR_GRAY2RGB)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:03:46.563776Z","iopub.execute_input":"2023-10-30T05:03:46.564726Z","iopub.status.idle":"2023-10-30T05:03:46.57107Z","shell.execute_reply.started":"2023-10-30T05:03:46.564688Z","shell.execute_reply":"2023-10-30T05:03:46.570186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def ImgDataGenerator(train_df,base_path):\n        '''Function to read dicom image path and store the images as numpy arrays'''\n        trainset = []\n        trainlabel = []\n        for i in tqdm(range(len(train_df))):\n            study_id = train_df.loc[i,'StudyInstanceUID']\n            slice_id = train_df.loc[i,'slice']+'.dcm'\n            study_path = study_id+'/'+slice_id\n            \n            path = os.path.join(base_path, study_path)\n      \n                #dc = dicom.read_file(os.path.join(path,im))\n            #if dc.file_meta.TransferSyntaxUID.name =='JPEG Lossless, Non-Hierarchical, First-Order Prediction (Process 14 [Selection Value 1])':\n            #    continue\n            img = load_dicom(path)\n            img = cv2.resize(img, (128 , 128))\n            image = img_to_array(img)\n            image = image / 255.0\n            trainset += [image]\n            cur_label = [train_df.loc[i,f'C{j}'] for j in range(1,8)]\n            trainlabel += [cur_label]\n\n                         \n                \n        return np.array(trainset), np.array(trainlabel)\n","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:04:25.402561Z","iopub.execute_input":"2023-10-30T05:04:25.40296Z","iopub.status.idle":"2023-10-30T05:04:25.411236Z","shell.execute_reply.started":"2023-10-30T05:04:25.402927Z","shell.execute_reply":"2023-10-30T05:04:25.41018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def RSNAImgArrayGenerator(ids,base_path):\n    '''Function to generate numpy array for test dataset'''\n           \n    testset=[]\n    for id in tqdm(ids):        \n        path = os.path.join(base_path, id)\n        if os.path.exists(path):\n            for im in (os.listdir(path)):\n                dc = dicom.read_file(os.path.join(path,im))\n                img=load_dicom(os.path.join(path,im))\n                img=cv2.resize(img,(128, 128))\n                image=img_to_array(img)\n                image=image/255.0\n                testset+=[image]\n    return np.array(testset)\n","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:04:49.471798Z","iopub.execute_input":"2023-10-30T05:04:49.472549Z","iopub.status.idle":"2023-10-30T05:04:49.479045Z","shell.execute_reply.started":"2023-10-30T05:04:49.472513Z","shell.execute_reply":"2023-10-30T05:04:49.478136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Get list of study ids who doesn't have segmentation data\nnon_seg_train_ids = [id for id in train_data['StudyInstanceUID'].unique() if id not in seg_labels['StudyInstanceUID'].unique()]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:05:18.798756Z","iopub.execute_input":"2023-10-30T05:05:18.799116Z","iopub.status.idle":"2023-10-30T05:05:24.266489Z","shell.execute_reply.started":"2023-10-30T05:05:18.799086Z","shell.execute_reply":"2023-10-30T05:05:24.265363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(non_seg_train_ids)","metadata":{"execution":{"iopub.status.busy":"2023-10-20T04:16:14.505058Z","iopub.execute_input":"2023-10-20T04:16:14.50544Z","iopub.status.idle":"2023-10-20T04:16:14.511222Z","shell.execute_reply.started":"2023-10-20T04:16:14.505412Z","shell.execute_reply":"2023-10-20T04:16:14.510284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#non_seg_training_data = RSNAImgArrayGenerator(non_seg_train_ids,train_images)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:07:06.940051Z","iopub.execute_input":"2023-10-30T05:07:06.940415Z","iopub.status.idle":"2023-10-30T05:07:06.944762Z","shell.execute_reply.started":"2023-10-30T05:07:06.940385Z","shell.execute_reply":"2023-10-30T05:07:06.943858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Fetch training data for study ids who doesn't have segmentation images\nnon_seg_train_data = train_data[train_data['StudyInstanceUID'].isin(non_seg_train_ids)]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:07:42.860627Z","iopub.execute_input":"2023-10-30T05:07:42.861131Z","iopub.status.idle":"2023-10-30T05:07:42.869513Z","shell.execute_reply.started":"2023-10-30T05:07:42.861089Z","shell.execute_reply":"2023-10-30T05:07:42.867889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"non_seg_train_data.head(2)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:07:55.753953Z","iopub.execute_input":"2023-10-30T05:07:55.754718Z","iopub.status.idle":"2023-10-30T05:07:55.766562Z","shell.execute_reply.started":"2023-10-30T05:07:55.754683Z","shell.execute_reply":"2023-10-30T05:07:55.765542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Convert train images of segmented studyids to array\nX_seg,y_seg = ImgDataGenerator(seg_labels,train_images)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:11:08.692613Z","iopub.execute_input":"2023-10-30T05:11:08.693011Z","iopub.status.idle":"2023-10-30T05:23:02.249708Z","shell.execute_reply.started":"2023-10-30T05:11:08.692977Z","shell.execute_reply":"2023-10-30T05:23:02.248798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#save for future use\nnp.save('/kaggle/working/seg_train_images.npy',X_seg)\nnp.save('/kaggle/working/seg_train_images_labels.npy',y_seg)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:25:32.729758Z","iopub.execute_input":"2023-10-30T05:25:32.730135Z","iopub.status.idle":"2023-10-30T05:25:44.534263Z","shell.execute_reply.started":"2023-10-30T05:25:32.730106Z","shell.execute_reply":"2023-10-30T05:25:44.533402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Uncomment this if you want to use the above output in the next run\n#X_seg = np.load(r'/kaggle/input/identify-vertbrae-using-cnn/seg_train_images.npy')\n#y_seg = np.load(r'/kaggle/input/identify-vertbrae-using-cnn/seg_train_images_labels.npy')","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:26:29.976364Z","iopub.execute_input":"2023-10-30T05:26:29.976706Z","iopub.status.idle":"2023-10-30T05:26:29.980651Z","shell.execute_reply.started":"2023-10-30T05:26:29.976678Z","shell.execute_reply":"2023-10-30T05:26:29.979719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_seg.shape,y_seg.shape)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:27:45.144353Z","iopub.execute_input":"2023-10-30T05:27:45.144982Z","iopub.status.idle":"2023-10-30T05:27:45.150102Z","shell.execute_reply.started":"2023-10-30T05:27:45.144948Z","shell.execute_reply":"2023-10-30T05:27:45.148941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Visualize a random CT scan image\nimport matplotlib.pyplot as plt\nplt.imshow(X_seg[500], cmap = 'bone')","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:28:37.473992Z","iopub.execute_input":"2023-10-30T05:28:37.474358Z","iopub.status.idle":"2023-10-30T05:28:37.818572Z","shell.execute_reply.started":"2023-10-30T05:28:37.474325Z","shell.execute_reply":"2023-10-30T05:28:37.817501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Find its segmentation value. \ny_seg[500]\n#The above slice represents cervicals C3 and C4","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:28:44.218562Z","iopub.execute_input":"2023-10-30T05:28:44.219588Z","iopub.status.idle":"2023-10-30T05:28:44.22726Z","shell.execute_reply.started":"2023-10-30T05:28:44.219545Z","shell.execute_reply":"2023-10-30T05:28:44.225942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_basic_cnn():\n    \n    '''Basic Convolutional Neural Network to train segmentation CT scan images'''\n    \n    \n    inp = tfl.Input((128, 128 ,3))\n    x = tfl.Conv2D(32, (3, 3), activation='relu')(inp)\n    x = tfl.MaxPooling2D((2, 2))(x)\n    x = tfl.Conv2D(64, (3, 3), activation='relu')(inp)\n    x = tfl.MaxPooling2D((2, 2))(x)\n    x = tfl.Conv2D(128, (3, 3), activation='relu')(inp)\n    x = tfl.MaxPooling2D((2, 2))(x)\n    x = tfl.Flatten()(x)\n    x = tfl.Dense(128, 'relu')(x)\n    x = tfl.Dropout(0.5)(x)\n    out = tfl.Dense(7, 'sigmoid')(x)\n    \n    model = tf.keras.models.Model(inp, out)\n    \n    model.compile(loss=\"binary_crossentropy\",\n                  optimizer = tf.keras.optimizers.Adam(learning_rate = 1e-4),\n                  metrics=[tf.keras.metrics.BinaryAccuracy()])\n    model.summary()\n    \n    return model\n\n#recall, precision. Way to use softmax [1,0,0,0,1,0,0] -> [0.5,0,0,0,0.5,0,0]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:29:59.18957Z","iopub.execute_input":"2023-10-30T05:29:59.190331Z","iopub.status.idle":"2023-10-30T05:29:59.198677Z","shell.execute_reply.started":"2023-10-30T05:29:59.190299Z","shell.execute_reply":"2023-10-30T05:29:59.197784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X_seg, y_seg, random_state=42, test_size=0.1)","metadata":{"execution":{"iopub.status.busy":"2023-10-19T17:11:22.159205Z","iopub.execute_input":"2023-10-19T17:11:22.159784Z","iopub.status.idle":"2023-10-19T17:11:24.768186Z","shell.execute_reply.started":"2023-10-19T17:11:22.159754Z","shell.execute_reply":"2023-10-19T17:11:24.767044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.shape,y_train.shape)\nprint(X_test.shape,y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-10-19T17:29:04.206537Z","iopub.execute_input":"2023-10-19T17:29:04.210104Z","iopub.status.idle":"2023-10-19T17:29:04.22518Z","shell.execute_reply.started":"2023-10-19T17:29:04.210053Z","shell.execute_reply":"2023-10-19T17:29:04.222436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = get_basic_cnn()","metadata":{"execution":{"iopub.status.busy":"2023-10-19T17:29:04.688684Z","iopub.execute_input":"2023-10-19T17:29:04.689041Z","iopub.status.idle":"2023-10-19T17:29:05.721273Z","shell.execute_reply.started":"2023-10-19T17:29:04.689007Z","shell.execute_reply":"2023-10-19T17:29:05.72012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test), batch_size=64)","metadata":{"execution":{"iopub.status.busy":"2023-10-19T17:29:09.010546Z","iopub.execute_input":"2023-10-19T17:29:09.011356Z","iopub.status.idle":"2023-10-19T20:30:39.155077Z","shell.execute_reply.started":"2023-10-19T17:29:09.01128Z","shell.execute_reply":"2023-10-19T20:30:39.151688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_hat = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-10-19T20:55:40.716409Z","iopub.execute_input":"2023-10-19T20:55:40.718305Z","iopub.status.idle":"2023-10-19T20:56:13.001463Z","shell.execute_reply.started":"2023-10-19T20:55:40.718238Z","shell.execute_reply":"2023-10-19T20:56:12.999641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score = model.evaluate(X_test, y_test, verbose = 1)","metadata":{"execution":{"iopub.status.busy":"2023-10-19T21:56:31.236491Z","iopub.execute_input":"2023-10-19T21:56:31.23685Z","iopub.status.idle":"2023-10-19T21:57:00.876768Z","shell.execute_reply.started":"2023-10-19T21:56:31.236825Z","shell.execute_reply":"2023-10-19T21:57:00.874784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Test loss:', score[0]) \nprint('Test accuracy:', score[1])","metadata":{"execution":{"iopub.status.busy":"2023-10-19T21:58:13.476274Z","iopub.execute_input":"2023-10-19T21:58:13.476697Z","iopub.status.idle":"2023-10-19T21:58:13.482486Z","shell.execute_reply.started":"2023-10-19T21:58:13.476669Z","shell.execute_reply":"2023-10-19T21:58:13.481202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = np.array(seg_labels.columns[2:-1])\nimg = X_test[17]\n\nproba = model.predict(img.reshape(1,128,128,3))","metadata":{"execution":{"iopub.status.busy":"2023-10-30T05:32:18.400207Z","iopub.execute_input":"2023-10-30T05:32:18.401242Z","iopub.status.idle":"2023-10-30T05:32:18.405387Z","shell.execute_reply.started":"2023-10-30T05:32:18.401186Z","shell.execute_reply":"2023-10-30T05:32:18.404328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Fetches the probability value for each class in a sorted order\nnp.argsort(proba[0]) ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n#When I try to generate non_seg_image array for predictions, the notebook ran out of memory. Will be\n#fixed in future iteration\n\n# non_seg_data = train_data[~train_data['StudyInstanceUID'].isin(seg_labels['StudyInstanceUID'])]\n\n# X_non_seg = RSNADFGenerator(non_seg_data,train_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code for future purpose \n# accuracies=[]\n# for train_idx, val_idx in StratifiedKFold(5).split(df_train, df_train['patient_overall']):    \n#     K.clear_session()\n#     x_train = df_train.iloc[train_idx].reset_index()\n#     x_val = df_train.iloc[val_idx].reset_index()\n\n#     train_gen = RSNATrainGenerator(x_train, min(len(x_train), 64), infinite = False, base_path = train_images_dir)\n#     val_gen = RSNATrainGenerator(x_val, min(len(x_val), 64), infinite = False, base_path = train_images_dir)\n\n#     model = get_basic_cnn()\n#     print(\"validation steps: \",(len(x_val) // 64), \"steps_per_epoch: \",(len(x_train) // 64))\n\n#     hist = model.fit(                            \n#         train_gen,\n#         epochs = 5,\n#         callbacks = [tf.keras.callbacks.EarlyStopping(monitor = 'val_loss', patience = 2, restore_best_weights = True)],\n#         validation_steps = max((len(x_val) // 64), 1),\n#         steps_per_epoch = max((len(x_train) // 64), 1),\n#         validation_data = val_gen\n#       )\n\n#     #hist2 = model2.fit_generator(                            \n#     #    train_gen,\n#     #    epochs = 5,\n#     #    callbacks = [tf.keras.callbacks.EarlyStopping(monitor = 'val_loss', patience = 2, restore_best_weights = True)],\n#     #    validation_steps = max((len(x_val) // 64), 1),\n#     #    steps_per_epoch = max((len(x_train) // 64), 1),\n#     #    validation_data = val_gen,\n#     #  )\n#     accuracies.append(model.evaluate(val_gen, steps = max((len(x_val) // 64), 1))[1])","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test), batch_size=64)","metadata":{},"execution_count":null,"outputs":[]}]}