{"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":"import pydicom as dicom\nimport matplotlib.pylab as plt\n\n# specify your image path\nimage_path = '/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00185/T2w/Image-40.dcm'\nds = dicom.dcmread(image_path)\n\nplt.imshow(ds.pixel_array)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:15.070041Z","iopub.execute_input":"2021-08-19T13:20:15.070467Z","iopub.status.idle":"2021-08-19T13:20:15.534637Z","shell.execute_reply.started":"2021-08-19T13:20:15.070359Z","shell.execute_reply":"2021-08-19T13:20:15.533628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pydicom\ndef load_dicom(path):\n    \n    data = pydicom.dcmread(path)\n    '''\n    Returns the image data as a numpy array.\n    '''  \n    if np.max(data.pixel_array)==0:\n        img = data.pixel_array\n    else:\n        img = data.pixel_array/np.max(data.pixel_array)\n        img = (img * 255).astype(np.uint8)\n        \n    return img\n","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:18.44811Z","iopub.execute_input":"2021-08-19T13:20:18.448473Z","iopub.status.idle":"2021-08-19T13:20:18.456967Z","shell.execute_reply.started":"2021-08-19T13:20:18.448434Z","shell.execute_reply":"2021-08-19T13:20:18.456024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfrom pandas import ExcelWriter\nfrom pandas import ExcelFile\n\ndf = pd.read_csv('/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/train_labels.csv')\ndata = df.set_index(\"BraTS21ID\")\ndata = data.drop([109, 123, 709], axis=0)\ndf=data.reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:21.114085Z","iopub.execute_input":"2021-08-19T13:20:21.114455Z","iopub.status.idle":"2021-08-19T13:20:21.129251Z","shell.execute_reply.started":"2021-08-19T13:20:21.114421Z","shell.execute_reply":"2021-08-19T13:20:21.128384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nlabels=np.array(df['MGMT_value'])","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:26.660225Z","iopub.execute_input":"2021-08-19T13:20:26.660638Z","iopub.status.idle":"2021-08-19T13:20:26.664744Z","shell.execute_reply.started":"2021-08-19T13:20:26.660592Z","shell.execute_reply":"2021-08-19T13:20:26.66386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Verisetindeki görüntüleri inceleme**","metadata":{}},{"cell_type":"code","source":"from glob import glob\nimagePatches = glob('/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/train/*/', recursive=True)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:42.285052Z","iopub.execute_input":"2021-08-19T13:20:42.285421Z","iopub.status.idle":"2021-08-19T13:20:42.348577Z","shell.execute_reply.started":"2021-08-19T13:20:42.285382Z","shell.execute_reply":"2021-08-19T13:20:42.347722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfiles=[]\nfiles.append ('/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00109/')\nfiles.append ('/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00709/')\nfiles.append ('/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00123/')\nfor file in files:\n    imagePatches.remove(file)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:45.450183Z","iopub.execute_input":"2021-08-19T13:20:45.450553Z","iopub.status.idle":"2021-08-19T13:20:45.456033Z","shell.execute_reply.started":"2021-08-19T13:20:45.45052Z","shell.execute_reply":"2021-08-19T13:20:45.454868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(imagePatches)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:49.032202Z","iopub.execute_input":"2021-08-19T13:20:49.032564Z","iopub.status.idle":"2021-08-19T13:20:49.038577Z","shell.execute_reply.started":"2021-08-19T13:20:49.032532Z","shell.execute_reply":"2021-08-19T13:20:49.037482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**READ ALL SEQUENCES FOR EACH SUBFOLDER !**","metadata":{}},{"cell_type":"code","source":"import re\n\ndef atoi(text):\n    return int(text) if text.isdigit() else text\n\ndef natural_keys(text):\n    '''\n    alist.sort(key=natural_keys) sorts in human order\n    http://nedbatchelder.com/blog/200712/human_sorting.html\n    (See Toothy's implementation in the comments)\n    '''\n    return [ atoi(c) for c in re.split(r'(\\d+)', text) ]","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:52.50675Z","iopub.execute_input":"2021-08-19T13:20:52.507104Z","iopub.status.idle":"2021-08-19T13:20:52.512474Z","shell.execute_reply.started":"2021-08-19T13:20:52.507056Z","shell.execute_reply":"2021-08-19T13:20:52.511482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imagePatches.sort(key=natural_keys)\nflair_patches = []\nt1w_patches=[]\nt1wce_patches=[]\nt2w_patches=[]\nfor subfolder in imagePatches:\n    flair_patches.append(glob(subfolder + 'FLAIR/**/**/*.dcm', recursive=True))\n    t1w_patches.append(glob(subfolder + 'T1w/**/**/*.dcm', recursive=True))\n    t1wce_patches.append(glob(subfolder + 'T1wCE/**/**/*.dcm', recursive=True))\n    t2w_patches.append(glob(subfolder + 'T2w/**/**/*.dcm', recursive=True))","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:20:54.482134Z","iopub.execute_input":"2021-08-19T13:20:54.482586Z","iopub.status.idle":"2021-08-19T13:21:43.011035Z","shell.execute_reply.started":"2021-08-19T13:20:54.482548Z","shell.execute_reply":"2021-08-19T13:21:43.010087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def all_slice(sequence, list_name):\n    for x in range(0,len(sequence)):\n        sequence[x].sort(key=natural_keys)\n        list_name.append((sequence[x][0:len(sequence[x])]))\n    return list_name","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:21:43.012604Z","iopub.execute_input":"2021-08-19T13:21:43.012951Z","iopub.status.idle":"2021-08-19T13:21:43.018828Z","shell.execute_reply.started":"2021-08-19T13:21:43.012911Z","shell.execute_reply":"2021-08-19T13:21:43.017659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_flair_patches = []\nall_slice(flair_patches,all_flair_patches)\nall_t1w_patches =[]\nall_t1w_patches = all_slice(t1w_patches,all_t1w_patches)\nall_t1wce_patches=[]\nall_t1wce_patches = all_slice(t1wce_patches,all_t1wce_patches)\nall_t2w_patches=[]\nall_t2w_patches = all_slice(t2w_patches,all_t2w_patches)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:21:43.02092Z","iopub.execute_input":"2021-08-19T13:21:43.021436Z","iopub.status.idle":"2021-08-19T13:21:46.152942Z","shell.execute_reply.started":"2021-08-19T13:21:43.021397Z","shell.execute_reply":"2021-08-19T13:21:46.152008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**For each patch, take middle 3 slices as an input.**","metadata":{}},{"cell_type":"code","source":"import cv2\ndef create_input(patches):\n    inputs=np.zeros((582,256,256,3))\n    for i in range(0,len(patches)):\n        for j in range(len(patches[i])//2,(len(patches[i])//2)+3):\n            img= load_dicom(patches[i][j])\n            image_array = cv2.resize(img, (256,256), interpolation=cv2.INTER_AREA)\n            image_array = np.expand_dims(image_array, -1)\n        inputs[i]=image_array\n    return inputs","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:21:46.154558Z","iopub.execute_input":"2021-08-19T13:21:46.154888Z","iopub.status.idle":"2021-08-19T13:21:46.314753Z","shell.execute_reply.started":"2021-08-19T13:21:46.154847Z","shell.execute_reply":"2021-08-19T13:21:46.313868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t2w_inputs = create_input(all_t2w_patches)\nflair_inputs = create_input(all_flair_patches)\nt1wce_inputs = create_input(all_t1wce_patches)\nt1w_inputs = create_input(all_t1w_patches)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:21:46.316148Z","iopub.execute_input":"2021-08-19T13:21:46.316513Z","iopub.status.idle":"2021-08-19T13:22:47.930959Z","shell.execute_reply.started":"2021-08-19T13:21:46.316473Z","shell.execute_reply":"2021-08-19T13:22:47.929954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd \nimport random\nimport cv2\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport keras\n\nimport keras.backend as K\nfrom keras.models import Model, Sequential\nfrom keras.layers import Input, Dense, Flatten, Dropout, BatchNormalization\nfrom keras.layers import Conv2D, SeparableConv2D, MaxPool2D, LeakyReLU, Activation, GlobalAveragePooling2D\nfrom keras.optimizers import Adam, Adamax, Adagrad\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, EarlyStopping\nimport tensorflow as tf\nfrom keras.optimizers import SGD\nfrom keras.utils.np_utils import to_categorical","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:22:47.932499Z","iopub.execute_input":"2021-08-19T13:22:47.932868Z","iopub.status.idle":"2021-08-19T13:22:52.213973Z","shell.execute_reply.started":"2021-08-19T13:22:47.932829Z","shell.execute_reply":"2021-08-19T13:22:52.213088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"flair_inputs= np.asarray(flair_inputs)\nt1w_inputs= np.asarray(t1w_inputs)\nt1wce_inputs= np.asarray(t1wce_inputs)\nt2w_inputs = np.asarray(t2w_inputs)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:22:52.215281Z","iopub.execute_input":"2021-08-19T13:22:52.215645Z","iopub.status.idle":"2021-08-19T13:22:52.223279Z","shell.execute_reply.started":"2021-08-19T13:22:52.215607Z","shell.execute_reply":"2021-08-19T13:22:52.222495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom IPython.display import Image\nfrom sklearn.metrics import confusion_matrix\nnp.random.seed(1)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:22:52.225582Z","iopub.execute_input":"2021-08-19T13:22:52.225985Z","iopub.status.idle":"2021-08-19T13:22:52.936156Z","shell.execute_reply.started":"2021-08-19T13:22:52.225944Z","shell.execute_reply":"2021-08-19T13:22:52.935284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import layers\ndef get_model(optimizer):\n    \"\"\"Build a 3D convolutional neural network model.\"\"\"\n\n    inputs = keras.Input((256,256,3,1))\n    \n    \n\n    x = layers.Conv3D(filters=64, kernel_size=3, activation=\"relu\",padding='same')(inputs)\n    x = layers.MaxPool3D(pool_size=2)(x)\n    x = layers.BatchNormalization()(x)\n\n    #x = layers.Conv3D(filters=64, kernel_size=3, activation=\"relu\",padding='same')(x)\n    #x = layers.MaxPool3D(pool_size=2)(x)\n    #x = layers.BatchNormalization()(x)\n\n    x = layers.Conv3D(filters=128, kernel_size=3, activation=\"relu\",padding='same')(inputs)\n    x = layers.MaxPool3D(pool_size=2)(x)\n    x = layers.BatchNormalization()(x)\n\n    #x = layers.Conv3D(filters=256, kernel_size=3, activation=\"relu\",padding='same')(x)\n    #x = layers.MaxPool3D(pool_size=2)(x)\n    #x = layers.BatchNormalization()(x)\n    \n    x = layers.GlobalAveragePooling3D()(x)\n    #x=layers.Flatten()(x)\n    #x = layers.Dense(units=1024, activation=\"relu\")(x)\n    #x = layers.Dropout(0.3)(x)\n    x = layers.Dense(units=512, activation=\"relu\")(x)\n    x = layers.Dropout(0.3)(x)\n    \n    x = layers.Dense(units=256, activation=\"relu\")(x)\n    x = layers.Dropout(0.3)(x)\n    \n\n    outputs = layers.Dense(units=1, activation=\"sigmoid\")(x)\n\n    # Define the model.\n    model = keras.Model(inputs, outputs, name=\"3dcnn\")\n    model.compile(loss='binary_crossentropy',\n                  optimizer=optimizer, metrics=['accuracy'])\n    return model\n\n\n# Build model.\nmodel = get_model('Adam')","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:33:13.736768Z","iopub.execute_input":"2021-08-19T13:33:13.737127Z","iopub.status.idle":"2021-08-19T13:33:13.832033Z","shell.execute_reply.started":"2021-08-19T13:33:13.737095Z","shell.execute_reply":"2021-08-19T13:33:13.831223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**For each input set, train the 3D-CNN model and save them.**","metadata":{}},{"cell_type":"code","source":"reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.3, patience=3, mode='auto', verbose = 1)\ncallbacks = [ModelCheckpoint(filepath='/kaggle/output/models/best_model.h5', monitor='val_loss', save_best_only=True)]\nx_train, x_valid, y_train, y_valid = train_test_split(flair_inputs, labels, test_size = 0.2, random_state = 1)\noptimizers= ['SGD', 'RMSprop', 'Adagrad', 'Adadelta', 'Adam', 'Adamax', 'Nadam']\nearly_stop = EarlyStopping(monitor='val_loss', min_delta=0.1, patience=3, mode='min')\nx_train = x_train/255\nx_valid = x_valid/255\nmodel=get_model('Adam')\nhistory = model.fit(x_train, y_train, epochs=50, batch_size=8,shuffle=True, validation_data=(x_valid, y_valid),callbacks=[early_stop])","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:54:01.780172Z","iopub.execute_input":"2021-08-19T13:54:01.780542Z","iopub.status.idle":"2021-08-19T13:54:20.200838Z","shell.execute_reply.started":"2021-08-19T13:54:01.780506Z","shell.execute_reply":"2021-08-19T13:54:20.199992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('/kaggle/t1winputs.hdf5')\nmodel_t1w= keras.models.load_model('/kaggle/t1winputs.hdf5')","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:52:38.252864Z","iopub.execute_input":"2021-08-19T13:52:38.253213Z","iopub.status.idle":"2021-08-19T13:52:38.418474Z","shell.execute_reply.started":"2021-08-19T13:52:38.253182Z","shell.execute_reply":"2021-08-19T13:52:38.417552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('/kaggle/t1wceinputs.hdf5')\nmodel_t1wce= keras.models.load_model('/kaggle/t1wceinputs.hdf5')","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:53:08.501128Z","iopub.execute_input":"2021-08-19T13:53:08.501494Z","iopub.status.idle":"2021-08-19T13:53:08.698286Z","shell.execute_reply.started":"2021-08-19T13:53:08.50146Z","shell.execute_reply":"2021-08-19T13:53:08.69576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('/kaggle/t2winputs.hdf5')\nmodel_t2w= keras.models.load_model('/kaggle/t2winputs.hdf5')","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:53:52.347336Z","iopub.execute_input":"2021-08-19T13:53:52.347716Z","iopub.status.idle":"2021-08-19T13:53:52.505899Z","shell.execute_reply.started":"2021-08-19T13:53:52.347685Z","shell.execute_reply":"2021-08-19T13:53:52.504992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('/kaggle/flairinputs.hdf5')\nmodel_flair= keras.models.load_model('/kaggle/flairinputs.hdf5')","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:54:23.789679Z","iopub.execute_input":"2021-08-19T13:54:23.790034Z","iopub.status.idle":"2021-08-19T13:54:24.465902Z","shell.execute_reply.started":"2021-08-19T13:54:23.790002Z","shell.execute_reply":"2021-08-19T13:54:24.464951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds_flair=model_flair.predict(x_valid)\npreds_t1w=model_t1w.predict(x_valid)\npreds_t2w=model_t2w.predict(x_valid)\npreds_t1wce=model_t1wce.predict(x_valid)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:54:29.923133Z","iopub.execute_input":"2021-08-19T13:54:29.923508Z","iopub.status.idle":"2021-08-19T13:54:32.117432Z","shell.execute_reply.started":"2021-08-19T13:54:29.92347Z","shell.execute_reply":"2021-08-19T13:54:32.116469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = [(g + h + a + b) / 4 for g, h, a, b in zip(preds_flair,preds_t1w, preds_t2w,preds_t1wce)]","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:54:35.758893Z","iopub.execute_input":"2021-08-19T13:54:35.759244Z","iopub.status.idle":"2021-08-19T13:54:35.76465Z","shell.execute_reply.started":"2021-08-19T13:54:35.759212Z","shell.execute_reply":"2021-08-19T13:54:35.763692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import roc_curve,roc_auc_score\n\nfpr , tpr , thresholds = roc_curve ( y_valid , mean)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:37:02.767906Z","iopub.execute_input":"2021-08-19T13:37:02.768259Z","iopub.status.idle":"2021-08-19T13:37:02.774534Z","shell.execute_reply.started":"2021-08-19T13:37:02.768226Z","shell.execute_reply":"2021-08-19T13:37:02.773226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_roc_curve(fpr,tpr): \n  plt.plot(fpr,tpr) \n  plt.axis([0,1,0,1]) \n  plt.xlabel('False Positive Rate') \n  plt.ylabel('True Positive Rate') \n  plt.show()    \n  \nplot_roc_curve (fpr,tpr) ","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:37:04.836394Z","iopub.execute_input":"2021-08-19T13:37:04.836748Z","iopub.status.idle":"2021-08-19T13:37:04.959143Z","shell.execute_reply.started":"2021-08-19T13:37:04.836717Z","shell.execute_reply":"2021-08-19T13:37:04.958333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"auc_score=roc_auc_score(y_valid,mean)\nprint(auc_score)","metadata":{"execution":{"iopub.status.busy":"2021-08-19T13:54:44.4322Z","iopub.execute_input":"2021-08-19T13:54:44.432571Z","iopub.status.idle":"2021-08-19T13:54:44.440751Z","shell.execute_reply.started":"2021-08-19T13:54:44.432537Z","shell.execute_reply":"2021-08-19T13:54:44.439603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**TESTING PART !!!**","metadata":{}},{"cell_type":"markdown","source":"**Load my models**","metadata":{}},{"cell_type":"code","source":"model_t1w= keras.models.load_model('/kaggle/t1winputs.hdf5')\nmodel_t1wce= keras.models.load_model('/kaggle/t1wceinputs.hdf5')\nmodel_t2w= keras.models.load_model('/kaggle/t2winputs.hdf5')\nmodel_flair= keras.models.load_model('/kaggle/flairinputs.hdf5')","metadata":{"execution":{"iopub.status.busy":"2021-08-19T15:17:53.541294Z","iopub.execute_input":"2021-08-19T15:17:53.541687Z","iopub.status.idle":"2021-08-19T15:17:54.039107Z","shell.execute_reply.started":"2021-08-19T15:17:53.541653Z","shell.execute_reply":"2021-08-19T15:17:54.038258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\ndef create_input(patches, number_image):\n    inputs=np.zeros((number_image,256,256,3))\n    for i in range(0,len(patches)):\n        for j in range(len(patches[i])//2,(len(patches[i])//2)+3):\n            img= load_dicom(patches[i][j])\n            image_array = cv2.resize(img, (256,256), interpolation=cv2.INTER_AREA)\n            image_array = np.expand_dims(image_array, -1)\n        inputs[i]=image_array\n    return inputs","metadata":{"execution":{"iopub.status.busy":"2021-08-19T15:17:57.486011Z","iopub.execute_input":"2021-08-19T15:17:57.486341Z","iopub.status.idle":"2021-08-19T15:17:57.492894Z","shell.execute_reply.started":"2021-08-19T15:17:57.486310Z","shell.execute_reply":"2021-08-19T15:17:57.491917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testimages= glob('/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/test/*/', recursive=True)\ntestimages.sort(key=natural_keys)\nflair_patches = []\nt1w_patches=[]\nt1wce_patches=[]\nt2w_patches=[]\nfor subfolder in testimages:\n    flair_patches.append(glob(subfolder + 'FLAIR/**/**/*.dcm', recursive=True))\n    t1w_patches.append(glob(subfolder + 'T1w/**/**/*.dcm', recursive=True))\n    t1wce_patches.append(glob(subfolder + 'T1wCE/**/**/*.dcm', recursive=True))\n    t2w_patches.append(glob(subfolder + 'T2w/**/**/*.dcm', recursive=True))\nall_flair_patches = []\nall_slice(flair_patches,all_flair_patches)\nall_t1w_patches =[]\nall_t1w_patches = all_slice(t1w_patches,all_t1w_patches)\nall_t1wce_patches=[]\nall_t1wce_patches = all_slice(t1wce_patches,all_t1wce_patches)\nall_t2w_patches=[]\nall_t2w_patches = all_slice(t2w_patches,all_t2w_patches)\nt2w_inputs = create_input(all_t2w_patches, len(testimages))\nflair_inputs = create_input(all_flair_patches,len(testimages))\nt1wce_inputs = create_input(all_t1wce_patches,len(testimages))\nt1w_inputs = create_input(all_t1w_patches,len(testimages))\ntestflair_inputs= np.asarray(flair_inputs)/255\ntestt1w_inputs= np.asarray(t1w_inputs)/255\ntestt1wce_inputs= np.asarray(t1wce_inputs)/255\ntestt2w_inputs = np.asarray(t2w_inputs)/255\npreds_flair=model_flair.predict(testflair_inputs)\npreds_t1w=model_t1w.predict(testt1w_inputs)\npreds_t2w=model_t2w.predict(testt2w_inputs)\npreds_t1wce=model_t1wce.predict(testt1wce_inputs)\nmean = [(g + h + a + b) / 4 for g, h, a, b in zip(preds_flair,preds_t1w, preds_t2w,preds_t1wce)]","metadata":{"execution":{"iopub.status.busy":"2021-08-19T15:18:04.839136Z","iopub.execute_input":"2021-08-19T15:18:04.839492Z","iopub.status.idle":"2021-08-19T15:18:11.324526Z","shell.execute_reply.started":"2021-08-19T15:18:04.839458Z","shell.execute_reply":"2021-08-19T15:18:11.323639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nsample=pd.read_csv(\"/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/sample_submission.csv\",index_col=\"BraTS21ID\")\nsample[\"MGMT_value\"] = 0\nsample[\"MGMT_value\"] = [str(a)[1:-1] for a in mean]\nsample[\"MGMT_value\"].to_csv(\"submission.csv\")\n","metadata":{"execution":{"iopub.status.busy":"2021-08-19T15:18:14.074832Z","iopub.execute_input":"2021-08-19T15:18:14.075185Z","iopub.status.idle":"2021-08-19T15:18:14.103155Z","shell.execute_reply.started":"2021-08-19T15:18:14.075153Z","shell.execute_reply":"2021-08-19T15:18:14.102397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample","metadata":{"execution":{"iopub.status.busy":"2021-08-19T15:18:18.645658Z","iopub.execute_input":"2021-08-19T15:18:18.646004Z","iopub.status.idle":"2021-08-19T15:18:18.657788Z","shell.execute_reply.started":"2021-08-19T15:18:18.645974Z","shell.execute_reply":"2021-08-19T15:18:18.656813Z"},"trusted":true},"execution_count":null,"outputs":[]}]}