{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":52254,"databundleVersionId":8756537,"sourceType":"competition"},{"sourceId":139134997,"sourceType":"kernelVersion"},{"sourceId":139881797,"sourceType":"kernelVersion"}],"dockerImageVersionId":30528,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Abdominal Trauma UNET - Target Organ\nfrom segmentation image of target organ, predict it in CT scan images<br/> \nhttps://www.kaggle.com/code/stpeteishii/abdominal-trauma-unet","metadata":{"papermill":{"duration":0.009655,"end_time":"2023-07-11T04:08:31.528281","exception":false,"start_time":"2023-07-11T04:08:31.518626","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"images: https://www.kaggle.com/code/stpeteishii/one-patient-images-slide-show <br/>\nmasks: https://www.kaggle.com/code/stpeteishii/segmentation-image-of-the-matched-id","metadata":{}},{"cell_type":"markdown","source":"https://arxiv.org/pdf/1505.04597.pdf","metadata":{"papermill":{"duration":0.008294,"end_time":"2023-07-11T04:08:31.545451","exception":false,"start_time":"2023-07-11T04:08:31.537157","status":"completed"},"tags":[]}},{"cell_type":"code","source":"!pip install imantics --quiet","metadata":{"papermill":{"duration":15.417197,"end_time":"2023-07-11T04:08:46.970986","exception":false,"start_time":"2023-07-11T04:08:31.553789","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:02.156568Z","iopub.execute_input":"2024-09-06T13:43:02.157459Z","iopub.status.idle":"2024-09-06T13:43:16.423091Z","shell.execute_reply.started":"2024-09-06T13:43:02.157424Z","shell.execute_reply":"2024-09-06T13:43:16.421839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport cv2\nimport json\nimport random\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nimport imantics\nfrom PIL import Image\nfrom skimage.transform import resize\nfrom sklearn.model_selection import train_test_split\n%matplotlib inline","metadata":{"papermill":{"duration":8.983267,"end_time":"2023-07-11T04:08:55.963588","exception":false,"start_time":"2023-07-11T04:08:46.980321","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:16.425871Z","iopub.execute_input":"2024-09-06T13:43:16.426247Z","iopub.status.idle":"2024-09-06T13:43:25.357453Z","shell.execute_reply.started":"2024-09-06T13:43:16.426209Z","shell.execute_reply":"2024-09-06T13:43:25.35646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_dir ='/kaggle/input/one-patient-images-slide-show'\nmasks_dir = '/kaggle/input/segmentation-image-of-the-matched-id/4' # left kidney\norgans=['bowel','liver','spleen','right kidney','left kidney']","metadata":{"papermill":{"duration":0.02292,"end_time":"2023-07-11T04:08:55.996944","exception":false,"start_time":"2023-07-11T04:08:55.974024","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:25.360136Z","iopub.execute_input":"2024-09-06T13:43:25.360859Z","iopub.status.idle":"2024-09-06T13:43:25.365803Z","shell.execute_reply.started":"2024-09-06T13:43:25.360828Z","shell.execute_reply":"2024-09-06T13:43:25.364802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_listdir0 = sorted(os.listdir(images_dir))\nimages_listdir=[]\nfor i in range(len(images_listdir0)):\n    if i%4==0:\n        images_listdir+=[images_listdir0[i]]\nimages_listdir= images_listdir[50:99]\nmasks_listdir = sorted(os.listdir(masks_dir))\nN=list(range(9))\nrandom_N = N\n#np.random.choice(N, size = 9, replace = False)","metadata":{"papermill":{"duration":0.257623,"end_time":"2023-07-11T04:08:56.264361","exception":false,"start_time":"2023-07-11T04:08:56.006738","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:25.367349Z","iopub.execute_input":"2024-09-06T13:43:25.367624Z","iopub.status.idle":"2024-09-06T13:43:25.711328Z","shell.execute_reply.started":"2024-09-06T13:43:25.367599Z","shell.execute_reply":"2024-09-06T13:43:25.710619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(images_listdir))\nprint(len(masks_listdir))\n#number of images with left kidney is limited, so use all images in #4 folder. ","metadata":{"papermill":{"duration":0.027463,"end_time":"2023-07-11T04:08:56.301016","exception":false,"start_time":"2023-07-11T04:08:56.273553","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:25.713923Z","iopub.execute_input":"2024-09-06T13:43:25.714194Z","iopub.status.idle":"2024-09-06T13:43:25.718681Z","shell.execute_reply.started":"2024-09-06T13:43:25.71417Z","shell.execute_reply":"2024-09-06T13:43:25.717854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_size=512\ninput_image_size=(512,512)","metadata":{"papermill":{"duration":0.020017,"end_time":"2023-07-11T04:08:56.336291","exception":false,"start_time":"2023-07-11T04:08:56.316274","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:25.719746Z","iopub.execute_input":"2024-09-06T13:43:25.720058Z","iopub.status.idle":"2024-09-06T13:43:25.725373Z","shell.execute_reply.started":"2024-09-06T13:43:25.720027Z","shell.execute_reply":"2024-09-06T13:43:25.724442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_image(path):\n    img = cv2.imread(path)\n    img = cv2.resize(img, (image_size, image_size))\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    return img","metadata":{"papermill":{"duration":0.018858,"end_time":"2023-07-11T04:08:56.363872","exception":false,"start_time":"2023-07-11T04:08:56.345014","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:25.726574Z","iopub.execute_input":"2024-09-06T13:43:25.726903Z","iopub.status.idle":"2024-09-06T13:43:25.732403Z","shell.execute_reply.started":"2024-09-06T13:43:25.726873Z","shell.execute_reply":"2024-09-06T13:43:25.731587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"number=120","metadata":{"papermill":{"duration":0.018704,"end_time":"2023-07-11T04:08:56.391595","exception":false,"start_time":"2023-07-11T04:08:56.372891","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:25.73353Z","iopub.execute_input":"2024-09-06T13:43:25.733843Z","iopub.status.idle":"2024-09-06T13:43:25.739826Z","shell.execute_reply.started":"2024-09-06T13:43:25.733821Z","shell.execute_reply":"2024-09-06T13:43:25.738915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Input images ","metadata":{"papermill":{"duration":0.008863,"end_time":"2023-07-11T04:08:56.409542","exception":false,"start_time":"2023-07-11T04:08:56.400679","status":"completed"},"tags":[]}},{"cell_type":"code","source":"rows = 3\ncols = 3\nfig, ax = plt.subplots(rows, cols, figsize = (10,10))\nfor i, ax in enumerate(ax.flat):\n    if i < len(random_N):\n        img = read_image(f\"{images_dir}/{images_listdir[i]}\")\n        ax.set_title(f\"{images_listdir[i]}\")\n        ax.imshow(img)\n        ax.axis('off')","metadata":{"papermill":{"duration":1.818676,"end_time":"2023-07-11T04:08:58.237091","exception":false,"start_time":"2023-07-11T04:08:56.418415","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:25.740957Z","iopub.execute_input":"2024-09-06T13:43:25.741292Z","iopub.status.idle":"2024-09-06T13:43:27.186008Z","shell.execute_reply.started":"2024-09-06T13:43:25.741244Z","shell.execute_reply":"2024-09-06T13:43:27.185075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Ground truth masks","metadata":{"papermill":{"duration":0.020571,"end_time":"2023-07-11T04:08:58.277611","exception":false,"start_time":"2023-07-11T04:08:58.25704","status":"completed"},"tags":[]}},{"cell_type":"code","source":"fig, ax = plt.subplots(rows, cols, figsize = (10,10))\nfor i, ax in enumerate(ax.flat):\n    if i < len(random_N):\n        if os.path.exists(os.path.join(masks_dir,masks_listdir[i])):\n            img = read_image(f\"{masks_dir}/{masks_listdir[i]}\")\n            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n            ax.set_title(f\"{masks_listdir[i]}\")\n            ax.imshow(img)\n            ax.axis('off')\n        else:\n            print('not exist')","metadata":{"papermill":{"duration":0.905126,"end_time":"2023-07-11T04:08:59.201955","exception":false,"start_time":"2023-07-11T04:08:58.296829","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:27.18703Z","iopub.execute_input":"2024-09-06T13:43:27.187318Z","iopub.status.idle":"2024-09-06T13:43:28.278508Z","shell.execute_reply.started":"2024-09-06T13:43:27.187265Z","shell.execute_reply":"2024-09-06T13:43:28.277608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MASKS=np.zeros((1,image_size, image_size, 1), dtype=bool)\nIMAGES=np.zeros((1,image_size, image_size, 3),dtype=np.uint8)\n\nfor j,file in enumerate(images_listdir):   ##the smaller, the faster\n    try:\n        image = read_image(f\"{images_dir}/{file}\")\n        image_ex = np.expand_dims(image, axis=0)\n        IMAGES = np.vstack([IMAGES, image_ex])\n        mask = read_image(f\"{masks_dir}/{masks_listdir[j]}\") \n        mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)\n        mask = mask.reshape(512,512,1)\n        mask_ex = np.expand_dims(mask, axis=0)    \n        MASKS = np.vstack([MASKS, mask_ex])\n    except:\n        print(file)\n        continue","metadata":{"papermill":{"duration":1.160612,"end_time":"2023-07-11T04:09:00.38412","exception":false,"start_time":"2023-07-11T04:08:59.223508","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:28.279821Z","iopub.execute_input":"2024-09-06T13:43:28.280116Z","iopub.status.idle":"2024-09-06T13:43:29.436541Z","shell.execute_reply.started":"2024-09-06T13:43:28.28009Z","shell.execute_reply":"2024-09-06T13:43:29.435725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images=np.array(IMAGES)[1:number+1]\nmasks=np.array(MASKS)[1:number+1]\nprint(images.shape,masks.shape)","metadata":{"papermill":{"duration":0.042314,"end_time":"2023-07-11T04:09:00.448602","exception":false,"start_time":"2023-07-11T04:09:00.406288","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:29.437664Z","iopub.execute_input":"2024-09-06T13:43:29.437957Z","iopub.status.idle":"2024-09-06T13:43:29.460143Z","shell.execute_reply.started":"2024-09-06T13:43:29.437932Z","shell.execute_reply":"2024-09-06T13:43:29.459316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_train, images_test, masks_train, masks_test = train_test_split(\n    images, masks, test_size=0.4, random_state=42)","metadata":{"_kg_hide-input":true,"papermill":{"duration":0.040675,"end_time":"2023-07-11T04:09:00.511171","exception":false,"start_time":"2023-07-11T04:09:00.470496","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:29.461128Z","iopub.execute_input":"2024-09-06T13:43:29.461386Z","iopub.status.idle":"2024-09-06T13:43:29.483804Z","shell.execute_reply.started":"2024-09-06T13:43:29.461364Z","shell.execute_reply":"2024-09-06T13:43:29.483117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(images_train), len(masks_train))","metadata":{"papermill":{"duration":0.032989,"end_time":"2023-07-11T04:09:00.573399","exception":false,"start_time":"2023-07-11T04:09:00.54041","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:29.488032Z","iopub.execute_input":"2024-09-06T13:43:29.488318Z","iopub.status.idle":"2024-09-06T13:43:29.493308Z","shell.execute_reply.started":"2024-09-06T13:43:29.488294Z","shell.execute_reply":"2024-09-06T13:43:29.492411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# U-Net","metadata":{"papermill":{"duration":0.02079,"end_time":"2023-07-11T04:09:00.614825","exception":false,"start_time":"2023-07-11T04:09:00.594035","status":"completed"},"tags":[]}},{"cell_type":"code","source":"def conv_block(input, num_filters):\n    conv = tf.keras.layers.Conv2D(num_filters, 3, padding=\"same\")(input)\n    conv = tf.keras.layers.BatchNormalization()(conv)\n    conv = tf.keras.layers.Activation(\"relu\")(conv)\n    conv = tf.keras.layers.Conv2D(num_filters, 3, padding=\"same\")(conv)\n    conv = tf.keras.layers.BatchNormalization()(conv)\n    conv = tf.keras.layers.Activation(\"relu\")(conv)\n    return conv\n\ndef encoder_block(input, num_filters):\n    skip = conv_block(input, num_filters)\n    pool = tf.keras.layers.MaxPool2D((2,2))(skip)\n    return skip, pool\n\ndef decoder_block(input, skip, num_filters):\n    up_conv = tf.keras.layers.Conv2DTranspose(num_filters, (2,2), strides=2, padding=\"same\")(input)\n    conv = tf.keras.layers.Concatenate()([up_conv, skip])\n    conv = conv_block(conv, num_filters)\n    return conv\n\ndef Unet(input_shape):\n    inputs = tf.keras.layers.Input(input_shape)\n\n    skip1, pool1 = encoder_block(inputs, 64)\n    skip2, pool2 = encoder_block(pool1, 128)\n    skip3, pool3 = encoder_block(pool2, 256)\n    skip4, pool4 = encoder_block(pool3, 512)\n\n    bridge = conv_block(pool4, 1024)\n\n    decode1 = decoder_block(bridge, skip4, 512)\n    decode2 = decoder_block(decode1, skip3, 256)\n    decode3 = decoder_block(decode2, skip2, 128)\n    decode4 = decoder_block(decode3, skip1, 64)\n    outputs = tf.keras.layers.Conv2D(1, 1, padding=\"same\", activation=\"sigmoid\")(decode4)\n    model = tf.keras.models.Model(inputs, outputs, name=\"U-Net\")\n    return model\n\nunet_model = Unet((512,512,3))\nunet_model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])\n#unet_model.summary()","metadata":{"_kg_hide-output":true,"papermill":{"duration":3.40184,"end_time":"2023-07-11T04:09:04.037345","exception":false,"start_time":"2023-07-11T04:09:00.635505","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:29.494514Z","iopub.execute_input":"2024-09-06T13:43:29.494803Z","iopub.status.idle":"2024-09-06T13:43:33.284632Z","shell.execute_reply.started":"2024-09-06T13:43:29.494759Z","shell.execute_reply":"2024-09-06T13:43:33.283788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train\nSuitable number epoch range is narrow.","metadata":{"papermill":{"duration":0.021696,"end_time":"2023-07-11T04:09:04.081495","exception":false,"start_time":"2023-07-11T04:09:04.059799","status":"completed"},"tags":[]}},{"cell_type":"code","source":"unet_result = unet_model.fit(\n    images_train, masks_train, \n    validation_split = 0.2, batch_size = 4, epochs = 800)","metadata":{"papermill":{"duration":147.201421,"end_time":"2023-07-11T04:11:31.304006","exception":false,"start_time":"2023-07-11T04:09:04.102585","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T13:43:33.285981Z","iopub.execute_input":"2024-09-06T13:43:33.286709Z","iopub.status.idle":"2024-09-06T15:12:00.916817Z","shell.execute_reply.started":"2024-09-06T13:43:33.286674Z","shell.execute_reply":"2024-09-06T15:12:00.915767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\n# Tính trung bình độ chính xác huấn luyện và kiểm thử\navg_train_acc = np.mean(unet_result.history['accuracy'])\navg_val_acc = np.mean(unet_result.history['val_accuracy'])\n\n# In kết quả\nprint(f\"Trung bình độ chính xác huấn luyện: {avg_train_acc}\")\nprint(f\"Trung bình độ chính xác kiểm thử: {avg_val_acc}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-09-06T15:12:00.918318Z","iopub.execute_input":"2024-09-06T15:12:00.918646Z","iopub.status.idle":"2024-09-06T15:12:00.925392Z","shell.execute_reply.started":"2024-09-06T15:12:00.91862Z","shell.execute_reply":"2024-09-06T15:12:00.924537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Vẽ biểu đồ độ chính xác theo epoch\nplt.plot(unet_result.history['accuracy'], label='Huấn luyện')\nplt.plot(unet_result.history['val_accuracy'], label='Kiểm thử')\nplt.title('Độ chính xác theo Epoch')\nplt.xlabel('Epoch')\nplt.ylabel('Độ chính xác')\nplt.legend(loc='lower right')\nplt.grid(True)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-09-06T15:12:00.926684Z","iopub.execute_input":"2024-09-06T15:12:00.926948Z","iopub.status.idle":"2024-09-06T15:12:01.294008Z","shell.execute_reply.started":"2024-09-06T15:12:00.926924Z","shell.execute_reply":"2024-09-06T15:12:01.293145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Predict valid images","metadata":{"papermill":{"duration":0.058091,"end_time":"2023-07-11T04:11:31.42581","exception":false,"start_time":"2023-07-11T04:11:31.367719","status":"completed"},"tags":[]}},{"cell_type":"code","source":"def show_result(idx, og, unet, target, p):\n    \n    fig, axs = plt.subplots(1, 3, figsize=(12,12))\n    axs[0].set_title(\"Original \"+str(idx) )\n    axs[0].imshow(og)\n    axs[0].axis('off')\n    \n    axs[1].set_title(\"U-Net: p>\"+str(p))\n    axs[1].imshow(unet)\n    axs[1].axis('off')\n    \n    axs[2].set_title(\"Ground Truth\")\n    axs[2].imshow(target)\n    axs[2].axis('off')\n\n    plt.show()","metadata":{"papermill":{"duration":0.070807,"end_time":"2023-07-11T04:11:31.553458","exception":false,"start_time":"2023-07-11T04:11:31.482651","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T15:12:01.295308Z","iopub.execute_input":"2024-09-06T15:12:01.295682Z","iopub.status.idle":"2024-09-06T15:12:01.303246Z","shell.execute_reply.started":"2024-09-06T15:12:01.295646Z","shell.execute_reply":"2024-09-06T15:12:01.302188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unet_predict = unet_model.predict(images_test)","metadata":{"papermill":{"duration":5.678511,"end_time":"2023-07-11T04:11:37.295638","exception":false,"start_time":"2023-07-11T04:11:31.617127","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T15:12:01.304589Z","iopub.execute_input":"2024-09-06T15:12:01.304913Z","iopub.status.idle":"2024-09-06T15:12:46.334174Z","shell.execute_reply.started":"2024-09-06T15:12:01.304881Z","shell.execute_reply":"2024-09-06T15:12:46.333211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(images_test)","metadata":{"papermill":{"duration":0.068633,"end_time":"2023-07-11T04:11:37.422135","exception":false,"start_time":"2023-07-11T04:11:37.353502","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T15:12:46.335713Z","iopub.execute_input":"2024-09-06T15:12:46.336554Z","iopub.status.idle":"2024-09-06T15:12:46.342523Z","shell.execute_reply.started":"2024-09-06T15:12:46.336514Z","shell.execute_reply":"2024-09-06T15:12:46.341655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r1,r2,r3,r4=0.7,0.8,0.9,0.99","metadata":{"papermill":{"duration":0.066144,"end_time":"2023-07-11T04:11:37.545376","exception":false,"start_time":"2023-07-11T04:11:37.479232","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T15:12:46.343885Z","iopub.execute_input":"2024-09-06T15:12:46.344223Z","iopub.status.idle":"2024-09-06T15:12:46.350946Z","shell.execute_reply.started":"2024-09-06T15:12:46.344191Z","shell.execute_reply":"2024-09-06T15:12:46.350008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unet_predict1 = (unet_predict > r1).astype(np.uint8)\nunet_predict2 = (unet_predict > r2).astype(np.uint8)\nunet_predict3 = (unet_predict > r3).astype(np.uint8)\nunet_predict4 = (unet_predict > r4).astype(np.uint8)","metadata":{"papermill":{"duration":0.075937,"end_time":"2023-07-11T04:11:37.684847","exception":false,"start_time":"2023-07-11T04:11:37.60891","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T15:12:46.352094Z","iopub.execute_input":"2024-09-06T15:12:46.35239Z","iopub.status.idle":"2024-09-06T15:12:46.372627Z","shell.execute_reply.started":"2024-09-06T15:12:46.352365Z","shell.execute_reply":"2024-09-06T15:12:46.371688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_test_idx = random.sample(range(len(unet_predict)), 3)\nfor idx in show_test_idx: \n    show_result(idx, images_test[idx], unet_predict1[idx], masks_test[idx], r1)\n    show_result(idx, images_test[idx], unet_predict2[idx], masks_test[idx], r2)\n    show_result(idx, images_test[idx], unet_predict3[idx], masks_test[idx], r3)\n    show_result(idx, images_test[idx], unet_predict4[idx], masks_test[idx], r4)\n    print()","metadata":{"papermill":{"duration":3.719208,"end_time":"2023-07-11T04:11:41.462814","exception":false,"start_time":"2023-07-11T04:11:37.743606","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-09-06T15:12:46.373925Z","iopub.execute_input":"2024-09-06T15:12:46.374576Z","iopub.status.idle":"2024-09-06T15:12:50.886332Z","shell.execute_reply.started":"2024-09-06T15:12:46.37454Z","shell.execute_reply":"2024-09-06T15:12:50.885307Z"},"trusted":true},"execution_count":null,"outputs":[]}]}