{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":52254,"databundleVersionId":6863140,"sourceType":"competition"},{"sourceId":6211844,"sourceType":"datasetVersion","datasetId":3567114}],"dockerImageVersionId":30554,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <center>Multi-label classification of abdominal trauma from CT images</center>\n\n","metadata":{"papermill":{"duration":0.025483,"end_time":"2022-02-01T10:21:43.84374","exception":false,"start_time":"2022-02-01T10:21:43.818257","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"## To commence this project, the neccesary libraries need to be installed.\n## We would be using the **TensorFlow** framework and the pretrained **EfficientNetB1**\n","metadata":{}},{"cell_type":"code","source":"# Imporitng libraries\nimport pandas as pd\nimport os\nimport random\nimport numpy as np\nimport tensorflow as tf\nimport cv2\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom IPython.display import clear_output\nfrom sklearn.metrics import confusion_matrix\nfrom sklearn.model_selection import StratifiedKFold\n\n\nrandom.seed(42)","metadata":{"id":"fUPKjZaaJHkM","papermill":{"duration":5.021373,"end_time":"2022-02-01T10:21:48.88737","exception":false,"start_time":"2022-02-01T10:21:43.865997","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-06-17T22:01:40.972551Z","iopub.execute_input":"2024-06-17T22:01:40.972891Z","iopub.status.idle":"2024-06-17T22:01:49.664133Z","shell.execute_reply.started":"2024-06-17T22:01:40.972862Z","shell.execute_reply":"2024-06-17T22:01:49.663301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Loading the training dataset\ntrain_img = \"/kaggle/input/rsna-atd-512x512-png-v2-dataset/train_images\"","metadata":{"execution":{"iopub.status.busy":"2024-06-17T22:01:49.665725Z","iopub.execute_input":"2024-06-17T22:01:49.666316Z","iopub.status.idle":"2024-06-17T22:01:49.670636Z","shell.execute_reply.started":"2024-06-17T22:01:49.666286Z","shell.execute_reply":"2024-06-17T22:01:49.669727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in os.listdir(train_img):\n    for j in os.listdir(os.path.join(train_img,i)):\n        print(len(os.listdir(os.path.join(train_img,i,j))))","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-06-17T22:01:49.671836Z","iopub.execute_input":"2024-06-17T22:01:49.672112Z","iopub.status.idle":"2024-06-17T22:01:57.609882Z","shell.execute_reply.started":"2024-06-17T22:01:49.672089Z","shell.execute_reply":"2024-06-17T22:01:57.608964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install imbalanced-learn","metadata":{"execution":{"iopub.status.busy":"2024-06-17T22:01:57.612119Z","iopub.execute_input":"2024-06-17T22:01:57.612395Z","iopub.status.idle":"2024-06-17T22:02:08.966531Z","shell.execute_reply.started":"2024-06-17T22:01:57.612371Z","shell.execute_reply":"2024-06-17T22:02:08.965416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Part A\n## Import and explore the data","metadata":{"papermill":{"duration":0.02193,"end_time":"2022-02-01T10:21:48.93356","exception":false,"start_time":"2022-02-01T10:21:48.91163","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# Making a list containing all unique classes in the training set\n\n# Reading the training labels\ntraining_labels = pd.read_csv(\"/kaggle/input/rsna-2023-abdominal-trauma-detection/train_2024.csv\")","metadata":{"id":"PBlH8ae3LbG0","papermill":{"duration":0.069238,"end_time":"2022-02-01T10:21:49.024476","exception":false,"start_time":"2022-02-01T10:21:48.955238","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-06-17T22:02:08.968154Z","iopub.execute_input":"2024-06-17T22:02:08.968546Z","iopub.status.idle":"2024-06-17T22:02:08.994847Z","shell.execute_reply.started":"2024-06-17T22:02:08.968509Z","shell.execute_reply":"2024-06-17T22:02:08.994177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Viewing the dataset in a structured format\ntraining_labels","metadata":{"execution":{"iopub.status.busy":"2024-06-17T22:02:08.996236Z","iopub.execute_input":"2024-06-17T22:02:08.996499Z","iopub.status.idle":"2024-06-17T22:02:09.022683Z","shell.execute_reply.started":"2024-06-17T22:02:08.996475Z","shell.execute_reply":"2024-06-17T22:02:09.021692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Part B\n## In the next few cells, we chose to explore the dataframe to check for missing values","metadata":{}},{"cell_type":"code","source":"training_labels.columns","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.006948Z","iopub.execute_input":"2023-10-30T20:31:32.007229Z","iopub.status.idle":"2023-10-30T20:31:32.01436Z","shell.execute_reply.started":"2023-10-30T20:31:32.007204Z","shell.execute_reply":"2023-10-30T20:31:32.013463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['patient_id'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.015579Z","iopub.execute_input":"2023-10-30T20:31:32.015867Z","iopub.status.idle":"2023-10-30T20:31:32.026634Z","shell.execute_reply.started":"2023-10-30T20:31:32.015842Z","shell.execute_reply":"2023-10-30T20:31:32.025549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['bowel_healthy'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.027991Z","iopub.execute_input":"2023-10-30T20:31:32.028288Z","iopub.status.idle":"2023-10-30T20:31:32.038159Z","shell.execute_reply.started":"2023-10-30T20:31:32.02825Z","shell.execute_reply":"2023-10-30T20:31:32.037188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['bowel_injury'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.039497Z","iopub.execute_input":"2023-10-30T20:31:32.03981Z","iopub.status.idle":"2023-10-30T20:31:32.049345Z","shell.execute_reply.started":"2023-10-30T20:31:32.039787Z","shell.execute_reply":"2023-10-30T20:31:32.048467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['extravasation_healthy'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.050672Z","iopub.execute_input":"2023-10-30T20:31:32.051293Z","iopub.status.idle":"2023-10-30T20:31:32.059799Z","shell.execute_reply.started":"2023-10-30T20:31:32.051261Z","shell.execute_reply":"2023-10-30T20:31:32.058844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['extravasation_injury'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.061113Z","iopub.execute_input":"2023-10-30T20:31:32.061446Z","iopub.status.idle":"2023-10-30T20:31:32.071902Z","shell.execute_reply.started":"2023-10-30T20:31:32.061416Z","shell.execute_reply":"2023-10-30T20:31:32.071027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['kidney_healthy'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.073001Z","iopub.execute_input":"2023-10-30T20:31:32.073324Z","iopub.status.idle":"2023-10-30T20:31:32.08242Z","shell.execute_reply.started":"2023-10-30T20:31:32.0733Z","shell.execute_reply":"2023-10-30T20:31:32.08155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['kidney_low'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.087736Z","iopub.execute_input":"2023-10-30T20:31:32.087997Z","iopub.status.idle":"2023-10-30T20:31:32.095241Z","shell.execute_reply.started":"2023-10-30T20:31:32.087974Z","shell.execute_reply":"2023-10-30T20:31:32.094358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['kidney_high'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.096435Z","iopub.execute_input":"2023-10-30T20:31:32.09682Z","iopub.status.idle":"2023-10-30T20:31:32.105924Z","shell.execute_reply.started":"2023-10-30T20:31:32.096789Z","shell.execute_reply":"2023-10-30T20:31:32.105029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['liver_healthy'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.107023Z","iopub.execute_input":"2023-10-30T20:31:32.107289Z","iopub.status.idle":"2023-10-30T20:31:32.117752Z","shell.execute_reply.started":"2023-10-30T20:31:32.107265Z","shell.execute_reply":"2023-10-30T20:31:32.116811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['liver_low'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.11884Z","iopub.execute_input":"2023-10-30T20:31:32.119105Z","iopub.status.idle":"2023-10-30T20:31:32.129736Z","shell.execute_reply.started":"2023-10-30T20:31:32.119083Z","shell.execute_reply":"2023-10-30T20:31:32.128886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['liver_high'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.130813Z","iopub.execute_input":"2023-10-30T20:31:32.131066Z","iopub.status.idle":"2023-10-30T20:31:32.140336Z","shell.execute_reply.started":"2023-10-30T20:31:32.131043Z","shell.execute_reply":"2023-10-30T20:31:32.139461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['spleen_healthy'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.141637Z","iopub.execute_input":"2023-10-30T20:31:32.141882Z","iopub.status.idle":"2023-10-30T20:31:32.15168Z","shell.execute_reply.started":"2023-10-30T20:31:32.141861Z","shell.execute_reply":"2023-10-30T20:31:32.150708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['spleen_low'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.152702Z","iopub.execute_input":"2023-10-30T20:31:32.153014Z","iopub.status.idle":"2023-10-30T20:31:32.162811Z","shell.execute_reply.started":"2023-10-30T20:31:32.152989Z","shell.execute_reply":"2023-10-30T20:31:32.161966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['spleen_high'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.163977Z","iopub.execute_input":"2023-10-30T20:31:32.164241Z","iopub.status.idle":"2023-10-30T20:31:32.174468Z","shell.execute_reply.started":"2023-10-30T20:31:32.164218Z","shell.execute_reply":"2023-10-30T20:31:32.173443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels['any_injury'].isna().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.175635Z","iopub.execute_input":"2023-10-30T20:31:32.175888Z","iopub.status.idle":"2023-10-30T20:31:32.184669Z","shell.execute_reply.started":"2023-10-30T20:31:32.17586Z","shell.execute_reply":"2023-10-30T20:31:32.183795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Using the EfficientNetB1 model and tweaking the last two layers to suit our work\ndef create_model(decay_steps=10,warmup_steps=10):\n    base_model = tf.keras.applications.EfficientNetB1(\n    weights= \"imagenet\", include_top=False, input_shape= (512,512,3)\n    )\n    num_classes=61\n\n    x = base_model.output\n    x = tf.keras.layers.GlobalAveragePooling2D()(x)\n    x = tf.keras.layers.Dropout(0.2)(x)\n    x_bowel = tf.keras.layers.Dense(32, activation='silu')(x)\n    x_extra = tf.keras.layers.Dense(32, activation='silu')(x)\n    x_liver = tf.keras.layers.Dense(32, activation='silu')(x)\n    x_kidney = tf.keras.layers.Dense(32, activation='silu')(x)\n    x_spleen = tf.keras.layers.Dense(32, activation='silu')(x)\n\n    # Define heads\n    out_bowel = tf.keras.layers.Dense(1, name='bowel', activation='sigmoid')(x_bowel) # use sigmoid to convert predictions to [0-1]\n    out_extra = tf.keras.layers.Dense(1, name='extra', activation='sigmoid')(x_extra) # use sigmoid to convert predictions to [0-1]\n    out_liver = tf.keras.layers.Dense(3, name='liver', activation='softmax')(x_liver) # use softmax for the liver head\n    out_kidney = tf.keras.layers.Dense(3, name='kidney', activation='softmax')(x_kidney) # use softmax for the kidney head\n    out_spleen = tf.keras.layers.Dense(3, name='spleen', activation='softmax')(x_spleen) # use softmax for the spleen head\n\n    model = tf.keras.Model(inputs = base_model.input, outputs = [out_bowel,out_extra,out_liver,out_kidney,out_spleen])\n        # Cosine Decay\n    cosine_decay = tf.keras.optimizers.schedules.CosineDecay(\n        initial_learning_rate=1e-4,\n        decay_steps=decay_steps,\n        alpha=0.0,\n        #warmup_target=1e-3,\n        #warmup_steps=warmup_steps,\n    )\n\n    # Compile the model\n    optimizer = tf.keras.optimizers.Adam(learning_rate=cosine_decay)\n    loss = [\n        tf.keras.losses.BinaryCrossentropy(),\n        tf.keras.losses.BinaryCrossentropy(),\n        tf.keras.losses.CategoricalCrossentropy(),\n        tf.keras.losses.CategoricalCrossentropy(),\n        tf.keras.losses.CategoricalCrossentropy()]\n    \n    metrics = [\n        [tf.keras.metrics.BinaryAccuracy(name=\"bowel_binary_accuracy\")],\n        [tf.keras.metrics.BinaryAccuracy(name=\"extra_binary_accuracy\")],\n        [tf.keras.metrics.CategoricalAccuracy(name=\"liver_cat_accuracy\")],\n        [tf.keras.metrics.CategoricalAccuracy(name=\"kidney_cat_accuracy\")],\n        [tf.keras.metrics.CategoricalAccuracy(name=\"spleen_cat_accuracy\")]]\n    #    \"bowel\":[\"accuracy\"],\n    #    \"extra\":[\"accuracy\"],\n    #    \"liver\":[\"accuracy\"],\n    #    \"kidney\":[\"accuracy\"],\n    #    \"spleen\":[\"accuracy\"],\n    #}\n    print(\"[INFO] Compiling the model...\")\n    model.compile(\n        optimizer=optimizer,\n      loss=loss,\n      metrics=metrics\n    )\n    return model","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.185975Z","iopub.execute_input":"2023-10-30T20:31:32.186259Z","iopub.status.idle":"2023-10-30T20:31:32.204138Z","shell.execute_reply.started":"2023-10-30T20:31:32.186235Z","shell.execute_reply":"2023-10-30T20:31:32.203306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = create_model()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:32.205247Z","iopub.execute_input":"2023-10-30T20:31:32.205534Z","iopub.status.idle":"2023-10-30T20:31:35.619383Z","shell.execute_reply.started":"2023-10-30T20:31:32.205488Z","shell.execute_reply":"2023-10-30T20:31:35.61843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:35.620707Z","iopub.execute_input":"2023-10-30T20:31:35.621072Z","iopub.status.idle":"2023-10-30T20:31:36.439586Z","shell.execute_reply.started":"2023-10-30T20:31:35.621039Z","shell.execute_reply":"2023-10-30T20:31:36.438649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.plot_model(\n    model,\n    to_file='model.png'\n)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:36.440796Z","iopub.execute_input":"2023-10-30T20:31:36.441082Z","iopub.status.idle":"2023-10-30T20:31:38.748688Z","shell.execute_reply.started":"2023-10-30T20:31:36.441057Z","shell.execute_reply":"2023-10-30T20:31:38.747217Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_labels = training_labels.set_index('patient_id')\ntraining_labels.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:38.750516Z","iopub.execute_input":"2023-10-30T20:31:38.751614Z","iopub.status.idle":"2023-10-30T20:31:38.766715Z","shell.execute_reply.started":"2023-10-30T20:31:38.751584Z","shell.execute_reply":"2023-10-30T20:31:38.765518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Part C\n## Balancing the imbalanced training dataset ","metadata":{}},{"cell_type":"code","source":"#Using histogram to get the distribution of the labels and to check if there are outliers and wrong labels\ntraining_labels.hist(figsize=(20,12),bins=2)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:38.767917Z","iopub.execute_input":"2023-10-30T20:31:38.768218Z","iopub.status.idle":"2023-10-30T20:31:40.948098Z","shell.execute_reply.started":"2023-10-30T20:31:38.768182Z","shell.execute_reply":"2023-10-30T20:31:40.947104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#images ,labels","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:40.949322Z","iopub.execute_input":"2023-10-30T20:31:40.949636Z","iopub.status.idle":"2023-10-30T20:31:40.953848Z","shell.execute_reply.started":"2023-10-30T20:31:40.94961Z","shell.execute_reply":"2023-10-30T20:31:40.95293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = []\nlabels = []\nfor i in sorted(os.listdir(train_img)):\n    folder = os.listdir(os.path.join(train_img,i))[0]\n    file = os.listdir(os.path.join(train_img,i,folder))[0]\n    images.append(cv2.imread(os.path.join(train_img,i,folder,file), cv2.IMREAD_COLOR ))\n    labels.append(np.asarray(training_labels.loc[int(i)]))\nimages = np.asarray(images)\nlabels = np.asarray(labels)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:31:40.95581Z","iopub.execute_input":"2023-10-30T20:31:40.95619Z","iopub.status.idle":"2023-10-30T20:31:42.162489Z","shell.execute_reply.started":"2023-10-30T20:31:40.956148Z","shell.execute_reply":"2023-10-30T20:31:42.161706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Examples of images","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(30,12))\nfor i in range(10):\n    plt.subplot(2,5,i+1)\n    plt.imshow(images[i])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T20:51:03.994535Z","iopub.execute_input":"2023-10-30T20:51:03.995415Z","iopub.status.idle":"2023-10-30T20:51:06.104331Z","shell.execute_reply.started":"2023-10-30T20:51:03.995381Z","shell.execute_reply":"2023-10-30T20:51:06.102807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:06:48.20857Z","iopub.execute_input":"2023-10-30T21:06:48.209581Z","iopub.status.idle":"2023-10-30T21:06:48.2139Z","shell.execute_reply.started":"2023-10-30T21:06:48.209544Z","shell.execute_reply":"2023-10-30T21:06:48.212876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(images, labels, test_size=0.25)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:16:23.5431Z","iopub.execute_input":"2023-10-30T21:16:23.54402Z","iopub.status.idle":"2023-10-30T21:16:23.603742Z","shell.execute_reply.started":"2023-10-30T21:16:23.543984Z","shell.execute_reply":"2023-10-30T21:16:23.602873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from imblearn.over_sampling import RandomOverSampler\n\n#oversampler = RandomOverSampler(random_state=42)\n#new_images, new_labels = oversampler.fit_resample(images, labels)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:16:23.868532Z","iopub.execute_input":"2023-10-30T21:16:23.868859Z","iopub.status.idle":"2023-10-30T21:16:23.873112Z","shell.execute_reply.started":"2023-10-30T21:16:23.868833Z","shell.execute_reply":"2023-10-30T21:16:23.87217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Part D\n## Training the model with the training dataset","metadata":{}},{"cell_type":"code","source":"bowel_labels = labels[:,2]\nextravasation_labels = labels[:,4]\nkidney_labels = labels[:,4:7]\nliver_labels = labels[:,7:10]\nspleen_labels = labels[:,10:13]\nany_labels = labels[:,-1]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:16:24.426642Z","iopub.execute_input":"2023-10-30T21:16:24.427516Z","iopub.status.idle":"2023-10-30T21:16:24.432745Z","shell.execute_reply.started":"2023-10-30T21:16:24.42747Z","shell.execute_reply":"2023-10-30T21:16:24.431654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bowel_val = y_val[:,2]\nextravasation_val = y_val[:,4]\nkidney_val = y_val[:,4:7]\nliver_val = y_val[:,7:10]\nspleen_val = y_val[:,10:13]\nany_val = y_val[:,-1]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:20:41.331157Z","iopub.execute_input":"2023-10-30T21:20:41.331579Z","iopub.status.idle":"2023-10-30T21:20:41.340406Z","shell.execute_reply.started":"2023-10-30T21:20:41.331545Z","shell.execute_reply":"2023-10-30T21:20:41.339412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bowel_train = y_train[:,2]\nextravasation_train = y_train[:,4]\nkidney_train = y_train[:,4:7]\nliver_train = y_train[:,7:10]\nspleen_train = y_train[:,10:13]\nany_train = y_train[:,-1]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:20:41.840491Z","iopub.execute_input":"2023-10-30T21:20:41.840861Z","iopub.status.idle":"2023-10-30T21:20:41.846179Z","shell.execute_reply.started":"2023-10-30T21:20:41.84083Z","shell.execute_reply":"2023-10-30T21:20:41.845192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 20\nnum_epoch = 20\nhistory = model.fit(x=X_train,y=[bowel_train,extravasation_train,kidney_train,liver_train,spleen_train],batch_size=batch_size, epochs=num_epoch, verbose=1, validation_data=(X_val,[bowel_val,extravasation_val,kidney_val,liver_val,spleen_val]))\n\n\nvalidation_data=(X_val,[bowel_val,extravasation_val,kidney_val,liver_val,spleen_val])","metadata":{"papermill":{"duration":1176.379334,"end_time":"2022-02-01T14:07:30.902597","exception":false,"start_time":"2022-02-01T13:47:54.523263","status":"completed"},"tags":[],"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-10-30T21:21:05.681012Z","iopub.execute_input":"2023-10-30T21:21:05.681802Z","iopub.status.idle":"2023-10-30T21:24:27.964946Z","shell.execute_reply.started":"2023-10-30T21:21:05.681767Z","shell.execute_reply":"2023-10-30T21:24:27.963963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history.history.keys()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:24:27.966988Z","iopub.execute_input":"2023-10-30T21:24:27.967613Z","iopub.status.idle":"2023-10-30T21:24:27.974286Z","shell.execute_reply.started":"2023-10-30T21:24:27.967578Z","shell.execute_reply":"2023-10-30T21:24:27.973309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_acc = ['val_bowel_bowel_binary_accuracy', 'val_extra_extra_binary_accuracy', 'val_liver_liver_cat_accuracy', 'val_kidney_kidney_cat_accuracy', 'val_spleen_spleen_cat_accuracy']","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-10-30T21:24:27.975575Z","iopub.execute_input":"2023-10-30T21:24:27.97585Z","iopub.status.idle":"2023-10-30T21:24:27.984168Z","shell.execute_reply.started":"2023-10-30T21:24:27.975827Z","shell.execute_reply":"2023-10-30T21:24:27.983267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i,j in enumerate(val_acc):\n    print(j, np.asarray(history.history[val_acc[i]])[-1].round(2))\n#np.asarray(history.history['val_bowel_bowel_binary_accuracy'])[-1].round(2)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:24:27.986275Z","iopub.execute_input":"2023-10-30T21:24:27.986601Z","iopub.status.idle":"2023-10-30T21:24:27.995085Z","shell.execute_reply.started":"2023-10-30T21:24:27.986567Z","shell.execute_reply":"2023-10-30T21:24:27.994262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in history.history.keys():\n    if i.endswith(\"_loss\") and not i ==\"val_loss\":\n        plt.plot(history.history[i], label=i)\nplt.xlabel(\"Epochs\")\nplt.ylabel(\"Loss\")\nplt.legend(loc=(1.05,0.0))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:24:27.996362Z","iopub.execute_input":"2023-10-30T21:24:27.996636Z","iopub.status.idle":"2023-10-30T21:24:28.326172Z","shell.execute_reply.started":"2023-10-30T21:24:27.996613Z","shell.execute_reply":"2023-10-30T21:24:28.325247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in history.history.keys():\n    if i.endswith(\"accuracy\") and not i ==\"val_accuracy\":\n        plt.plot(history.history[i], label=i)\nplt.xlabel(\"Epochs\")\nplt.ylabel(\"Loss\")\nplt.legend(loc=(1.05,0.0))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:24:28.327734Z","iopub.execute_input":"2023-10-30T21:24:28.328076Z","iopub.status.idle":"2023-10-30T21:24:28.708496Z","shell.execute_reply.started":"2023-10-30T21:24:28.328046Z","shell.execute_reply":"2023-10-30T21:24:28.707386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history[\"val_loss\"], label=\"val_loss\")\nplt.plot(history.history[\"loss\"], label=\"loss\")\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T21:24:28.710057Z","iopub.execute_input":"2023-10-30T21:24:28.710924Z","iopub.status.idle":"2023-10-30T21:24:28.994554Z","shell.execute_reply.started":"2023-10-30T21:24:28.710883Z","shell.execute_reply":"2023-10-30T21:24:28.993447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}