{"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":"# pynnrd kütüphanesi kaggle sisteminde mevcut olmadığı için pip ile indirildi\n!pip install pynrrd","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:57:42.168204Z","iopub.execute_input":"2023-05-22T11:57:42.168522Z","iopub.status.idle":"2023-05-22T11:57:49.424984Z","shell.execute_reply.started":"2023-05-22T11:57:42.168469Z","shell.execute_reply":"2023-05-22T11:57:49.424147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport pydicom\nimport os\nimport matplotlib.pyplot as plt\nimport collections\nfrom tqdm import tqdm_notebook as tqdm\nfrom datetime import datetime\nimport seaborn as sns\nimport nrrd\nimport warnings\nwarnings.filterwarnings('ignore')\n\nfrom math import ceil, floor, log\nimport cv2\n\nimport tensorflow as tf\nimport keras\n\nimport sys\n\n# from keras_applications.resnet import ResNet50\nfrom keras_applications.inception_v3 import InceptionV3\n\nfrom sklearn.model_selection import ShuffleSplit\nfrom sklearn.metrics import confusion_matrix, classification_report, multilabel_confusion_matrix\ninput_path = \"/kaggle/input/rsna-intracranial-hemorrhage-detection/rsna-intracranial-hemorrhage-detection/\"\ntest_images_dir = input_path + 'stage_2_test/'\ntrain_images_dir = input_path + 'stage_2_train/'","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-22T11:57:49.427851Z","iopub.execute_input":"2023-05-22T11:57:49.428356Z","iopub.status.idle":"2023-05-22T11:57:52.701339Z","shell.execute_reply.started":"2023-05-22T11:57:49.428171Z","shell.execute_reply":"2023-05-22T11:57:52.700388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 0. Preprocessing (brain + subudral + soft)\n(REMOVED) Many thanks to [Ryan Epp](https://www.kaggle.com/reppic/gradient-sigmoid-windowing). Code is taken from his kernel (see his kernel for more information and other peoples work --- for example [David Tang](https://www.kaggle.com/dcstang/see-like-a-radiologist-with-systematic-windowing), [Marco](https://www.kaggle.com/marcovasquez/basic-eda-data-visualization), [Nanashi](https://www.kaggle.com/jesucristo/rsna-introduction-eda-models), and [Richard McKinley](https://www.kaggle.com/omission/eda-view-dicom-images-with-correct-windowing)). At first I thought I couldn't use sigmoid windowing for this kernel because of how expensive it is to do, but I could resize the image prior to the transformation to save a lot of computation. Not sure how much this will affect the performance of the training, but it really speeded it up.<br>\n(NEW) Based on two great kernels: [appian42's repo](https://github.com/appian42/kaggle-rsna-intracranial-hemorrhage/) (windowing), [Jeremy's kernel](https://www.kaggle.com/jhoward/cleaning-the-data-for-rapid-prototyping-fastai) (cleaning)","metadata":{}},{"cell_type":"code","source":"# https://www.kaggle.com/code/reppic/gradient-sigmoid-windowing\ndef correct_dcm(dcm):\n    x = dcm.pixel_array + 1000\n    px_mode = 4096\n    x[x>=px_mode] = x[x>=px_mode] - px_mode\n    dcm.PixelData = x.tobytes()\n    dcm.RescaleIntercept = -1000\n\ndef window_image(dcm, window_center, window_width):\n    if (dcm.BitsStored == 12) and (dcm.PixelRepresentation == 0) and (int(dcm.RescaleIntercept) > -100):\n        correct_dcm(dcm)\n    img = dcm.pixel_array * dcm.RescaleSlope + dcm.RescaleIntercept\n    img_min = window_center - window_width // 2\n    img_max = window_center + window_width // 2\n    img = np.clip(img, img_min, img_max)\n\n    return img\n\ndef bsb_window(dcm):\n    brain_img = window_image(dcm, 40, 80)\n    subdural_img = window_image(dcm, 80, 200)\n    soft_img = window_image(dcm, 40, 380)\n    \n    brain_img = (brain_img - 0) / 80\n    subdural_img = (subdural_img - (-20)) / 200\n    soft_img = (soft_img - (-150)) / 380\n    bsb_img = np.array([brain_img, subdural_img, soft_img]).transpose(1,2,0)\n\n    return bsb_img\n\n# Sanity Check\n# Example dicoms: ID_2669954a7, ID_5c8b5d701, ID_52c9913b1\n\ndicom = pydicom.dcmread(train_images_dir + 'ID_5c8b5d701' + '.dcm')\n#                                     ID  Label\n# 4045566          ID_5c8b5d701_epidural      0\n# 4045567  ID_5c8b5d701_intraparenchymal      1\n# 4045568  ID_5c8b5d701_intraventricular      0\n# 4045569      ID_5c8b5d701_subarachnoid      1\n# 4045570          ID_5c8b5d701_subdural      1\n# 4045571               ID_5c8b5d701_any      1\nplt.imshow(bsb_window(dicom), cmap=plt.cm.bone);\n","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:57:52.703967Z","iopub.execute_input":"2023-05-22T11:57:52.704586Z","iopub.status.idle":"2023-05-22T11:57:52.972555Z","shell.execute_reply.started":"2023-05-22T11:57:52.704527Z","shell.execute_reply":"2023-05-22T11:57:52.971668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Check (with an example) if the correction works (visually)","metadata":{}},{"cell_type":"code","source":"def window_with_correction(dcm, window_center, window_width):\n    if (dcm.BitsStored == 12) and (dcm.PixelRepresentation == 0) and (int(dcm.RescaleIntercept) > -100):\n        correct_dcm(dcm)\n    img = dcm.pixel_array * dcm.RescaleSlope + dcm.RescaleIntercept\n    img_min = window_center - window_width // 2\n    img_max = window_center + window_width // 2\n    img = np.clip(img, img_min, img_max)\n    return img\n\ndef window_without_correction(dcm, window_center, window_width):\n    img = dcm.pixel_array * dcm.RescaleSlope + dcm.RescaleIntercept\n    img_min = window_center - window_width // 2\n    img_max = window_center + window_width // 2\n    img = np.clip(img, img_min, img_max)\n    return img\n\ndef window_testing(img, window):\n    brain_img = window(img, 40, 80)\n    subdural_img = window(img, 80, 200)\n    soft_img = window(img, 40, 380)\n    \n    brain_img = (brain_img - 0) / 80\n    subdural_img = (subdural_img - (-20)) / 200\n    soft_img = (soft_img - (-150)) / 380\n    bsb_img = np.array([brain_img, subdural_img, soft_img]).transpose(1,2,0)\n\n    return bsb_img\n\n# example of a \"bad data point\" (i.e. (dcm.BitsStored == 12) and (dcm.PixelRepresentation == 0) and (int(dcm.RescaleIntercept) > -100) == True)\ndicom = pydicom.dcmread(train_images_dir + \"ID_036db39b7\" + \".dcm\")\n\nfig, ax = plt.subplots(1, 2)\n\nax[0].imshow(window_testing(dicom, window_without_correction), cmap=plt.cm.bone);\nax[0].set_title(\"original\")\nax[1].imshow(window_testing(dicom, window_with_correction), cmap=plt.cm.bone);\nax[1].set_title(\"corrected\");","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:57:52.974064Z","iopub.execute_input":"2023-05-22T11:57:52.974551Z","iopub.status.idle":"2023-05-22T11:57:53.301293Z","shell.execute_reply.started":"2023-05-22T11:57:52.974494Z","shell.execute_reply":"2023-05-22T11:57:53.30028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 1. Helper functions\n\n* read and transform dcms to 3-channel inputs for e.g. InceptionV3. \n* uses `bsb_window` from previous cell\n\n\\* (REMOVED) Source for windowing (although now partly removed from this kernel): https://www.kaggle.com/omission/eda-view-dicom-images-with-correct-windowing","metadata":{}},{"cell_type":"code","source":"def _read(path, desired_size):\n    \"\"\"Will be used in DataGenerator\"\"\"\n    \n    dcm = pydicom.dcmread(path)\n    \n    try:\n        img = bsb_window(dcm)\n    except:\n        img = np.zeros(desired_size)\n    \n    \n    img = cv2.resize(img, desired_size[:2], interpolation=cv2.INTER_LINEAR)\n    \n    return img\n\n# Another sanity check \nplt.imshow(\n    _read(train_images_dir+'ID_5c8b5d701'+'.dcm', (128, 128)), cmap=plt.cm.bone\n);","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","execution":{"iopub.status.busy":"2023-05-22T11:57:53.305182Z","iopub.execute_input":"2023-05-22T11:57:53.305812Z","iopub.status.idle":"2023-05-22T11:57:53.599804Z","shell.execute_reply.started":"2023-05-22T11:57:53.305473Z","shell.execute_reply":"2023-05-22T11:57:53.598987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2. Data generators\n\nInherits from keras.utils.Sequence object and thus should be safe for multiprocessing.\n","metadata":{}},{"cell_type":"code","source":"class DataGenerator(keras.utils.Sequence):\n\n    def __init__(self, list_IDs, labels=None, batch_size=1, img_size=(512, 512, 1), \n                 img_dir=train_images_dir, *args, **kwargs):\n\n        self.list_IDs = list_IDs\n        self.labels = labels\n        self.batch_size = batch_size\n        self.img_size = img_size\n        self.img_dir = img_dir\n        self.on_epoch_end()\n\n    def __len__(self):\n        return int(ceil(len(self.indices) / self.batch_size))\n\n    def __getitem__(self, index):\n        indices = self.indices[index*self.batch_size:(index+1)*self.batch_size]\n        list_IDs_temp = [self.list_IDs[k] for k in indices]\n        \n        if self.labels is not None:\n            X, Y = self.__data_generation(list_IDs_temp)\n            return X, Y\n        else:\n            X = self.__data_generation(list_IDs_temp)\n            return X\n        \n    def on_epoch_end(self):\n        \n        \n        if self.labels is not None: # for training phase we undersample and shuffle\n            # keep probability of any=0 and any=1\n            keep_prob = self.labels.iloc[:, 0].map({0: 0.35, 1: 0.5})\n            keep = (keep_prob > np.random.rand(len(keep_prob)))\n            self.indices = np.arange(len(self.list_IDs))[keep]\n            np.random.shuffle(self.indices)\n        else:\n            self.indices = np.arange(len(self.list_IDs))\n\n    def __data_generation(self, list_IDs_temp):\n        X = np.empty((self.batch_size, *self.img_size))\n        \n        if self.labels is not None: # training phase\n            Y = np.empty((self.batch_size, 6), dtype=np.float32)\n        \n            for i, ID in enumerate(list_IDs_temp):\n                X[i,] = _read(self.img_dir+ID+\".dcm\", self.img_size)\n                Y[i,] = self.labels.loc[ID].values\n        \n            return X, Y\n        \n        else: # test phase\n            for i, ID in enumerate(list_IDs_temp):\n                X[i,] = _read(self.img_dir+ID+\".dcm\", self.img_size)\n            \n            return X","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:57:53.605777Z","iopub.execute_input":"2023-05-22T11:57:53.608315Z","iopub.status.idle":"2023-05-22T11:57:53.634438Z","shell.execute_reply.started":"2023-05-22T11:57:53.608256Z","shell.execute_reply":"2023-05-22T11:57:53.633485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3a. loss function and metric","metadata":{}},{"cell_type":"code","source":"from keras import backend as K\n\ndef weighted_log_loss(y_true, y_pred):\n    \"\"\"\n    Can be used as the loss function in model.compile()\n    ---------------------------------------------------\n    \"\"\"\n    \n    class_weights = np.array([2., 1., 1., 1., 1., 1.])\n    \n    eps = K.epsilon()\n    \n    y_pred = K.clip(y_pred, eps, 1.0-eps)\n\n    out = -(         y_true  * K.log(      y_pred) * class_weights\n            + (1.0 - y_true) * K.log(1.0 - y_pred) * class_weights)\n    \n    return K.mean(out, axis=-1)\n\n\ndef _normalized_weighted_average(arr, weights=None):\n    \"\"\"\n    A simple Keras implementation that mimics that of \n    numpy.average(), specifically for this competition\n    \"\"\"\n    \n    if weights is not None:\n        scl = K.sum(weights)\n        weights = K.expand_dims(weights, axis=1)\n        return K.sum(K.dot(arr, weights), axis=1) / scl\n    return K.mean(arr, axis=1)\n\n\ndef weighted_loss(y_true, y_pred):\n    \"\"\"\n    Will be used as the metric in model.compile()\n    ---------------------------------------------\n    \n    Similar to the custom loss function 'weighted_log_loss()' above\n    but with normalized weights, which should be very similar \n    to the official competition metric:\n        https://www.kaggle.com/kambarakun/lb-probe-weights-n-of-positives-scoring\n    and hence:\n        sklearn.metrics.log_loss with sample weights\n    \"\"\"\n    \n    class_weights = K.variable([2., 1., 1., 1., 1., 1.])\n    \n    eps = K.epsilon()\n    \n    y_pred = K.clip(y_pred, eps, 1.0-eps)\n\n    loss = -(        y_true  * K.log(      y_pred)\n            + (1.0 - y_true) * K.log(1.0 - y_pred))\n    \n    loss_samples = _normalized_weighted_average(loss, class_weights)\n    \n    return K.mean(loss_samples)\n\n\ndef weighted_log_loss_metric(trues, preds):\n    \"\"\"\n    Will be used to calculate the log loss \n    of the validation set in PredictionCheckpoint()\n    ------------------------------------------\n    \"\"\"\n    class_weights = [2., 1., 1., 1., 1., 1.]\n    \n    epsilon = 1e-7\n    \n    preds = np.clip(preds, epsilon, 1-epsilon)\n    loss = trues * np.log(preds) + (1 - trues) * np.log(1 - preds)\n    loss_samples = np.average(loss, axis=1, weights=class_weights)\n\n    return - loss_samples.mean()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:57:53.640096Z","iopub.execute_input":"2023-05-22T11:57:53.642828Z","iopub.status.idle":"2023-05-22T11:57:53.666032Z","shell.execute_reply.started":"2023-05-22T11:57:53.642776Z","shell.execute_reply":"2023-05-22T11:57:53.665053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3b. Model\n\nModel is divided into three parts: <br> \n\n* (REMOVED) The initial layer, which will transform/map input image of shape (\\_, \\_, 1) to another \"image\" of shape (\\_, \\_, 3).\n\n* The new input image is then passed through InceptionV3 (which I named \"engine\"). InceptionV3 could be replaced by any of the available architectures in keras_application.\n\n* Finally, the output from InceptionV3 goes through average pooling followed by two dense layers (including output layer).","metadata":{}},{"cell_type":"code","source":"\nclass PredictionCheckpoint(keras.callbacks.Callback):\n    \n    def __init__(self, test_df, valid_df, \n                 test_images_dir=test_images_dir, \n                 valid_images_dir=train_images_dir, \n                 batch_size=32, input_size=(224, 224, 3)):\n        \n        self.test_df = test_df\n        self.valid_df = valid_df\n        self.test_images_dir = test_images_dir\n        self.valid_images_dir = valid_images_dir\n        self.batch_size = batch_size\n        self.input_size = input_size\n        \n    def on_train_begin(self, logs={}):\n        self.test_predictions = []\n        self.valid_predictions = []\n        \n    def on_epoch_end(self,batch, logs={}):\n        self.test_predictions.append(\n            self.model.predict_generator(\n                DataGenerator(self.test_df.index, None, self.batch_size, self.input_size, self.test_images_dir), verbose=2)[:len(self.test_df)])\n        \n        # Commented out to save time\n#         self.valid_predictions.append(\n#             self.model.predict_generator(\n#                 DataGenerator(self.valid_df.index, None, self.batch_size, self.input_size, self.valid_images_dir), verbose=2)[:len(self.valid_df)])\n        \n#         print(\"validation loss: %.4f\" %\n#               weighted_log_loss_metric(self.valid_df.values, \n#                                    np.average(self.valid_predictions, axis=0, \n#                                               weights=[2**i for i in range(len(self.valid_predictions))])))\n        \n        # here you could also save the predictions with np.save()\n\n\nclass MyDeepModel:\n    \n    def __init__(self, engine, input_dims, batch_size=5, num_epochs=4, learning_rate=1e-3, \n                 decay_rate=1.0, decay_steps=1, weights=\"imagenet\", verbose=1):\n        \n        self.engine = engine\n        self.input_dims = input_dims\n        self.batch_size = batch_size\n        self.num_epochs = num_epochs\n        self.learning_rate = learning_rate\n        self.decay_rate = decay_rate\n        self.decay_steps = decay_steps\n        self.weights = weights\n        self.verbose = verbose\n        self._build()\n\n    def _build(self):\n        \n        \n        engine = self.engine(include_top=False, weights=self.weights, input_shape=self.input_dims,\n                             backend = keras.backend, layers = keras.layers,\n                             models = keras.models, utils = keras.utils)\n        \n        x = keras.layers.GlobalAveragePooling2D(name='avg_pool')(engine.output)\n#         x = keras.layers.Dropout(0.2)(x)\n#         x = keras.layers.Dense(keras.backend.int_shape(x)[1], activation=\"relu\", name=\"dense_hidden_1\")(x)\n#         x = keras.layers.Dropout(0.1)(x)\n        out = keras.layers.Dense(6, activation=\"sigmoid\", name='dense_output')(x)\n\n        self.model = keras.models.Model(inputs=engine.input, outputs=out)\n\n        self.model.compile(loss=\"binary_crossentropy\", optimizer=keras.optimizers.Adam(), metrics=[weighted_loss])\n    \n\n    def fit_and_predict(self, train_df, valid_df, test_df):\n        \n        # callbacks\n        pred_history = PredictionCheckpoint(test_df, valid_df, input_size=self.input_dims)\n        #checkpointer = keras.callbacks.ModelCheckpoint(filepath='%s-{epoch:02d}.hdf5' % self.engine.__name__, verbose=1, save_weights_only=True, save_best_only=False)\n        scheduler = keras.callbacks.LearningRateScheduler(lambda epoch: self.learning_rate * pow(self.decay_rate, floor(epoch / self.decay_steps)))\n        \n        self.model.fit_generator(\n            DataGenerator(\n                train_df.index, \n                train_df, \n                self.batch_size, \n                self.input_dims, \n                train_images_dir\n            ),\n            epochs=self.num_epochs,\n            verbose=self.verbose,\n            use_multiprocessing=True,\n            workers=4,\n            callbacks=[pred_history, scheduler]\n        )\n        \n        return pred_history\n    \n    def save(self, path):\n        self.model.save_weights(path)\n    \n    def load(self, path):\n        self.model.load_weights(path)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-05-22T11:57:53.67148Z","iopub.execute_input":"2023-05-22T11:57:53.673727Z","iopub.status.idle":"2023-05-22T11:57:53.705464Z","shell.execute_reply.started":"2023-05-22T11:57:53.673676Z","shell.execute_reply":"2023-05-22T11:57:53.704467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 4. Read csv files\n","metadata":{}},{"cell_type":"code","source":"def read_testset(filename=input_path+\"stage_2_sample_submission.csv\"):\n    df = pd.read_csv(filename)\n    df[\"Image\"] = df[\"ID\"].str.slice(stop=12)\n    df[\"Diagnosis\"] = df[\"ID\"].str.slice(start=13)\n    \n    df = df.loc[:, [\"Label\", \"Diagnosis\", \"Image\"]]\n    df = df.set_index(['Image', 'Diagnosis']).unstack(level=-1)\n    \n    return df\n\ndef read_trainset(filename=input_path+\"stage_2_train.csv\"):\n    df = pd.read_csv(filename)\n    df[\"Image\"] = df[\"ID\"].str.slice(stop=12)\n    df[\"Diagnosis\"] = df[\"ID\"].str.slice(start=13)\n    \n    duplicates_to_remove = [\n        56346, 56347, 56348, 56349,\n        56350, 56351, 1171830, 1171831,\n        1171832, 1171833, 1171834, 1171835,\n        3705312, 3705313, 3705314, 3705315,\n        3705316, 3705317, 3842478, 3842479,\n        3842480, 3842481, 3842482, 3842483\n    ]\n    \n    df = df.drop(index=duplicates_to_remove)\n    df = df.reset_index(drop=True)\n    \n    df = df.loc[:, [\"Label\", \"Diagnosis\", \"Image\"]]\n    df = df.set_index(['Image', 'Diagnosis']).unstack(level=-1)\n    \n    return df\n\n    \ntest_df = read_testset()\ndf = read_trainset()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:57:53.710563Z","iopub.execute_input":"2023-05-22T11:57:53.71283Z","iopub.status.idle":"2023-05-22T11:58:13.43275Z","shell.execute_reply.started":"2023-05-22T11:57:53.71278Z","shell.execute_reply":"2023-05-22T11:58:13.431863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head(3)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:13.434319Z","iopub.execute_input":"2023-05-22T11:58:13.434825Z","iopub.status.idle":"2023-05-22T11:58:13.587783Z","shell.execute_reply.started":"2023-05-22T11:58:13.434705Z","shell.execute_reply":"2023-05-22T11:58:13.587012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head(3)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:13.589272Z","iopub.execute_input":"2023-05-22T11:58:13.589763Z","iopub.status.idle":"2023-05-22T11:58:13.605285Z","shell.execute_reply.started":"2023-05-22T11:58:13.589566Z","shell.execute_reply":"2023-05-22T11:58:13.60441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_df)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:13.606753Z","iopub.execute_input":"2023-05-22T11:58:13.607434Z","iopub.status.idle":"2023-05-22T11:58:13.615381Z","shell.execute_reply.started":"2023-05-22T11:58:13.607383Z","shell.execute_reply":"2023-05-22T11:58:13.614419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 5. Train model and predict\n\n*Using train, validation and test set* <br>\n\nTraining for 5 epochs with Adam optimizer, with a learning rate of 0.0005 and decay rate of 0.8. The validation predictions are \\[exponentially weighted\\] averaged over all 5 epochs (not in this commit). `fit_and_predict` returns validation and test predictions for all epochs.\n","metadata":{}},{"cell_type":"code","source":"# train set (00%) and validation set (10%)\nss = ShuffleSplit(n_splits=10, test_size=0.1, random_state=42).split(df.index)\n\n# lets go for the first fold only\ntrain_idx, valid_idx = next(ss)\n\n# obtain model\nmodel = MyDeepModel(engine=InceptionV3, input_dims=(256, 256, 3), batch_size=32, learning_rate=5e-4,\n                    num_epochs=5, decay_rate=0.8, decay_steps=1, weights=\"imagenet\", verbose=1)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:13.616885Z","iopub.execute_input":"2023-05-22T11:58:13.617461Z","iopub.status.idle":"2023-05-22T11:58:29.316283Z","shell.execute_reply.started":"2023-05-22T11:58:13.617408Z","shell.execute_reply":"2023-05-22T11:58:29.315532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# obtain test + validation predictions (history.test_predictions, history.valid_predictions)\n#history = model.fit_and_predict(df.iloc[train_idx], df.iloc[valid_idx], test_df)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:29.317724Z","iopub.execute_input":"2023-05-22T11:58:29.318039Z","iopub.status.idle":"2023-05-22T11:58:29.322676Z","shell.execute_reply.started":"2023-05-22T11:58:29.317989Z","shell.execute_reply":"2023-05-22T11:58:29.321859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 6. Submit test predictions","metadata":{}},{"cell_type":"code","source":"#test_df.iloc[:, :] = np.average(history.test_predictions, axis=0, weights=[0, 1, 2, 4, 6]) # let's do a weighted average for epochs (>1)\n\n#test_df = test_df.stack().reset_index()\n\n#test_df.insert(loc=0, column='ID', value=test_df['Image'].astype(str) + \"_\" + test_df['Diagnosis'])\n\n#test_df = test_df.drop([\"Image\", \"Diagnosis\"], axis=1)\n\n#test_df.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:29.323973Z","iopub.execute_input":"2023-05-22T11:58:29.324449Z","iopub.status.idle":"2023-05-22T11:58:29.332529Z","shell.execute_reply.started":"2023-05-22T11:58:29.324368Z","shell.execute_reply":"2023-05-22T11:58:29.331492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model.save(\"weights\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:29.334066Z","iopub.execute_input":"2023-05-22T11:58:29.334608Z","iopub.status.idle":"2023-05-22T11:58:29.340998Z","shell.execute_reply.started":"2023-05-22T11:58:29.334426Z","shell.execute_reply":"2023-05-22T11:58:29.339015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model.model.save(\"model\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:29.342428Z","iopub.execute_input":"2023-05-22T11:58:29.342923Z","iopub.status.idle":"2023-05-22T11:58:29.348273Z","shell.execute_reply.started":"2023-05-22T11:58:29.342856Z","shell.execute_reply":"2023-05-22T11:58:29.347229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# RSNA VERİ SETİ ÜZERİNDEN TAHMİNLER VE GÖRSELLEŞTİRME","metadata":{}},{"cell_type":"code","source":"# Eğitilen modelin yüklenmesi\nmodel.load(\"/kaggle/input/test-weight/weights\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:29.349871Z","iopub.execute_input":"2023-05-22T11:58:29.350398Z","iopub.status.idle":"2023-05-22T11:58:32.347841Z","shell.execute_reply.started":"2023-05-22T11:58:29.350349Z","shell.execute_reply":"2023-05-22T11:58:32.346957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model.model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:32.349459Z","iopub.execute_input":"2023-05-22T11:58:32.349784Z","iopub.status.idle":"2023-05-22T11:58:32.354229Z","shell.execute_reply.started":"2023-05-22T11:58:32.349732Z","shell.execute_reply":"2023-05-22T11:58:32.353382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.model.predict(np.expand_dims(_read(train_images_dir+'ID_5c8b5d701'+'.dcm', (256,256,1)),0))\n# Model tahmini yapılabilmesi için input'un uygun formata getirilmesi gerekmektedir.\n# nğ.expand_dims komutu görseli modele uygun boyuta genişletmektedir.\n#                                     ID  Label\n# 4045566          ID_5c8b5d701_epidural      0\n# 4045567  ID_5c8b5d701_intraparenchymal      1\n# 4045568  ID_5c8b5d701_intraventricular      0\n# 4045569      ID_5c8b5d701_subarachnoid      1\n# 4045570          ID_5c8b5d701_subdural      1\n# 4045571               ID_5c8b5d701_any      1","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:32.355854Z","iopub.execute_input":"2023-05-22T11:58:32.356593Z","iopub.status.idle":"2023-05-22T11:58:36.123712Z","shell.execute_reply.started":"2023-05-22T11:58:32.356541Z","shell.execute_reply":"2023-05-22T11:58:36.123033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head(20)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:36.125301Z","iopub.execute_input":"2023-05-22T11:58:36.125693Z","iopub.status.idle":"2023-05-22T11:58:36.144121Z","shell.execute_reply.started":"2023-05-22T11:58:36.125598Z","shell.execute_reply":"2023-05-22T11:58:36.143089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Kaggle veri seti içerisindeki sonuçların incelenmesi","metadata":{}},{"cell_type":"code","source":"temp_df =  pd.DataFrame(columns=[\"any\", \"epidural\", \"intraparenchymal\", \"intraventricular\", \"subarachnoid\", \"subdural\"])\npredict = model.model.predict(np.expand_dims(_read(train_images_dir+'ID_0002081b6'+'.dcm', (256,256,3)),0))[0]\ntemp_df.loc[len(temp_df)] = predict # Elde edilen prediction sonuçları dataframe içerisindeki son satıra yerleştirildi\ntemp_df\n# Gerçek Hasta Değerleri\n# any\tepidural\tintraparenchymal\tintraventricular\tsubarachnoid\tsubdural\n# 1\t       0\t           1\t              0\t                 0\t          0 ","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:36.145703Z","iopub.execute_input":"2023-05-22T11:58:36.146296Z","iopub.status.idle":"2023-05-22T11:58:36.226771Z","shell.execute_reply.started":"2023-05-22T11:58:36.146224Z","shell.execute_reply":"2023-05-22T11:58:36.225936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Notebook'un en başındaki normal bir hastanın windowing yapılarak matplotlib ile tekrar görselleştirilmesi\nplt.imshow(\n    _read(train_images_dir+'ID_0002081b6'+'.dcm', (256, 256)), cmap=plt.cm.bone\n);","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:36.228112Z","iopub.execute_input":"2023-05-22T11:58:36.228449Z","iopub.status.idle":"2023-05-22T11:58:36.409177Z","shell.execute_reply.started":"2023-05-22T11:58:36.228399Z","shell.execute_reply":"2023-05-22T11:58:36.408289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_df =  pd.DataFrame(columns=[\"any\", \"epidural\", \"intraparenchymal\", \"intraventricular\", \"subarachnoid\", \"subdural\"])\npredict = model.model.predict(np.expand_dims(_read(train_images_dir+'ID_0004a5701'+'.dcm', (256,256,3)),0))[0]\ntemp_df.loc[len(temp_df)] = predict\ntemp_df\n# Gerçek Hasta Değerleri\n# any\tepidural\tintraparenchymal\tintraventricular\tsubarachnoid\tsubdural\n# 1\t       0\t           0\t              0\t                 0\t          1 \nplt.imshow(\n    _read(train_images_dir+'ID_0004a5701'+'.dcm', (256, 256)), cmap=plt.cm.bone\n);","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:36.410648Z","iopub.execute_input":"2023-05-22T11:58:36.411203Z","iopub.status.idle":"2023-05-22T11:58:36.651845Z","shell.execute_reply.started":"2023-05-22T11:58:36.411146Z","shell.execute_reply":"2023-05-22T11:58:36.650961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_df =  pd.DataFrame(columns=[\"any\", \"epidural\", \"intraparenchymal\", \"intraventricular\", \"subarachnoid\", \"subdural\"])\npredict = model.model.predict(np.expand_dims(_read(train_images_dir+'ID_0002a38ad'+'.dcm', (256,256,3)),0))[0]\ntemp_df.loc[len(temp_df)] = predict\ntemp_df\n# Gerçek Hasta Değerleri\n# any\tepidural\tintraparenchymal\tintraventricular\tsubarachnoid\tsubdural\n# 1\t       0\t           0\t              0\t                 1\t          1","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:36.653385Z","iopub.execute_input":"2023-05-22T11:58:36.65395Z","iopub.status.idle":"2023-05-22T11:58:36.734767Z","shell.execute_reply.started":"2023-05-22T11:58:36.653877Z","shell.execute_reply":"2023-05-22T11:58:36.733844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(\n    _read(train_images_dir+'ID_0002a38ad'+'.dcm', (256, 256)), cmap=plt.cm.bone\n);","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:36.736183Z","iopub.execute_input":"2023-05-22T11:58:36.736482Z","iopub.status.idle":"2023-05-22T11:58:36.911866Z","shell.execute_reply.started":"2023-05-22T11:58:36.73643Z","shell.execute_reply":"2023-05-22T11:58:36.911016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Custom Veri Seti Üzerinde İncelemeler","metadata":{}},{"cell_type":"code","source":"ds = pydicom.dcmread(\"/kaggle/input/intraparamkimal/ser002img00113.dcm\")\nprint(ds)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:36.913434Z","iopub.execute_input":"2023-05-22T11:58:36.913996Z","iopub.status.idle":"2023-05-22T11:58:36.942079Z","shell.execute_reply.started":"2023-05-22T11:58:36.913732Z","shell.execute_reply":"2023-05-22T11:58:36.94125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(\n    _read(\"/kaggle/input/intraparamkimal/ser002img00087.dcm\", (256, 256)), cmap=plt.cm.bone\n);","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:36.943438Z","iopub.execute_input":"2023-05-22T11:58:36.943935Z","iopub.status.idle":"2023-05-22T11:58:37.135567Z","shell.execute_reply.started":"2023-05-22T11:58:36.94386Z","shell.execute_reply":"2023-05-22T11:58:37.134673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(\n    _read(\"/kaggle/input/ventrikler-dcm/ser002img00067.dcm\", (256, 256)), cmap=plt.cm.bone\n);\n","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:37.137001Z","iopub.execute_input":"2023-05-22T11:58:37.137472Z","iopub.status.idle":"2023-05-22T11:58:37.328894Z","shell.execute_reply.started":"2023-05-22T11:58:37.137417Z","shell.execute_reply":"2023-05-22T11:58:37.327762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(\n    _read(\"/kaggle/input/intraparamkimal/ser002img00118.dcm\", (256, 256)), cmap=plt.cm.bone\n);\n","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:37.330148Z","iopub.execute_input":"2023-05-22T11:58:37.330441Z","iopub.status.idle":"2023-05-22T11:58:37.524288Z","shell.execute_reply.started":"2023-05-22T11:58:37.330395Z","shell.execute_reply":"2023-05-22T11:58:37.523283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def detectHemorrhage(fold_path):\n    test_df = pd.DataFrame(columns=[\"dcm_name\", \"any\", \"epidural\", \"intraparenchymal\", \"intraventricular\", \"subarachnoid\", \"subdural\"])\n    for i in os.listdir(fold_path):\n        full_dcm_path = fold_path + \"/\" + i\n        prediction = model.model.predict(np.expand_dims(_read(full_dcm_path, (256,256,3)),0))[0] # Detection happening here\n        prediction = list(prediction)\n        prediction.insert(0, i)\n        test_df.loc[len(test_df)] = prediction\n    return test_df","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:37.526168Z","iopub.execute_input":"2023-05-22T11:58:37.526652Z","iopub.status.idle":"2023-05-22T11:58:37.535668Z","shell.execute_reply.started":"2023-05-22T11:58:37.526457Z","shell.execute_reply":"2023-05-22T11:58:37.534473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Intraparamkimal Tahminleri","metadata":{}},{"cell_type":"code","source":"fold_path  = \"/kaggle/input/intraparamkimal\"\ninstraparamkimal = detectHemorrhage(fold_path)\ninstraparamkimal","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:37.551583Z","iopub.execute_input":"2023-05-22T11:58:37.551852Z","iopub.status.idle":"2023-05-22T11:58:40.144432Z","shell.execute_reply.started":"2023-05-22T11:58:37.5518Z","shell.execute_reply":"2023-05-22T11:58:40.143731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Hastalık Görülmeyen Hastalar Üzerinde Tahminler (Any=0)","metadata":{}},{"cell_type":"code","source":"fold_path  = \"/kaggle/input/temiz-dcm\"\ntemiz = detectHemorrhage(fold_path)\ntemiz.head(50)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:40.151685Z","iopub.execute_input":"2023-05-22T11:58:40.151962Z","iopub.status.idle":"2023-05-22T11:58:43.995069Z","shell.execute_reply.started":"2023-05-22T11:58:40.151893Z","shell.execute_reply":"2023-05-22T11:58:43.994372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Ventrikler Tahminleri","metadata":{}},{"cell_type":"code","source":"fold_path  = \"/kaggle/input/ventrikler-dcm\"\nventrikler = detectHemorrhage(fold_path)\nventrikler.head(50)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:43.996447Z","iopub.execute_input":"2023-05-22T11:58:43.996746Z","iopub.status.idle":"2023-05-22T11:58:45.619188Z","shell.execute_reply.started":"2023-05-22T11:58:43.996693Z","shell.execute_reply":"2023-05-22T11:58:45.618327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Belirli Threshold Değerleri İle Tahminlerin Confusion Matrix'lerinin Çizdirilmesi","metadata":{}},{"cell_type":"code","source":"def detectHemorrhageWithThreshold(fold_path, threshold):\n    # Sonuçların aktarılması için dataframe oluşturma\n    test_df = pd.DataFrame(columns=[\"dcm_name\", \"any\", \"epidural\", \"intraparenchymal\", \"intraventricular\", \"subarachnoid\", \"subdural\"])\n    for i in os.listdir(fold_path): # Path içerisindeki her bir dosyanın ismini döngü ile elde etme\n        full_dcm_path = fold_path + \"/\" + i # Tahmin yapılacak olan dicom görüntüsünün tam dosya yolu\n        # Custom veri seti içerisindeki dicom görselinin önişleme aşamaları gerçekleştirildikten  sonra uygun formatta modele verilmesi ve tahmin işlemi\n        prediction = model.model.predict(np.expand_dims(_read(full_dcm_path, (256,256,3)),0))[0] # Tahmin burada gerçekleşiyor\n        for x in range(len(prediction)): # Bu döngü içerisinde perdiction olarak gelen dizi içerisindeki sonuçlar belirlenen eşik ile filtreleniyor\n            if(prediction[x] >= threshold):\n                prediction[x] = 1 # Eğer threshold'dan büyük bir değer ise 1 olarak değiştir\n            else:\n                prediction[x] = 0 # Eğer threshold'dan küçük bir değer ise 0 olarak değiştir\n        prediction = list(prediction) # Sonuç olarak üretilen prediction dizisini liste olarak aktar\n        prediction.insert(0, i) # Listenin başına tahmini yapılan dosya ismini ekle\n        test_df.loc[len(test_df)] = prediction # Sonucu dataframe'e aktar\n    return test_df # Belirtilen klasör içerisindeki tüm dicom görsellerinin sonuçlarını barındıran dataframe","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:45.620608Z","iopub.execute_input":"2023-05-22T11:58:45.620934Z","iopub.status.idle":"2023-05-22T11:58:45.630921Z","shell.execute_reply.started":"2023-05-22T11:58:45.620867Z","shell.execute_reply":"2023-05-22T11:58:45.629862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Farklı threshold'larda tek bir hastalık türü için denemeler","metadata":{}},{"cell_type":"code","source":"fold_path  = \"/kaggle/input/intraparamkimal\"\ninstraparamkimal_th_0_70 = detectHemorrhageWithThreshold(fold_path, 0.7)\ninstraparamkimal_th_0_60 = detectHemorrhageWithThreshold(fold_path, 0.6)\ninstraparamkimal_th_0_50 = detectHemorrhageWithThreshold(fold_path, 0.5)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:45.632663Z","iopub.execute_input":"2023-05-22T11:58:45.633184Z","iopub.status.idle":"2023-05-22T11:58:51.776447Z","shell.execute_reply.started":"2023-05-22T11:58:45.633007Z","shell.execute_reply":"2023-05-22T11:58:51.775524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"instraparamkimal_th_0_70.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:51.777845Z","iopub.execute_input":"2023-05-22T11:58:51.778182Z","iopub.status.idle":"2023-05-22T11:58:51.795827Z","shell.execute_reply.started":"2023-05-22T11:58:51.778128Z","shell.execute_reply":"2023-05-22T11:58:51.794794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fold_path  = \"/kaggle/input/temiz-dcm\"\ntemiz_th_0_70 = detectHemorrhageWithThreshold(fold_path, 0.7)\ntemiz_th_0_60 = detectHemorrhageWithThreshold(fold_path, 0.6)\ntemiz_th_0_50 = detectHemorrhageWithThreshold(fold_path, 0.5)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:58:51.797282Z","iopub.execute_input":"2023-05-22T11:58:51.797732Z","iopub.status.idle":"2023-05-22T11:59:01.387352Z","shell.execute_reply.started":"2023-05-22T11:58:51.79753Z","shell.execute_reply":"2023-05-22T11:59:01.386488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temiz_th_0_70.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:01.388853Z","iopub.execute_input":"2023-05-22T11:59:01.389177Z","iopub.status.idle":"2023-05-22T11:59:01.407731Z","shell.execute_reply.started":"2023-05-22T11:59:01.389122Z","shell.execute_reply":"2023-05-22T11:59:01.406872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fold_path  = \"/kaggle/input/ventrikler-dcm\"\nventrikler_th_0_70 = detectHemorrhageWithThreshold(fold_path, 0.7)\nventrikler_th_0_60 = detectHemorrhageWithThreshold(fold_path, 0.6)\nventrikler_th_0_50 = detectHemorrhageWithThreshold(fold_path, 0.5)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:01.40908Z","iopub.execute_input":"2023-05-22T11:59:01.409554Z","iopub.status.idle":"2023-05-22T11:59:05.279207Z","shell.execute_reply.started":"2023-05-22T11:59:01.40934Z","shell.execute_reply":"2023-05-22T11:59:05.278308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ventrikler_th_0_70.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:05.280579Z","iopub.execute_input":"2023-05-22T11:59:05.280877Z","iopub.status.idle":"2023-05-22T11:59:05.298122Z","shell.execute_reply.started":"2023-05-22T11:59:05.280831Z","shell.execute_reply":"2023-05-22T11:59:05.297339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# confusion matrix\n# Convert predictions classes to one hot vectors \ndef conf_matrix(df, index, realValue):\n    Y_pred_classes = df.iloc[:,index].values\n    # Convert validation observations to one hot vectors\n    Y_true = np.full(len(df), realValue)\n    # compute the confusion matrix\n    confusion_mtx = confusion_matrix(Y_true, Y_pred_classes) \n    return confusion_mtx\ndef plot_confusion_matrix(fold_path : str, index: int , title : str, realValue):\n    # Index ve realValue değerleri gerçek değerler ile tahmin edilen değerleri karşılaştırmak için kullanılmıştır.\n    # Test yapılan veri setlerinde hastalar hastalık türlerine göre ayrıldıkları için o hastalığın bulunduğu sütunu işaret etmektedir.\n    # RealValue 1 ise hastalık vardır. 0 ise hasta değildir. Bu değerler ile ile fonksiyona parametre olarak girilmektedir.\n    # 80\n    th_0_80 = detectHemorrhageWithThreshold(fold_path, 0.8)\n    conf_0_8 = conf_matrix(th_0_80, index, realValue)\n    # 70\n    th_0_70 = detectHemorrhageWithThreshold(fold_path, 0.7)\n    conf_0_7 = conf_matrix(th_0_70, index, realValue)\n    # 60\n    th_0_60 = detectHemorrhageWithThreshold(fold_path, 0.6)\n    conf_0_6 = conf_matrix(th_0_60, index, realValue)\n    # 50\n    th_0_50 = detectHemorrhageWithThreshold(fold_path, 0.5)\n    conf_0_5 = conf_matrix(th_0_50, index, realValue)\n\n\n    # plot the confusion matrix\n    f,axes = plt.subplots(2,2, figsize=(12,12))\n    f.suptitle(title)\n    sns.heatmap(conf_0_8, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[0,0])\n    axes[0,0].set_title(\"80 Threshold\")\n    axes[0,0].set_xlabel(\"Predicted Label\")\n    axes[0,0].set_ylabel(\"True Label\")\n    \n    sns.heatmap(conf_0_7, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[0,1])\n    axes[0,1].set_title(\"70 Threshold\")\n    axes[0,1].set_xlabel(\"Predicted Label\")\n    axes[0,1].set_ylabel(\"True Label\")\n    \n    sns.heatmap(conf_0_6, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[1,0])\n    axes[1,0].set_title(\"60 Threshold\")\n    axes[1,0].set_xlabel(\"Predicted Label\")\n    axes[1,0].set_ylabel(\"True Label\")\n \n    sns.heatmap(conf_0_5, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[1,1])\n    axes[1,1].set_title(\"50 Threshold\")\n    axes[1,1].set_xlabel(\"Predicted Label\")\n    axes[1,1].set_ylabel(\"True Label\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:05.299548Z","iopub.execute_input":"2023-05-22T11:59:05.300084Z","iopub.status.idle":"2023-05-22T11:59:05.32027Z","shell.execute_reply.started":"2023-05-22T11:59:05.300032Z","shell.execute_reply":"2023-05-22T11:59:05.319251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_confusion_matrix(\"/kaggle/input/intraparamkimal\", 3, \"Intraparamkimal\", 1)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:05.322087Z","iopub.execute_input":"2023-05-22T11:59:05.322656Z","iopub.status.idle":"2023-05-22T11:59:14.336804Z","shell.execute_reply.started":"2023-05-22T11:59:05.322463Z","shell.execute_reply":"2023-05-22T11:59:14.33603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_confusion_matrix(\"/kaggle/input/temiz-dcm\", 1, \"Temiz Hastalar\", 0)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:14.338651Z","iopub.execute_input":"2023-05-22T11:59:14.339264Z","iopub.status.idle":"2023-05-22T11:59:27.195355Z","shell.execute_reply.started":"2023-05-22T11:59:14.339205Z","shell.execute_reply":"2023-05-22T11:59:27.194559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_confusion_matrix(\"/kaggle/input/ventrikler-dcm\", 4, \"Ventrikler\", 1)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:27.196806Z","iopub.execute_input":"2023-05-22T11:59:27.197195Z","iopub.status.idle":"2023-05-22T11:59:33.386355Z","shell.execute_reply.started":"2023-05-22T11:59:27.197137Z","shell.execute_reply":"2023-05-22T11:59:33.385453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Aynı threshold değeri ile aynı veri üzerinde farklı hastalık türlerini inceleme\n## Bu aşamadan sonra threshold değeri 0.5 olarak ele alınmıştır","metadata":{}},{"cell_type":"code","source":"# confusion matrix\n# Convert predictions classes to one hot vectors \ndef conf_matrix(df, index, realValueIndex):\n    if(realValueIndex == index):\n        realValue = 1\n    elif(index == 1 and (realValueIndex == 2 or realValueIndex == 3 or realValueIndex == 4 or realValueIndex == 5 or realValueIndex == 6)):\n        realValue = 1\n    else:\n        realValue = 0\n        \n    Y_pred_classes = df.iloc[:,index].values\n    # Convert validation observations to one hot vectors\n    Y_true = np.full(len(df), realValue)\n    # compute the confusion matrix\n    confusion_mtx = confusion_matrix(Y_true, Y_pred_classes) \n    return confusion_mtx\ndef plot_confusion_matrix(fold_path : str, title : str, realValueIndex):\n    dataFrame = detectHemorrhageWithThreshold(fold_path, 0.5)\n    \n    # Any\n    conf_any = conf_matrix(dataFrame, 1, realValueIndex)\n    # Epidural\n    conf_epidural = conf_matrix(dataFrame, 2, realValueIndex)\n    # Intraparenchymal\n    conf_intraparenchymal = conf_matrix(dataFrame, 3, realValueIndex)\n    # Intraventricular\n    conf_intraventricular = conf_matrix(dataFrame, 4, realValueIndex)\n    # Subarachnoid\n    conf_subarachnoid = conf_matrix(dataFrame, 5, realValueIndex)\n    # Subdural\n    conf_subdural = conf_matrix(dataFrame, 6, realValueIndex)\n\n\n    # plot the confusion matrix\n    f,axes = plt.subplots(3,2, figsize=(14,21))\n    f.suptitle(title)\n    sns.heatmap(conf_any, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[0,0])\n    axes[0,0].set_title(\"Any\")\n    axes[0,0].set_xlabel(\"Predicted Label\")\n    axes[0,0].set_ylabel(\"True Label\")\n    \n    sns.heatmap(conf_epidural, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[0,1])\n    axes[0,1].set_title(\"Epidural\")\n    axes[0,1].set_xlabel(\"Predicted Label\")\n    axes[0,1].set_ylabel(\"True Label\")\n    \n    sns.heatmap(conf_intraparenchymal, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[1,0])\n    axes[1,0].set_title(\"Intraparenchymal\")\n    axes[1,0].set_xlabel(\"Predicted Label\")\n    axes[1,0].set_ylabel(\"True Label\")\n \n    sns.heatmap(conf_intraventricular, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[1,1])\n    axes[1,1].set_title(\"Intraventricular\")\n    axes[1,1].set_xlabel(\"Predicted Label\")\n    axes[1,1].set_ylabel(\"True Label\")\n        \n    sns.heatmap(conf_subarachnoid, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[2,0])\n    axes[2,0].set_title(\"Subarachnoid\")\n    axes[2,0].set_xlabel(\"Predicted Label\")\n    axes[2,0].set_ylabel(\"True Label\")\n        \n    sns.heatmap(conf_subdural, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=axes[2,1])\n    axes[2,1].set_title(\"Subdural\")\n    axes[2,1].set_xlabel(\"Predicted Label\")\n    axes[2,1].set_ylabel(\"True Label\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:33.387897Z","iopub.execute_input":"2023-05-22T11:59:33.388519Z","iopub.status.idle":"2023-05-22T11:59:33.415289Z","shell.execute_reply.started":"2023-05-22T11:59:33.388464Z","shell.execute_reply":"2023-05-22T11:59:33.414232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_confusion_matrix(\"/kaggle/input/intraparamkimal\", \"Intraparamkimal\", 3)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:33.419256Z","iopub.execute_input":"2023-05-22T11:59:33.419553Z","iopub.status.idle":"2023-05-22T11:59:36.833841Z","shell.execute_reply.started":"2023-05-22T11:59:33.4195Z","shell.execute_reply":"2023-05-22T11:59:36.832939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_confusion_matrix(\"/kaggle/input/temiz-dcm\", \"Temiz Hastalar\", -1)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:36.83555Z","iopub.execute_input":"2023-05-22T11:59:36.836239Z","iopub.status.idle":"2023-05-22T11:59:41.25595Z","shell.execute_reply.started":"2023-05-22T11:59:36.836166Z","shell.execute_reply":"2023-05-22T11:59:41.25502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_confusion_matrix(\"/kaggle/input/ventrikler-dcm\", \"Ventrikler\", 4)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:41.257435Z","iopub.execute_input":"2023-05-22T11:59:41.25799Z","iopub.status.idle":"2023-05-22T11:59:43.817676Z","shell.execute_reply.started":"2023-05-22T11:59:41.257933Z","shell.execute_reply":"2023-05-22T11:59:43.816845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ventrikler_th_0_50","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:43.819255Z","iopub.execute_input":"2023-05-22T11:59:43.819818Z","iopub.status.idle":"2023-05-22T11:59:43.849844Z","shell.execute_reply.started":"2023-05-22T11:59:43.819767Z","shell.execute_reply":"2023-05-22T11:59:43.848846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temiz_th_0_50.head(55)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:43.851241Z","iopub.execute_input":"2023-05-22T11:59:43.851714Z","iopub.status.idle":"2023-05-22T11:59:43.88728Z","shell.execute_reply.started":"2023-05-22T11:59:43.85149Z","shell.execute_reply":"2023-05-22T11:59:43.886405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"instraparamkimal_th_0_50.head(59)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:43.888782Z","iopub.execute_input":"2023-05-22T11:59:43.889234Z","iopub.status.idle":"2023-05-22T11:59:43.926632Z","shell.execute_reply.started":"2023-05-22T11:59:43.889053Z","shell.execute_reply":"2023-05-22T11:59:43.925911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def examineDcm(full_dcm_path, threshold, realValues):\n    # Prediction happening here\n    dicomName = full_dcm_path.split(\"/\")[-1]\n    columns=[\"dcm_name\", \"any\", \"epidural\", \"intraparenchymal\", \"intraventricular\", \"subarachnoid\", \"subdural\"]\n    test_df = pd.DataFrame(columns=columns)\n    prediction = model.model.predict(np.expand_dims(_read(full_dcm_path, (256,256,3)),0))[0] # Detection happening here\n    for x in range(len(prediction)):\n        if(prediction[x] >= threshold):\n            prediction[x] = 1\n        else:\n            prediction[x] = 0\n    prediction = list(prediction)\n    prediction.insert(0, dicomName)\n    test_df.loc[len(test_df)] = prediction\n    \n    print(f\"Dicom Name= {dicomName} || Patient Type= {full_dcm_path.split('/')[-2]}\")\n    for columnIndex in range(1,7):\n        print(\"             \", columns[columnIndex])\n        print(f\"Real Value= {realValues[columnIndex - 1]} ----- Predicted Value= {test_df.values[0][columnIndex]}\")\n    plt.imshow(\n    _read(full_dcm_path, (512, 512)), cmap=plt.cm.bone, aspect='auto'\n    );","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:43.928195Z","iopub.execute_input":"2023-05-22T11:59:43.928641Z","iopub.status.idle":"2023-05-22T11:59:43.940353Z","shell.execute_reply.started":"2023-05-22T11:59:43.928459Z","shell.execute_reply":"2023-05-22T11:59:43.939268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Intraparamkimal Hasta Grubundan 6 Adet Şüpheli Örnek İncelemesi","metadata":{}},{"cell_type":"code","source":"# Tahminlerde subdural çıkan dcm\nexamineDcm(\"/kaggle/input/intraparamkimal/ser002img00102.dcm\", 0.5, [1.0, 0.0, 1.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:43.942203Z","iopub.execute_input":"2023-05-22T11:59:43.942661Z","iopub.status.idle":"2023-05-22T11:59:44.27477Z","shell.execute_reply.started":"2023-05-22T11:59:43.942565Z","shell.execute_reply":"2023-05-22T11:59:44.273978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Hasta olarak gözüken ancak intrapamkimal teşhisi koyulamayan hasta\nexamineDcm(\"/kaggle/input/intraparamkimal/ser002img00121.dcm\", 0.5, [1.0, 0.0, 1.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:44.2763Z","iopub.execute_input":"2023-05-22T11:59:44.276835Z","iopub.status.idle":"2023-05-22T11:59:44.523409Z","shell.execute_reply.started":"2023-05-22T11:59:44.276782Z","shell.execute_reply":"2023-05-22T11:59:44.522432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/intraparamkimal/ser002img00124.dcm\", 0.5, [1.0, 0.0, 1.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:44.524849Z","iopub.execute_input":"2023-05-22T11:59:44.525172Z","iopub.status.idle":"2023-05-22T11:59:44.770227Z","shell.execute_reply.started":"2023-05-22T11:59:44.525124Z","shell.execute_reply":"2023-05-22T11:59:44.769273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# intraparenchymal ve intraventricular pozitif çıkan hasta 1\nexamineDcm(\"/kaggle/input/intraparamkimal/ser002img00156.dcm\", 0.5, [1.0, 0.0, 1.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:44.771713Z","iopub.execute_input":"2023-05-22T11:59:44.772048Z","iopub.status.idle":"2023-05-22T11:59:45.016308Z","shell.execute_reply.started":"2023-05-22T11:59:44.771989Z","shell.execute_reply":"2023-05-22T11:59:45.01538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# intraparenchymal ve intraventricular pozitif çıkan hasta 2\nexamineDcm(\"/kaggle/input/intraparamkimal/ser002img00089.dcm\", 0.5, [1.0, 0.0, 1.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:45.017849Z","iopub.execute_input":"2023-05-22T11:59:45.018163Z","iopub.status.idle":"2023-05-22T11:59:45.25674Z","shell.execute_reply.started":"2023-05-22T11:59:45.018113Z","shell.execute_reply":"2023-05-22T11:59:45.255682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# intraventricular pozitif intraparamkimal negatif çıkan hasta\nexamineDcm(\"/kaggle/input/intraparamkimal/ser002img00164.dcm\", 0.5, [1.0, 0.0, 1.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:45.258289Z","iopub.execute_input":"2023-05-22T11:59:45.258752Z","iopub.status.idle":"2023-05-22T11:59:45.499817Z","shell.execute_reply.started":"2023-05-22T11:59:45.25855Z","shell.execute_reply":"2023-05-22T11:59:45.499127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Temiz Hasta Grubundan 4 Adet Şüpheli Örnek İncelemesi","metadata":{}},{"cell_type":"code","source":"# Tahminlerde intraparenchymal kanama görülen temiz dicom\nexamineDcm(\"/kaggle/input/temiz-dcm/ser002img00068.dcm\", 0.5, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:45.501147Z","iopub.execute_input":"2023-05-22T11:59:45.501467Z","iopub.status.idle":"2023-05-22T11:59:45.747866Z","shell.execute_reply.started":"2023-05-22T11:59:45.501414Z","shell.execute_reply":"2023-05-22T11:59:45.746941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/temiz-dcm/ser002img00128.dcm\", 0.5, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:45.749524Z","iopub.execute_input":"2023-05-22T11:59:45.749866Z","iopub.status.idle":"2023-05-22T11:59:45.993525Z","shell.execute_reply.started":"2023-05-22T11:59:45.749815Z","shell.execute_reply":"2023-05-22T11:59:45.992422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/temiz-dcm/ser002img00183.dcm\", 0.5, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:45.995159Z","iopub.execute_input":"2023-05-22T11:59:45.995698Z","iopub.status.idle":"2023-05-22T11:59:46.234875Z","shell.execute_reply.started":"2023-05-22T11:59:45.995467Z","shell.execute_reply":"2023-05-22T11:59:46.234049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/temiz-dcm/ser002img00178.dcm\", 0.5, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:46.236301Z","iopub.execute_input":"2023-05-22T11:59:46.236787Z","iopub.status.idle":"2023-05-22T11:59:46.478887Z","shell.execute_reply.started":"2023-05-22T11:59:46.236733Z","shell.execute_reply":"2023-05-22T11:59:46.47811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Ventrikler Hasta Grubundan 7 Adet Şüpheli Örnek İncelemesi","metadata":{}},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/ventrikler-dcm/ser002img00094.dcm\", 0.5, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:46.480502Z","iopub.execute_input":"2023-05-22T11:59:46.481152Z","iopub.status.idle":"2023-05-22T11:59:46.724543Z","shell.execute_reply.started":"2023-05-22T11:59:46.48083Z","shell.execute_reply":"2023-05-22T11:59:46.72372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/ventrikler-dcm/ser002img00095.dcm\", 0.5, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:46.72601Z","iopub.execute_input":"2023-05-22T11:59:46.726446Z","iopub.status.idle":"2023-05-22T11:59:46.968942Z","shell.execute_reply.started":"2023-05-22T11:59:46.726387Z","shell.execute_reply":"2023-05-22T11:59:46.968035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/ventrikler-dcm/ser002img00093.dcm\", 0.5, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:46.97038Z","iopub.execute_input":"2023-05-22T11:59:46.970678Z","iopub.status.idle":"2023-05-22T11:59:47.221927Z","shell.execute_reply.started":"2023-05-22T11:59:46.970629Z","shell.execute_reply":"2023-05-22T11:59:47.22098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/ventrikler-dcm/ser002img00113.dcm\", 0.5, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:47.223474Z","iopub.execute_input":"2023-05-22T11:59:47.223772Z","iopub.status.idle":"2023-05-22T11:59:47.466466Z","shell.execute_reply.started":"2023-05-22T11:59:47.223723Z","shell.execute_reply":"2023-05-22T11:59:47.46559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/ventrikler-dcm/ser002img00114.dcm\", 0.5, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:47.46798Z","iopub.execute_input":"2023-05-22T11:59:47.468483Z","iopub.status.idle":"2023-05-22T11:59:47.72349Z","shell.execute_reply.started":"2023-05-22T11:59:47.468426Z","shell.execute_reply":"2023-05-22T11:59:47.722679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/ventrikler-dcm/ser002img00110.dcm\", 0.5, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:47.724823Z","iopub.execute_input":"2023-05-22T11:59:47.725161Z","iopub.status.idle":"2023-05-22T11:59:47.969908Z","shell.execute_reply.started":"2023-05-22T11:59:47.725095Z","shell.execute_reply":"2023-05-22T11:59:47.968991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"examineDcm(\"/kaggle/input/ventrikler-dcm/ser002img00165.dcm\", 0.5, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:47.971517Z","iopub.execute_input":"2023-05-22T11:59:47.971842Z","iopub.status.idle":"2023-05-22T11:59:48.216283Z","shell.execute_reply.started":"2023-05-22T11:59:47.97179Z","shell.execute_reply":"2023-05-22T11:59:48.215413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# NNRD Dosyalarının okunması ve incelenmesi","metadata":{}},{"cell_type":"code","source":"readData, header = nrrd.read(\"/kaggle/input/nrrd-j30s/nrrd/j30s.nrrd\")\n# nnrd.read() metotu 2 adet bilgiyi geri döndürmektedir.","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:10:15.228122Z","iopub.execute_input":"2023-05-22T12:10:15.228464Z","iopub.status.idle":"2023-05-22T12:10:16.262893Z","shell.execute_reply.started":"2023-05-22T12:10:15.22841Z","shell.execute_reply":"2023-05-22T12:10:16.261946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(header)\n# header parametresi dosya hakkında bilgiler içermektedir. Eğer etiketleme işlemi yapıldıysa etiketleme bilgileri de header içerisindendir.","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:50.825625Z","iopub.execute_input":"2023-05-22T11:59:50.82594Z","iopub.status.idle":"2023-05-22T11:59:50.832112Z","shell.execute_reply.started":"2023-05-22T11:59:50.825875Z","shell.execute_reply":"2023-05-22T11:59:50.831284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(readData)\n# 2. parametre ise görüntülerin bulunduğu matrislerdir.","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:50.833342Z","iopub.execute_input":"2023-05-22T11:59:50.833825Z","iopub.status.idle":"2023-05-22T11:59:50.843283Z","shell.execute_reply.started":"2023-05-22T11:59:50.833766Z","shell.execute_reply":"2023-05-22T11:59:50.842489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Nnrd data ilk okunduğunda açısal bir sorun olduğu için rotate işlemi uygulandı\n","metadata":{}},{"cell_type":"code","source":"# 101. Slice (nrrd data)\n\nplt.imshow(readData[:,:,100], cmap=plt.cm.bone)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:50.84476Z","iopub.execute_input":"2023-05-22T11:59:50.845346Z","iopub.status.idle":"2023-05-22T11:59:51.00904Z","shell.execute_reply.started":"2023-05-22T11:59:50.845175Z","shell.execute_reply":"2023-05-22T11:59:51.008173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 101. Slice (nrrd data)\nplt.imshow(np.rot90(readData[:,:,100], -1), cmap=plt.cm.bone)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.010789Z","iopub.execute_input":"2023-05-22T11:59:51.011417Z","iopub.status.idle":"2023-05-22T11:59:51.172729Z","shell.execute_reply.started":"2023-05-22T11:59:51.011088Z","shell.execute_reply":"2023-05-22T11:59:51.171895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 101. Slice (nrrd data)\nplt.imshow(np.fliplr(np.rot90(readData[:,:,100], -1)), cmap=plt.cm.bone)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.174112Z","iopub.execute_input":"2023-05-22T11:59:51.174695Z","iopub.status.idle":"2023-05-22T11:59:51.334593Z","shell.execute_reply.started":"2023-05-22T11:59:51.17463Z","shell.execute_reply":"2023-05-22T11:59:51.333695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.rot90(readData[:,:,55], -1).shape","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.336015Z","iopub.execute_input":"2023-05-22T11:59:51.336482Z","iopub.status.idle":"2023-05-22T11:59:51.344217Z","shell.execute_reply.started":"2023-05-22T11:59:51.33643Z","shell.execute_reply":"2023-05-22T11:59:51.343271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(pydicom.dcmread(\"/kaggle/input/nrrd-to-dicom/nrrd_to_dcm/ser002img00101.dcm\").pixel_array)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.346129Z","iopub.execute_input":"2023-05-22T11:59:51.346728Z","iopub.status.idle":"2023-05-22T11:59:51.553745Z","shell.execute_reply.started":"2023-05-22T11:59:51.346437Z","shell.execute_reply":"2023-05-22T11:59:51.552859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(\n    _read('/kaggle/input/nrrd-to-dicom/nrrd_to_dcm/ser002img00101.dcm', (512, 512)), cmap=plt.cm.bone\n)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.555292Z","iopub.execute_input":"2023-05-22T11:59:51.555809Z","iopub.status.idle":"2023-05-22T11:59:51.745686Z","shell.execute_reply.started":"2023-05-22T11:59:51.555758Z","shell.execute_reply":"2023-05-22T11:59:51.744843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dicom_template = pydicom.dcmread('/kaggle/input/nrrd-to-dicom/nrrd_to_dcm/ser002img00056.dcm')","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.747048Z","iopub.execute_input":"2023-05-22T11:59:51.747515Z","iopub.status.idle":"2023-05-22T11:59:51.793269Z","shell.execute_reply.started":"2023-05-22T11:59:51.747457Z","shell.execute_reply":"2023-05-22T11:59:51.792629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Dosya tipi değiştiği için ilk başlarda yapılan önişleme aşamaları tekrar gözden geçirildi.\n### Nrrd dosya kaynağına uygun hale getirildi\n### Nrrd dosyaları dicom dosyaları gibi bir sayısal dönüşüme ihtiyaç duymamaktadır. \n### Dicom için gerçek değerlere dönüşüm formulü = (img = dcm.pixel_array * dcm.RescaleSlope + dcm.RescaleIntercept)\n### Nrrd bu işleme ihtiyaç duymamaktadır. Direkt olarak gerçek değerleri vermektedir.","metadata":{}},{"cell_type":"code","source":"def nrrd_read(nrrd_array, desired_size): \n    nrrd_array = np.fliplr(np.rot90(nrrd_array, -1))\n    try:\n        img = nrrd_bsb_window(nrrd_array)\n    except:\n        img = np.zeros(desired_size)\n    \n    \n    img = cv2.resize(img, desired_size[:2], interpolation=cv2.INTER_LINEAR)\n    \n    return img\n\ndef nrrd_bsb_window(nrrd_array):\n    brain_img = nrrd_window_image(nrrd_array, 40, 80)\n    subdural_img = nrrd_window_image(nrrd_array, 80, 200)\n    soft_img = nrrd_window_image(nrrd_array, 40, 380)\n    \n    brain_img = (brain_img - 0) / 80\n    subdural_img = (subdural_img - (-20)) / 200\n    soft_img = (soft_img - (-150)) / 380\n    bsb_img = np.array([brain_img, subdural_img, soft_img]).transpose(1,2,0)\n\n    return bsb_img\n\ndef nrrd_window_image(nrrd_array, window_center, window_width):\n    img = nrrd_array\n    img_min = window_center - window_width // 2\n    img_max = window_center + window_width // 2\n    img = np.clip(img, img_min, img_max)\n\n    return img","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.795031Z","iopub.execute_input":"2023-05-22T11:59:51.795528Z","iopub.status.idle":"2023-05-22T11:59:51.806588Z","shell.execute_reply.started":"2023-05-22T11:59:51.795305Z","shell.execute_reply":"2023-05-22T11:59:51.805779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 101. Slice Nrrd file vs Dcm Fİle","metadata":{}},{"cell_type":"code","source":"plt.imshow(\n    nrrd_read(readData[:,:,100], (512, 512)), cmap=plt.cm.bone\n);","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.807847Z","iopub.execute_input":"2023-05-22T11:59:51.808354Z","iopub.status.idle":"2023-05-22T11:59:51.992568Z","shell.execute_reply.started":"2023-05-22T11:59:51.808304Z","shell.execute_reply":"2023-05-22T11:59:51.991641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(\n    _read(\"/kaggle/input/nrrd-to-dicom/nrrd_to_dcm/ser002img00101.dcm\", (512,512)), cmap=plt.cm.bone\n)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:51.994086Z","iopub.execute_input":"2023-05-22T11:59:51.994653Z","iopub.status.idle":"2023-05-22T11:59:52.195585Z","shell.execute_reply.started":"2023-05-22T11:59:51.994376Z","shell.execute_reply":"2023-05-22T11:59:52.194701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def detect_hemorrhage_from_nrrd(nrrd_path):\n    # Sonuçların kayıt edileceği dataframe'in oluşturulması\n    test_df = pd.DataFrame(columns=[\"dcm_name\", \"any\", \"epidural\", \"intraparenchymal\", \"intraventricular\", \"subarachnoid\", \"subdural\"])\n    readData, header = nrrd.read(nrrd_path) # nrrd dosyasının kaynaktan okunması\n    for idx in range(readData.shape[2]): # Nrrd içerisindeki her bir slice'ın döngü ile elde edilmesi\n        prediction = model.model.predict(np.expand_dims(nrrd_read(readData[:,:,idx], (256, 256)),0))[0] # Detection happening here\n        prediction = list(prediction) # Sonucun liste haline getirilmesi\n        prediction.insert(0, f\"ser002img00{idx+1}.dcm\") # Listenin başına slice'ın id'sinin getirilmesi\n        test_df.loc[len(test_df)] = prediction # Sonuçların dataframe içerisindeki son satıra kayıt edilmesi\n    return test_df","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:52.197033Z","iopub.execute_input":"2023-05-22T11:59:52.19756Z","iopub.status.idle":"2023-05-22T11:59:52.206888Z","shell.execute_reply.started":"2023-05-22T11:59:52.197478Z","shell.execute_reply":"2023-05-22T11:59:52.205808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def detect_hemorrhage_from_nrrd_with_threashold(nrrd_path, threshold):\n    # Üstteki fonkisyondan tek farkı sonuçların bir threshold değeri ile filtrelenmesi\n    test_df = pd.DataFrame(columns=[\"dcm_name\", \"any\", \"epidural\", \"intraparenchymal\", \"intraventricular\", \"subarachnoid\", \"subdural\"])\n    readData, header = nrrd.read(nrrd_path)\n    for idx in range(readData.shape[2]):\n        prediction = model.model.predict(np.expand_dims(nrrd_read(readData[:,:,idx], (256, 256)),0))[0] # Detection happening here\n        for column in range(len(prediction)): \n            # Elde edilen prediction sonucunda her bir değer threshold değeri ile kıyaslanmakta ve 0 ile 1 olarak değiştirilmektedir.\n            if(prediction[column] >= threshold):\n                prediction[column] = 1\n            else:\n                prediction[column] = 0\n        prediction = list(prediction)\n        prediction.insert(0, f\"ser002img00{idx+1}.dcm\")\n        test_df.loc[len(test_df)] = prediction\n    return test_df","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:52.208522Z","iopub.execute_input":"2023-05-22T11:59:52.209128Z","iopub.status.idle":"2023-05-22T11:59:52.219442Z","shell.execute_reply.started":"2023-05-22T11:59:52.208829Z","shell.execute_reply":"2023-05-22T11:59:52.218387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dcm_detection_hemorrhage = detectHemorrhage(\"/kaggle/input/nrrd-to-dicom/nrrd_to_dcm\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T11:59:52.221439Z","iopub.execute_input":"2023-05-22T11:59:52.221932Z","iopub.status.idle":"2023-05-22T12:00:03.770784Z","shell.execute_reply.started":"2023-05-22T11:59:52.221847Z","shell.execute_reply":"2023-05-22T12:00:03.769841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dcm_detection_hemorrhage.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:03.772183Z","iopub.execute_input":"2023-05-22T12:00:03.772483Z","iopub.status.idle":"2023-05-22T12:00:03.779448Z","shell.execute_reply.started":"2023-05-22T12:00:03.772435Z","shell.execute_reply":"2023-05-22T12:00:03.778643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nrrd_detection_hemorrhage = detect_hemorrhage_from_nrrd(\"/kaggle/input/nrrd-j30s/nrrd/j30s.nrrd\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:03.781007Z","iopub.execute_input":"2023-05-22T12:00:03.78158Z","iopub.status.idle":"2023-05-22T12:00:12.055766Z","shell.execute_reply.started":"2023-05-22T12:00:03.781519Z","shell.execute_reply":"2023-05-22T12:00:12.054741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nrrd_detection_hemorrhage.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:12.057134Z","iopub.execute_input":"2023-05-22T12:00:12.057429Z","iopub.status.idle":"2023-05-22T12:00:12.072209Z","shell.execute_reply.started":"2023-05-22T12:00:12.057383Z","shell.execute_reply":"2023-05-22T12:00:12.071422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nrrd_detection_hemorrhage","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:12.073487Z","iopub.execute_input":"2023-05-22T12:00:12.073962Z","iopub.status.idle":"2023-05-22T12:00:12.097629Z","shell.execute_reply.started":"2023-05-22T12:00:12.073896Z","shell.execute_reply":"2023-05-22T12:00:12.096613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dcm_detection_hemorrhage.sort_values(by=[\"dcm_name\"])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:12.099035Z","iopub.execute_input":"2023-05-22T12:00:12.09948Z","iopub.status.idle":"2023-05-22T12:00:12.118523Z","shell.execute_reply.started":"2023-05-22T12:00:12.099291Z","shell.execute_reply":"2023-05-22T12:00:12.117678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Segment Nrrd File\n# Segment dosyası header içerisinde etiketleme bilgileri yer almaktadır.\n# Segment içerisindeki slice'lar sadece mevcut etiketleri barındırmakta hastaya ait beyin görüntüleri bulunmamaktadır.","metadata":{}},{"cell_type":"code","source":"readData, header = nrrd.read(\"/kaggle/input/nrrd-j30s/nrrd/Segmentation.seg.nrrd\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:12.12039Z","iopub.execute_input":"2023-05-22T12:00:12.120778Z","iopub.status.idle":"2023-05-22T12:00:12.419367Z","shell.execute_reply.started":"2023-05-22T12:00:12.120714Z","shell.execute_reply":"2023-05-22T12:00:12.418446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"readData.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:12.420755Z","iopub.execute_input":"2023-05-22T12:00:12.421089Z","iopub.status.idle":"2023-05-22T12:00:12.426475Z","shell.execute_reply.started":"2023-05-22T12:00:12.421039Z","shell.execute_reply":"2023-05-22T12:00:12.425585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"header","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:12.428075Z","iopub.execute_input":"2023-05-22T12:00:12.428634Z","iopub.status.idle":"2023-05-22T12:00:12.44368Z","shell.execute_reply.started":"2023-05-22T12:00:12.42858Z","shell.execute_reply":"2023-05-22T12:00:12.442637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_segment_nrrd(segment_nrrd_path):\n    test_df = pd.DataFrame(columns=[\"dcm_name\", \"intraventricular\", \"intraparenchymal\", \"other\", ])\n    readData, header = nrrd.read(segment_nrrd_path)\n    for idx in range(readData.shape[2]):\n        segment_nrrd = readData[:,:,idx]      \n        temp_array=[0,0,0]\n        if(np.isin(segment_nrrd, 1).sum() > 0):\n            temp_array[0] = 1\n        if(np.isin(segment_nrrd, 2).sum() > 0):\n            temp_array[2] = 1\n        if(np.isin(segment_nrrd, 3).sum() > 0):\n            temp_array[1] = 1\n        temp_list = list(temp_array)\n        temp_list.insert(0, f\"ser002img00{idx+1}.dcm\")\n        test_df.loc[len(test_df)] = temp_list\n    return test_df","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:12.444898Z","iopub.execute_input":"2023-05-22T12:00:12.445407Z","iopub.status.idle":"2023-05-22T12:00:12.456644Z","shell.execute_reply.started":"2023-05-22T12:00:12.445173Z","shell.execute_reply":"2023-05-22T12:00:12.455018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_nrrd_df = read_segment_nrrd(\"/kaggle/input/nrrd-j30s/nrrd/Segmentation.seg.nrrd\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:12.458075Z","iopub.execute_input":"2023-05-22T12:00:12.458648Z","iopub.status.idle":"2023-05-22T12:00:13.935254Z","shell.execute_reply.started":"2023-05-22T12:00:12.458538Z","shell.execute_reply":"2023-05-22T12:00:13.934403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_nrrd_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:13.936592Z","iopub.execute_input":"2023-05-22T12:00:13.936885Z","iopub.status.idle":"2023-05-22T12:00:13.943266Z","shell.execute_reply.started":"2023-05-22T12:00:13.936841Z","shell.execute_reply":"2023-05-22T12:00:13.942445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_nrrd_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:13.944658Z","iopub.execute_input":"2023-05-22T12:00:13.945126Z","iopub.status.idle":"2023-05-22T12:00:13.964158Z","shell.execute_reply.started":"2023-05-22T12:00:13.945075Z","shell.execute_reply":"2023-05-22T12:00:13.963406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_nrrd_df[segment_nrrd_df[\"other\"] == 1]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:13.965395Z","iopub.execute_input":"2023-05-22T12:00:13.966511Z","iopub.status.idle":"2023-05-22T12:00:13.984577Z","shell.execute_reply.started":"2023-05-22T12:00:13.966461Z","shell.execute_reply":"2023-05-22T12:00:13.984004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_hemorrhage_from_nrrd_with_threashold = detect_hemorrhage_from_nrrd_with_threashold(\"/kaggle/input/nrrd-j30s/nrrd/j30s.nrrd\", 0.5)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:13.986724Z","iopub.execute_input":"2023-05-22T12:00:13.987233Z","iopub.status.idle":"2023-05-22T12:00:22.253488Z","shell.execute_reply.started":"2023-05-22T12:00:13.987183Z","shell.execute_reply":"2023-05-22T12:00:22.252641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_hemorrhage_from_nrrd_with_threashold.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.257051Z","iopub.execute_input":"2023-05-22T12:00:22.257315Z","iopub.status.idle":"2023-05-22T12:00:22.273038Z","shell.execute_reply.started":"2023-05-22T12:00:22.257268Z","shell.execute_reply":"2023-05-22T12:00:22.272019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def print_conf_matrix(label_name:str, real_values, predicted_values):\n    conf_matrix = confusion_matrix(real_values, predicted_values) \n    # plot the confusion matrix\n    f,ax = plt.subplots(figsize=(10, 10))\n    sns.heatmap(conf_matrix, annot=True, linewidths=0.01,cmap=\"Greens\",linecolor=\"gray\", fmt= '.1f',ax=ax)\n    plt.xlabel(\"Predicted Label\")\n    plt.ylabel(\"True Label\")\n    plt.title(f\"{label_name} Confusion Matrix\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.274546Z","iopub.execute_input":"2023-05-22T12:00:22.275122Z","iopub.status.idle":"2023-05-22T12:00:22.283833Z","shell.execute_reply.started":"2023-05-22T12:00:22.275068Z","shell.execute_reply":"2023-05-22T12:00:22.28293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# NRRD Hemorrhage Any Confusion Matrix","metadata":{}},{"cell_type":"code","source":"values = segment_nrrd_df.iloc[:,1:4].values","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.285467Z","iopub.execute_input":"2023-05-22T12:00:22.285992Z","iopub.status.idle":"2023-05-22T12:00:22.29335Z","shell.execute_reply.started":"2023-05-22T12:00:22.285737Z","shell.execute_reply":"2023-05-22T12:00:22.29253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any_values = [1 if (np.isin(values[idx], 1).sum() > 0) else 0 for idx in range(len(values))]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.295797Z","iopub.execute_input":"2023-05-22T12:00:22.296418Z","iopub.status.idle":"2023-05-22T12:00:22.308496Z","shell.execute_reply.started":"2023-05-22T12:00:22.296362Z","shell.execute_reply":"2023-05-22T12:00:22.307725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(any_values)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.310097Z","iopub.execute_input":"2023-05-22T12:00:22.31065Z","iopub.status.idle":"2023-05-22T12:00:22.320229Z","shell.execute_reply.started":"2023-05-22T12:00:22.310444Z","shell.execute_reply":"2023-05-22T12:00:22.319288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any_values[55:69]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.321793Z","iopub.execute_input":"2023-05-22T12:00:22.322415Z","iopub.status.idle":"2023-05-22T12:00:22.328781Z","shell.execute_reply.started":"2023-05-22T12:00:22.322224Z","shell.execute_reply":"2023-05-22T12:00:22.327942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_nrrd_df[\"any\"] = any_values","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.330173Z","iopub.execute_input":"2023-05-22T12:00:22.330691Z","iopub.status.idle":"2023-05-22T12:00:22.338665Z","shell.execute_reply.started":"2023-05-22T12:00:22.330606Z","shell.execute_reply":"2023-05-22T12:00:22.33783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_nrrd_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.340191Z","iopub.execute_input":"2023-05-22T12:00:22.340658Z","iopub.status.idle":"2023-05-22T12:00:22.356577Z","shell.execute_reply.started":"2023-05-22T12:00:22.340474Z","shell.execute_reply":"2023-05-22T12:00:22.354953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_nrrd_df[segment_nrrd_df[\"any\"] == 1].shape","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.357586Z","iopub.execute_input":"2023-05-22T12:00:22.357824Z","iopub.status.idle":"2023-05-22T12:00:22.366607Z","shell.execute_reply.started":"2023-05-22T12:00:22.357777Z","shell.execute_reply":"2023-05-22T12:00:22.3657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any_real_values = segment_nrrd_df[\"any\"].values\nany_predicted_values = detect_hemorrhage_from_nrrd_with_threashold[\"any\"].values","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.36814Z","iopub.execute_input":"2023-05-22T12:00:22.368665Z","iopub.status.idle":"2023-05-22T12:00:22.374201Z","shell.execute_reply.started":"2023-05-22T12:00:22.36861Z","shell.execute_reply":"2023-05-22T12:00:22.373333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any_real_values","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.375696Z","iopub.execute_input":"2023-05-22T12:00:22.376283Z","iopub.status.idle":"2023-05-22T12:00:22.386121Z","shell.execute_reply.started":"2023-05-22T12:00:22.376233Z","shell.execute_reply":"2023-05-22T12:00:22.385032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print_conf_matrix(\"Any\", any_real_values, any_predicted_values)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.387771Z","iopub.execute_input":"2023-05-22T12:00:22.388324Z","iopub.status.idle":"2023-05-22T12:00:22.58128Z","shell.execute_reply.started":"2023-05-22T12:00:22.388128Z","shell.execute_reply":"2023-05-22T12:00:22.580387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## intraventricular Confusion Matrix","metadata":{}},{"cell_type":"code","source":"intraventricular_real_values = segment_nrrd_df[\"intraventricular\"].values.astype(\"int32\")\nintraventricular_predicted_values = detect_hemorrhage_from_nrrd_with_threashold[\"intraventricular\"].values","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.582819Z","iopub.execute_input":"2023-05-22T12:00:22.583401Z","iopub.status.idle":"2023-05-22T12:00:22.589045Z","shell.execute_reply.started":"2023-05-22T12:00:22.583341Z","shell.execute_reply":"2023-05-22T12:00:22.588218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print_conf_matrix(\"Intraventricular\", real_values=intraventricular_real_values, predicted_values=intraventricular_predicted_values)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.590543Z","iopub.execute_input":"2023-05-22T12:00:22.591186Z","iopub.status.idle":"2023-05-22T12:00:22.791473Z","shell.execute_reply.started":"2023-05-22T12:00:22.591125Z","shell.execute_reply":"2023-05-22T12:00:22.790371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## intraparenchymal Confusion Matrix","metadata":{}},{"cell_type":"code","source":"intraparenchymal_real_values = segment_nrrd_df[\"intraparenchymal\"].values.astype(\"int32\")\nintraparenchymal_predicted_values = detect_hemorrhage_from_nrrd_with_threashold[\"intraparenchymal\"].values","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.793125Z","iopub.execute_input":"2023-05-22T12:00:22.793639Z","iopub.status.idle":"2023-05-22T12:00:22.799657Z","shell.execute_reply.started":"2023-05-22T12:00:22.793418Z","shell.execute_reply":"2023-05-22T12:00:22.798504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print_conf_matrix(\"Intraparenchymal\", real_values=intraparenchymal_real_values, predicted_values=intraparenchymal_predicted_values)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:22.801135Z","iopub.execute_input":"2023-05-22T12:00:22.801608Z","iopub.status.idle":"2023-05-22T12:00:23.010001Z","shell.execute_reply.started":"2023-05-22T12:00:22.801392Z","shell.execute_reply":"2023-05-22T12:00:23.008948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Other Confusion Matrix","metadata":{}},{"cell_type":"code","source":"detect_hemorrhage_from_nrrd_with_threashold.iloc[:,[2,5,6]]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.011665Z","iopub.execute_input":"2023-05-22T12:00:23.012176Z","iopub.status.idle":"2023-05-22T12:00:23.029569Z","shell.execute_reply.started":"2023-05-22T12:00:23.011973Z","shell.execute_reply":"2023-05-22T12:00:23.028578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"other_values = detect_hemorrhage_from_nrrd_with_threashold.iloc[:,[2,5,6]].values","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.031572Z","iopub.execute_input":"2023-05-22T12:00:23.032084Z","iopub.status.idle":"2023-05-22T12:00:23.040552Z","shell.execute_reply.started":"2023-05-22T12:00:23.031853Z","shell.execute_reply":"2023-05-22T12:00:23.039555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"other_values.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.042574Z","iopub.execute_input":"2023-05-22T12:00:23.043335Z","iopub.status.idle":"2023-05-22T12:00:23.051173Z","shell.execute_reply.started":"2023-05-22T12:00:23.043011Z","shell.execute_reply":"2023-05-22T12:00:23.050201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"other_values[55:65]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.053314Z","iopub.execute_input":"2023-05-22T12:00:23.053982Z","iopub.status.idle":"2023-05-22T12:00:23.061493Z","shell.execute_reply.started":"2023-05-22T12:00:23.053583Z","shell.execute_reply":"2023-05-22T12:00:23.06041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"other_values = [1 if (np.isin(other_values[idx], 1).sum() > 0) else 0 for idx in range(len(other_values))]","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.064519Z","iopub.execute_input":"2023-05-22T12:00:23.065967Z","iopub.status.idle":"2023-05-22T12:00:23.079745Z","shell.execute_reply.started":"2023-05-22T12:00:23.064807Z","shell.execute_reply":"2023-05-22T12:00:23.079147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"counter = 0\nfor i in range(len(other_values)):\n    if ( other_values[i] == 1):\n        counter +=1   \nprint(counter)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.0813Z","iopub.execute_input":"2023-05-22T12:00:23.081805Z","iopub.status.idle":"2023-05-22T12:00:23.088197Z","shell.execute_reply.started":"2023-05-22T12:00:23.081755Z","shell.execute_reply":"2023-05-22T12:00:23.087388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"other_real_values = segment_nrrd_df[\"other\"].values.astype(\"int32\")\nother_predicted_values = other_values","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.089522Z","iopub.execute_input":"2023-05-22T12:00:23.090045Z","iopub.status.idle":"2023-05-22T12:00:23.097177Z","shell.execute_reply.started":"2023-05-22T12:00:23.089993Z","shell.execute_reply":"2023-05-22T12:00:23.096408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print_conf_matrix(\"Other\", real_values=other_real_values, predicted_values=other_predicted_values)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.098865Z","iopub.execute_input":"2023-05-22T12:00:23.099439Z","iopub.status.idle":"2023-05-22T12:00:23.294025Z","shell.execute_reply.started":"2023-05-22T12:00:23.09939Z","shell.execute_reply":"2023-05-22T12:00:23.292049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#segment_nrrd_df.to_excel(\"segment_labels_v2.xlsx\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.295514Z","iopub.execute_input":"2023-05-22T12:00:23.296004Z","iopub.status.idle":"2023-05-22T12:00:23.300156Z","shell.execute_reply.started":"2023-05-22T12:00:23.29595Z","shell.execute_reply":"2023-05-22T12:00:23.299232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#nrrd_detection_hemorrhage.to_excel(\"nrrd_prediction.xlsx\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.301967Z","iopub.execute_input":"2023-05-22T12:00:23.30254Z","iopub.status.idle":"2023-05-22T12:00:23.310015Z","shell.execute_reply.started":"2023-05-22T12:00:23.302484Z","shell.execute_reply":"2023-05-22T12:00:23.308994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#detect_hemorrhage_from_nrrd_with_threashold.to_excel(\"nrr_prediction_with_threshold.xlsx\")","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.3115Z","iopub.execute_input":"2023-05-22T12:00:23.312012Z","iopub.status.idle":"2023-05-22T12:00:23.318995Z","shell.execute_reply.started":"2023-05-22T12:00:23.311935Z","shell.execute_reply":"2023-05-22T12:00:23.318099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 27 ADET HASTANIN NNRD SONUÇLARININ İNCELENMESİ ( 1 TANESİ SORUNLU )","metadata":{}},{"cell_type":"code","source":"all_patients_nrrd_path = \"/kaggle/input/all-patients-nrrd/\"\nprediction_nrrd_file_name = \"/prediction.nrrd\"\nsegment_nrrd_file_name = \"/segmentation.seg.nrrd\"\ntarget_names = [\"intraventricular\", \"intraparenchymal\", \"other\"]\nall_prediction_df = []\nall_segment_df = pd.DataFrame(columns=[\"id\",\"intraventricular\", \"intraparenchymal\", \"other\"])\nall_prediction_df = pd.DataFrame(columns=[\"id\",\"intraventricular\", \"intraparenchymal\", \"other\"])","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.320439Z","iopub.execute_input":"2023-05-22T12:00:23.321033Z","iopub.status.idle":"2023-05-22T12:00:23.335558Z","shell.execute_reply.started":"2023-05-22T12:00:23.320979Z","shell.execute_reply":"2023-05-22T12:00:23.335007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ----------------------------------","metadata":{}},{"cell_type":"code","source":"def read_segment_nrrd(segment_nrrd_path, nrrd_id, labels_dict):\n    \"\"\"\n    Açıklama: Bu fonkisyon etiketleme yapılmış nnrd dosyasını okuyarak dataframe'e aktarır.\n    Örnek \n    labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 }\n    \"\"\"\n    test_df = pd.DataFrame(columns=[\"id\",\"intraventricular\", \"intraparenchymal\", \"other\"])\n    readData, header = nrrd.read(segment_nrrd_path)\n    for idx in range(readData.shape[2]):\n        segment_nrrd = readData[:,:,idx]      \n        temp_array=[0,0,0]\n        counter = 0 # İndex belirtmektedir\n        for key, value in labels_dict.items():\n            if(value == -1):\n                counter +=1\n                continue\n            if(np.isin(segment_nrrd, value).sum() > 0):\n                temp_array[counter] = 1\n            counter +=1\n        temp_list = list(temp_array)\n        temp_list.insert(0, f\"{nrrd_id}---{idx}.dcm\")\n        test_df.loc[len(test_df)] = temp_list\n    return test_df","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.33683Z","iopub.execute_input":"2023-05-22T12:00:23.337404Z","iopub.status.idle":"2023-05-22T12:00:23.34878Z","shell.execute_reply.started":"2023-05-22T12:00:23.33735Z","shell.execute_reply":"2023-05-22T12:00:23.348191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def detect_hemorrhage_from_nrrd_with_threashold(nrrd_path, nrrd_id, threshold):\n    # Sonuçlar için dataframe oluşturma\n    test_df = pd.DataFrame(columns=[\"id\",\"intraventricular\", \"intraparenchymal\", \"other\"]) \n    readData, header = nrrd.read(nrrd_path) # Nrrd dosyasının okunması\n    for idx in range(readData.shape[2]): # Nrrd içerisindeki her bir slice'ın döngü ile elde edilmesi\n        prediction = model.model.predict(np.expand_dims(nrrd_read(readData[:,:,idx], (256, 256)),0))[0] # Detection happening here\n        temp = [0,0,0]\n        # \"intraventricular\", \"intraparenchymal\", \"other\" sırası ile diziye yerleştiriliyor.\n        # Eğer threshold'dan büyük bir değer ise 1 değil ise 0 olarak değiştirilir.\n        if(prediction[3] >= threshold):\n            temp[0] = 1\n        if(prediction[2] >= threshold):\n            temp[1] = 1\n        if((prediction[1] >= threshold) or (prediction[4] >= threshold) or (prediction[5] >= threshold)):\n            temp[2] = 1\n        prediction = list(temp) # Sonuç list olarak dönüştürülür\n        prediction.insert(0, f\"{nrrd_id}---{idx}.dcm\") # List başına slice ismini ekleme işlemi\n        test_df.loc[len(test_df)] = prediction # Her bir slice sonuçları dataframe'e yeni bir kayıt olara eklenir\n    return test_df # Nrrd'deki tüm slice'lara ait sonuçların bulunduğu dataframe","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.350349Z","iopub.execute_input":"2023-05-22T12:00:23.350945Z","iopub.status.idle":"2023-05-22T12:00:23.364448Z","shell.execute_reply.started":"2023-05-22T12:00:23.35071Z","shell.execute_reply":"2023-05-22T12:00:23.363401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1-  Patient ID = 2022_10_20_0421033701","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421033701\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:23.366432Z","iopub.execute_input":"2023-05-22T12:00:23.366978Z","iopub.status.idle":"2023-05-22T12:00:27.351139Z","shell.execute_reply.started":"2023-05-22T12:00:23.366709Z","shell.execute_reply":"2023-05-22T12:00:27.350415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:27.352937Z","iopub.execute_input":"2023-05-22T12:00:27.353431Z","iopub.status.idle":"2023-05-22T12:00:36.561895Z","shell.execute_reply.started":"2023-05-22T12:00:27.353375Z","shell.execute_reply":"2023-05-22T12:00:36.561034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2- Patient ID = 2022_10_20_0421033931","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421033931\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:36.563402Z","iopub.execute_input":"2023-05-22T12:00:36.563737Z","iopub.status.idle":"2023-05-22T12:00:40.868895Z","shell.execute_reply.started":"2023-05-22T12:00:36.563686Z","shell.execute_reply":"2023-05-22T12:00:40.868062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 1,\n                     \"intraparenchymal\": 2,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:40.870248Z","iopub.execute_input":"2023-05-22T12:00:40.870732Z","iopub.status.idle":"2023-05-22T12:00:49.78234Z","shell.execute_reply.started":"2023-05-22T12:00:40.87068Z","shell.execute_reply":"2023-05-22T12:00:49.781532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3- Patient ID = 2022_10_20_0421034201","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421034201\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:49.783694Z","iopub.execute_input":"2023-05-22T12:00:49.784179Z","iopub.status.idle":"2023-05-22T12:00:53.648583Z","shell.execute_reply.started":"2023-05-22T12:00:49.784126Z","shell.execute_reply":"2023-05-22T12:00:53.647695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:00:53.649974Z","iopub.execute_input":"2023-05-22T12:00:53.650325Z","iopub.status.idle":"2023-05-22T12:01:01.879368Z","shell.execute_reply.started":"2023-05-22T12:00:53.65026Z","shell.execute_reply":"2023-05-22T12:01:01.878394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 4- Patient ID = 2022_10_20_0421034932","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421034932\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:01.880976Z","iopub.execute_input":"2023-05-22T12:01:01.881455Z","iopub.status.idle":"2023-05-22T12:01:06.172391Z","shell.execute_reply.started":"2023-05-22T12:01:01.881404Z","shell.execute_reply":"2023-05-22T12:01:06.171544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 1,\n                     \"intraparenchymal\": -1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:06.17383Z","iopub.execute_input":"2023-05-22T12:01:06.17435Z","iopub.status.idle":"2023-05-22T12:01:15.02253Z","shell.execute_reply.started":"2023-05-22T12:01:06.174297Z","shell.execute_reply":"2023-05-22T12:01:15.0217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 5- Patient ID = 2022_10_20_0421035129","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421035129\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:15.024077Z","iopub.execute_input":"2023-05-22T12:01:15.024618Z","iopub.status.idle":"2023-05-22T12:01:19.110991Z","shell.execute_reply.started":"2023-05-22T12:01:15.024562Z","shell.execute_reply":"2023-05-22T12:01:19.108998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 2,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:19.112467Z","iopub.execute_input":"2023-05-22T12:01:19.112811Z","iopub.status.idle":"2023-05-22T12:01:28.35067Z","shell.execute_reply.started":"2023-05-22T12:01:19.112762Z","shell.execute_reply":"2023-05-22T12:01:28.349837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 6- Patient ID = 2022_10_20_0421035242","metadata":{},"attachments":{"6405b4f9-bbc0-4cf1-b034-f5ebac1cf9e8.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAbQAAAC9CAYAAADbTIg6AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACTFSURBVHhe7Z3PaxvH+8efz/cP0E26pIGPIxcCDiSNT/IlheIkvts1wZCDgy8l9GiE8NEY4WMpuZjkEDDFse9JYwLtxTo5acCGQq320PYi3/QPfL7zzI/dmZU0Wq0kWzt6v2BJtONZ7Yxm5vkxu8/zn//OzP6PAAAAgJzzf/rf0bL7jv768w91HO/okwAAAMD4GEqg1Y+10NLH8a4u2HxMM7e+pJ1GW5+YVHbo2Lp/pw3XBt/TKe2v648AAABSkVGgPaP93/6g1WKDdoTgYuHFx+KmLs4VbTrZ1m04atLs8juq6xIAAAD5IZtAW39AdwpNOrj3lPb0qdSsv6bPtlX022va0EWMa/W5loqvbCT83hLirUg3e32nda98/njXtvBcQejeq1XG7RfXqe+fRuWf95/JIlVnhWapQAtbXeoCAADoSTaBdrtEhXaLmv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+cO2W5joFqxob61Dk3MowdsvtbEGKM2H4k1h27X931Mf0a2A/EcvTAnc5umnwv/GoyIn0MACB0gnM5giRIHwMAmA4g0IKnRouJbN61yiUdWA+pAABACMDlCAAAIAhgoQEAAAgCCDQAAABBAIEGAAAgCCDQAAAABAEEGgAAgCCAQAMAABAEEGgAAACCAAINAABAEECgAQAACAIINAAAAAFA9P+iDq8foc1vugAAAABJRU5ErkJggg=="}}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421035242\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:28.352036Z","iopub.execute_input":"2023-05-22T12:01:28.352517Z","iopub.status.idle":"2023-05-22T12:01:32.453838Z","shell.execute_reply.started":"2023-05-22T12:01:28.352465Z","shell.execute_reply":"2023-05-22T12:01:32.453026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 1,\n                     \"intraparenchymal\": -1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:32.457263Z","iopub.execute_input":"2023-05-22T12:01:32.457517Z","iopub.status.idle":"2023-05-22T12:01:41.391058Z","shell.execute_reply.started":"2023-05-22T12:01:32.457469Z","shell.execute_reply":"2023-05-22T12:01:41.390222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 7- Patient ID = 2022_10_20_0421035334","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421035334\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:41.392404Z","iopub.execute_input":"2023-05-22T12:01:41.392886Z","iopub.status.idle":"2023-05-22T12:01:45.415689Z","shell.execute_reply.started":"2023-05-22T12:01:41.392834Z","shell.execute_reply":"2023-05-22T12:01:45.414753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:45.417057Z","iopub.execute_input":"2023-05-22T12:01:45.417393Z","iopub.status.idle":"2023-05-22T12:01:53.746488Z","shell.execute_reply.started":"2023-05-22T12:01:45.417341Z","shell.execute_reply":"2023-05-22T12:01:53.744693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 8- Patient ID = 2022_10_20_0421035458","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421035458\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:53.74811Z","iopub.execute_input":"2023-05-22T12:01:53.748457Z","iopub.status.idle":"2023-05-22T12:01:58.505034Z","shell.execute_reply.started":"2023-05-22T12:01:53.748403Z","shell.execute_reply":"2023-05-22T12:01:58.503003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:01:58.506727Z","iopub.execute_input":"2023-05-22T12:01:58.507108Z","iopub.status.idle":"2023-05-22T12:02:08.383605Z","shell.execute_reply.started":"2023-05-22T12:01:58.50704Z","shell.execute_reply":"2023-05-22T12:02:08.382773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 9- Patient ID = 2022_10_20_0421035730  ---->>>>>>>>>>> ***************SORUNLU","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421035730\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:08.384947Z","iopub.execute_input":"2023-05-22T12:02:08.385429Z","iopub.status.idle":"2023-05-22T12:02:14.09625Z","shell.execute_reply.started":"2023-05-22T12:02:08.385378Z","shell.execute_reply":"2023-05-22T12:02:14.095404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"\nsegment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))\n\"\"\"","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:14.097583Z","iopub.execute_input":"2023-05-22T12:02:14.098092Z","iopub.status.idle":"2023-05-22T12:02:14.104972Z","shell.execute_reply.started":"2023-05-22T12:02:14.098028Z","shell.execute_reply":"2023-05-22T12:02:14.104123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 10- Patient ID = 2022_10_20_0421040036","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421040036\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:14.106581Z","iopub.execute_input":"2023-05-22T12:02:14.107133Z","iopub.status.idle":"2023-05-22T12:02:17.595888Z","shell.execute_reply.started":"2023-05-22T12:02:14.107081Z","shell.execute_reply":"2023-05-22T12:02:17.59504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 2,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:17.597261Z","iopub.execute_input":"2023-05-22T12:02:17.59773Z","iopub.status.idle":"2023-05-22T12:02:26.080635Z","shell.execute_reply.started":"2023-05-22T12:02:17.597679Z","shell.execute_reply":"2023-05-22T12:02:26.078749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 11- Patient ID = 2022_10_20_0421040141","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421040141\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:26.082031Z","iopub.execute_input":"2023-05-22T12:02:26.082324Z","iopub.status.idle":"2023-05-22T12:02:30.622597Z","shell.execute_reply.started":"2023-05-22T12:02:26.08227Z","shell.execute_reply":"2023-05-22T12:02:30.621701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": 2\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:30.623977Z","iopub.execute_input":"2023-05-22T12:02:30.624458Z","iopub.status.idle":"2023-05-22T12:02:40.611675Z","shell.execute_reply.started":"2023-05-22T12:02:30.624406Z","shell.execute_reply":"2023-05-22T12:02:40.610957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 12- Patient ID = 2022_10_20_0421040333","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421040333\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:40.615072Z","iopub.execute_input":"2023-05-22T12:02:40.61532Z","iopub.status.idle":"2023-05-22T12:02:44.503586Z","shell.execute_reply.started":"2023-05-22T12:02:40.615274Z","shell.execute_reply":"2023-05-22T12:02:44.502743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": 2\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:44.504965Z","iopub.execute_input":"2023-05-22T12:02:44.505438Z","iopub.status.idle":"2023-05-22T12:02:52.897497Z","shell.execute_reply.started":"2023-05-22T12:02:44.505385Z","shell.execute_reply":"2023-05-22T12:02:52.896658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 13- Patient ID = 2022_10_20_04211100320","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_04211100320\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:52.898871Z","iopub.execute_input":"2023-05-22T12:02:52.899372Z","iopub.status.idle":"2023-05-22T12:02:57.146576Z","shell.execute_reply.started":"2023-05-22T12:02:52.89932Z","shell.execute_reply":"2023-05-22T12:02:57.14573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:02:57.148018Z","iopub.execute_input":"2023-05-22T12:02:57.148494Z","iopub.status.idle":"2023-05-22T12:03:06.654881Z","shell.execute_reply.started":"2023-05-22T12:02:57.14844Z","shell.execute_reply":"2023-05-22T12:03:06.653949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 14- Patient ID = 2022_10_20_0421110227","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421110227\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:06.656282Z","iopub.execute_input":"2023-05-22T12:03:06.656756Z","iopub.status.idle":"2023-05-22T12:03:10.66015Z","shell.execute_reply.started":"2023-05-22T12:03:06.656704Z","shell.execute_reply":"2023-05-22T12:03:10.659297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": 2\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:10.664494Z","iopub.execute_input":"2023-05-22T12:03:10.666946Z","iopub.status.idle":"2023-05-22T12:03:18.170859Z","shell.execute_reply.started":"2023-05-22T12:03:10.666874Z","shell.execute_reply":"2023-05-22T12:03:18.169051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 15- Patient ID = 2022_10_20_0421110416","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421110416\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:18.17229Z","iopub.execute_input":"2023-05-22T12:03:18.172596Z","iopub.status.idle":"2023-05-22T12:03:22.316705Z","shell.execute_reply.started":"2023-05-22T12:03:18.172535Z","shell.execute_reply":"2023-05-22T12:03:22.315688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": 2\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:22.318164Z","iopub.execute_input":"2023-05-22T12:03:22.318478Z","iopub.status.idle":"2023-05-22T12:03:31.417388Z","shell.execute_reply.started":"2023-05-22T12:03:22.318429Z","shell.execute_reply":"2023-05-22T12:03:31.415637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 16- Patient ID = 2022_10_20_0421110502","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421110502\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:31.418848Z","iopub.execute_input":"2023-05-22T12:03:31.419181Z","iopub.status.idle":"2023-05-22T12:03:35.12885Z","shell.execute_reply.started":"2023-05-22T12:03:31.419131Z","shell.execute_reply":"2023-05-22T12:03:35.126661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 2,\n                     \"intraparenchymal\": 1,\n                     \"other\": 3\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:35.130565Z","iopub.execute_input":"2023-05-22T12:03:35.130866Z","iopub.status.idle":"2023-05-22T12:03:43.230251Z","shell.execute_reply.started":"2023-05-22T12:03:35.130813Z","shell.execute_reply":"2023-05-22T12:03:43.229409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 17- Patient ID = 2022_10_20_0421110809","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421110809\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:43.23161Z","iopub.execute_input":"2023-05-22T12:03:43.232111Z","iopub.status.idle":"2023-05-22T12:03:47.040201Z","shell.execute_reply.started":"2023-05-22T12:03:43.232058Z","shell.execute_reply":"2023-05-22T12:03:47.039294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:47.041585Z","iopub.execute_input":"2023-05-22T12:03:47.042101Z","iopub.status.idle":"2023-05-22T12:03:55.046479Z","shell.execute_reply.started":"2023-05-22T12:03:47.042045Z","shell.execute_reply":"2023-05-22T12:03:55.045662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 18- Patient ID = 2022_10_20_0421110905","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421110905\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:55.047837Z","iopub.execute_input":"2023-05-22T12:03:55.048334Z","iopub.status.idle":"2023-05-22T12:03:59.462058Z","shell.execute_reply.started":"2023-05-22T12:03:55.04828Z","shell.execute_reply":"2023-05-22T12:03:59.461214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 2,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:03:59.463483Z","iopub.execute_input":"2023-05-22T12:03:59.463999Z","iopub.status.idle":"2023-05-22T12:04:08.95274Z","shell.execute_reply.started":"2023-05-22T12:03:59.463944Z","shell.execute_reply":"2023-05-22T12:04:08.951898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 19- Patient ID = 2022_10_20_0421110936","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421110936\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:04:08.954128Z","iopub.execute_input":"2023-05-22T12:04:08.954631Z","iopub.status.idle":"2023-05-22T12:04:13.82545Z","shell.execute_reply.started":"2023-05-22T12:04:08.954576Z","shell.execute_reply":"2023-05-22T12:04:13.824667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:04:13.829671Z","iopub.execute_input":"2023-05-22T12:04:13.831898Z","iopub.status.idle":"2023-05-22T12:04:22.783155Z","shell.execute_reply.started":"2023-05-22T12:04:13.831843Z","shell.execute_reply":"2023-05-22T12:04:22.782316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 20- Patient ID = 2022_10_20_0421111011","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421111011\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:04:22.784463Z","iopub.execute_input":"2023-05-22T12:04:22.784961Z","iopub.status.idle":"2023-05-22T12:04:26.405604Z","shell.execute_reply.started":"2023-05-22T12:04:22.78489Z","shell.execute_reply":"2023-05-22T12:04:26.404759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:04:26.407069Z","iopub.execute_input":"2023-05-22T12:04:26.407543Z","iopub.status.idle":"2023-05-22T12:04:34.793829Z","shell.execute_reply.started":"2023-05-22T12:04:26.407491Z","shell.execute_reply":"2023-05-22T12:04:34.793015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 21- Patient ID = 2022_10_20_0421111110","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421111110\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:04:34.795407Z","iopub.execute_input":"2023-05-22T12:04:34.795895Z","iopub.status.idle":"2023-05-22T12:04:38.774447Z","shell.execute_reply.started":"2023-05-22T12:04:34.795843Z","shell.execute_reply":"2023-05-22T12:04:38.773554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:04:38.775986Z","iopub.execute_input":"2023-05-22T12:04:38.776533Z","iopub.status.idle":"2023-05-22T12:04:48.210989Z","shell.execute_reply.started":"2023-05-22T12:04:38.776481Z","shell.execute_reply":"2023-05-22T12:04:48.209238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 22- Patient ID = 2022_10_20_0421111206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AcED4AQAACA4IPwAAAMEB4QcAACA4IPwAAAAEB4QfAACA4IDwAwAAEBwQfgAAAAKD6P8BBliwU1pZUUcAAAAASUVORK5CYII="}}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421111206\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:04:48.212583Z","iopub.execute_input":"2023-05-22T12:04:48.212927Z","iopub.status.idle":"2023-05-22T12:04:52.426529Z","shell.execute_reply.started":"2023-05-22T12:04:48.212834Z","shell.execute_reply":"2023-05-22T12:04:52.425684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:04:52.428011Z","iopub.execute_input":"2023-05-22T12:04:52.428479Z","iopub.status.idle":"2023-05-22T12:05:00.932856Z","shell.execute_reply.started":"2023-05-22T12:04:52.428285Z","shell.execute_reply":"2023-05-22T12:05:00.93102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 23- Patient ID = 2022_10_20_0421111254","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421111254\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:00.934621Z","iopub.execute_input":"2023-05-22T12:05:00.934991Z","iopub.status.idle":"2023-05-22T12:05:05.081973Z","shell.execute_reply.started":"2023-05-22T12:05:00.934939Z","shell.execute_reply":"2023-05-22T12:05:05.081083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 3,\n                     \"intraparenchymal\": 1,\n                     \"other\": 2\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:05.083359Z","iopub.execute_input":"2023-05-22T12:05:05.083834Z","iopub.status.idle":"2023-05-22T12:05:13.761432Z","shell.execute_reply.started":"2023-05-22T12:05:05.083782Z","shell.execute_reply":"2023-05-22T12:05:13.759447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 24- Patient ID = 2022_10_20_0421111354","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421111354\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:13.762897Z","iopub.execute_input":"2023-05-22T12:05:13.763217Z","iopub.status.idle":"2023-05-22T12:05:18.358124Z","shell.execute_reply.started":"2023-05-22T12:05:13.763166Z","shell.execute_reply":"2023-05-22T12:05:18.357248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:18.359499Z","iopub.execute_input":"2023-05-22T12:05:18.360002Z","iopub.status.idle":"2023-05-22T12:05:28.433708Z","shell.execute_reply.started":"2023-05-22T12:05:18.359949Z","shell.execute_reply":"2023-05-22T12:05:28.432856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 25- Patient ID = 2022_10_20_0421111439","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421111439\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:28.435076Z","iopub.execute_input":"2023-05-22T12:05:28.435547Z","iopub.status.idle":"2023-05-22T12:05:32.710802Z","shell.execute_reply.started":"2023-05-22T12:05:28.435495Z","shell.execute_reply":"2023-05-22T12:05:32.710106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": -1,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:32.714222Z","iopub.execute_input":"2023-05-22T12:05:32.714476Z","iopub.status.idle":"2023-05-22T12:05:41.74245Z","shell.execute_reply.started":"2023-05-22T12:05:32.71443Z","shell.execute_reply":"2023-05-22T12:05:41.741664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 26- Patient ID = 2022_10_20_0421111505","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421111505\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:41.743769Z","iopub.execute_input":"2023-05-22T12:05:41.744101Z","iopub.status.idle":"2023-05-22T12:05:46.063484Z","shell.execute_reply.started":"2023-05-22T12:05:41.744044Z","shell.execute_reply":"2023-05-22T12:05:46.06266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 2,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:46.06497Z","iopub.execute_input":"2023-05-22T12:05:46.065534Z","iopub.status.idle":"2023-05-22T12:05:55.753304Z","shell.execute_reply.started":"2023-05-22T12:05:46.065475Z","shell.execute_reply":"2023-05-22T12:05:55.752464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 27- Patient ID = 2022_10_20_0421111534","metadata":{}},{"cell_type":"code","source":"nrrd_id = \"2022_10_20_0421111534\"\npredictionData, predictionHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name)\nsegmentData, segmentHeader = nrrd.read(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name)\nprint(np.unique(segmentData))\nprint(segmentHeader)","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:05:55.754719Z","iopub.execute_input":"2023-05-22T12:05:55.755358Z","iopub.status.idle":"2023-05-22T12:06:00.382369Z","shell.execute_reply.started":"2023-05-22T12:05:55.755305Z","shell.execute_reply":"2023-05-22T12:06:00.37997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segment_result = read_segment_nrrd(all_patients_nrrd_path + nrrd_id + segment_nrrd_file_name, \n                  nrrd_id, \n                  labels_dict = {\n                     \"intraventricular\": 2,\n                     \"intraparenchymal\": 1,\n                     \"other\": -1\n                 })\n\nall_segment_df = pd.concat([all_segment_df, segment_result], ignore_index=True)\n\nprediction_result = detect_hemorrhage_from_nrrd_with_threashold(all_patients_nrrd_path + nrrd_id + prediction_nrrd_file_name, nrrd_id, 0.5)\n\nall_prediction_df = pd.concat([all_prediction_df, prediction_result], ignore_index=True)\n\ny_true = segment_result.iloc[:,1:].values.astype('int32')\ny_pred = prediction_result.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:06:00.383819Z","iopub.execute_input":"2023-05-22T12:06:00.38432Z","iopub.status.idle":"2023-05-22T12:06:10.81081Z","shell.execute_reply.started":"2023-05-22T12:06:00.384109Z","shell.execute_reply":"2023-05-22T12:06:10.809948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_prediction_df","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:06:10.81224Z","iopub.execute_input":"2023-05-22T12:06:10.812719Z","iopub.status.idle":"2023-05-22T12:06:10.8306Z","shell.execute_reply.started":"2023-05-22T12:06:10.812666Z","shell.execute_reply":"2023-05-22T12:06:10.829978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_segment_df","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:06:10.832062Z","iopub.execute_input":"2023-05-22T12:06:10.832381Z","iopub.status.idle":"2023-05-22T12:06:10.848076Z","shell.execute_reply.started":"2023-05-22T12:06:10.832332Z","shell.execute_reply":"2023-05-22T12:06:10.847261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_true = all_segment_df.iloc[:,1:].values.astype('int32')\ny_pred = all_prediction_df.iloc[:,1:].values.astype('int32')\nprint(\"Conf Matrix \\n-----------\\n\" , multilabel_confusion_matrix(y_true, y_pred))\nprint(\"Class. Report \\n-------------\\n\" , classification_report(y_true, y_pred,target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2023-05-22T12:06:10.849322Z","iopub.execute_input":"2023-05-22T12:06:10.849773Z","iopub.status.idle":"2023-05-22T12:06:10.877893Z","shell.execute_reply.started":"2023-05-22T12:06:10.849723Z","shell.execute_reply":"2023-05-22T12:06:10.876831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}