{"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":"markdown","source":"# **Notebook Setup**","metadata":{}},{"cell_type":"code","source":"# Import statements\nimport os\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nplt.style.use(\"ggplot\")\nimport seaborn as sns\nimport tifffile\nimport cv2\nimport tensorflow as tf\nfrom keras import backend as K\nfrom tensorflow import keras\nfrom sklearn.model_selection import train_test_split\nfrom tensorflow.keras.layers import Input, concatenate, Conv2D, MaxPooling2D, UpSampling2D, Dropout, Lambda\nfrom tensorflow.keras import layers\nfrom tensorflow.keras import models\nfrom tensorflow.keras import optimizers\nfrom tensorflow.keras.layers.experimental import preprocessing","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-29T18:02:59.677194Z","iopub.execute_input":"2022-09-29T18:02:59.678090Z","iopub.status.idle":"2022-09-29T18:03:11.040988Z","shell.execute_reply.started":"2022-09-29T18:02:59.677976Z","shell.execute_reply":"2022-09-29T18:03:11.040033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create directories to call in functions\n\nBASE_DIR = \"../input/hubmap-organ-segmentation\"\nTRAIN_DIR = \"../input/hubmap-organ-segmentation/train_images\"\nTEST_DIR = \"../input/hubmap-organ-segmentation/test_images\"\nLABEL_DIR = \"../input/hubmap-organ-segmentation/train_annotations\"\n\ntrain_dir = os.listdir(TRAIN_DIR)\ntest_dir = os.listdir(TEST_DIR)","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:03:15.022711Z","iopub.execute_input":"2022-09-29T18:03:15.023374Z","iopub.status.idle":"2022-09-29T18:03:15.157210Z","shell.execute_reply.started":"2022-09-29T18:03:15.023339Z","shell.execute_reply":"2022-09-29T18:03:15.156094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Import train and test csv files into data frames\n\ntrain_path = \"../input/hubmap-organ-segmentation/train.csv\"\ntest_path = \"../input/hubmap-organ-segmentation/test.csv\"\n\ntrain_df = pd.read_csv(train_path)\ntest_df = pd.read_csv(test_path)","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:03:17.329144Z","iopub.execute_input":"2022-09-29T18:03:17.329520Z","iopub.status.idle":"2022-09-29T18:03:17.797821Z","shell.execute_reply.started":"2022-09-29T18:03:17.329489Z","shell.execute_reply":"2022-09-29T18:03:17.796904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Modified from source below these are helpful functions that will help decode and encode RLE\n# Credits: https://www.kaggle.com/code/ihelon/hubmap-exploratory-data-analysis\n\n# https://www.kaggle.com/paulorzp/rle-functions-run-lenght-encode-decode\ndef rle2mask(mask_rle, shape):\n    '''\n    mask_rle: run-length as string formated (start length)\n    shape: (width,height) of array to return \n    Returns numpy array, 1 - mask, 0 - background\n\n    '''\n    s = mask_rle.split()\n    starts, lengths = [\n        np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])\n    ]\n    starts -= 1\n    ends = starts + lengths\n    img = np.zeros(shape[0] * shape[1], dtype=np.uint8)\n    for lo, hi in zip(starts, ends):\n        img[lo : hi] = 1\n    return img.reshape(shape).T\n\n\ndef read_image(image_id, scale=None, verbose=None):\n    image = tifffile.imread(\n        os.path.join(BASE_DIR, f\"train_images/{image_id}.tiff\")\n    )\n    if len(image.shape) == 5:\n        image = image.squeeze().transpose(1, 2, 0)\n    \n    mask = rle2mask(\n        train_df[train_df[\"id\"] == image_id][\"rle\"].values[0], \n        (image.shape[1], image.shape[0])\n    )\n    \n    if verbose:\n        print(f\"[{image_id}] Image shape: {image.shape}\")\n        print(f\"[{image_id}] Mask shape: {mask.shape}\")\n    \n    if scale:\n        new_size = (256, 256)\n        image = cv2.resize(image, new_size)\n        mask = cv2.resize(mask, new_size)\n        \n        if verbose:\n            print(f\"[{image_id}] Resized Image shape: {image.shape}\")\n            print(f\"[{image_id}] Resized Mask shape: {mask.shape}\")\n        \n    return image, mask\n\n\ndef read_test_image(image_id, scale=None, verbose=None):\n    image = tifffile.imread(\n        os.path.join(BASE_DIR, f\"test_images/{image_id}.tiff\")\n    )\n    if len(image.shape) == 5:\n        image = image.squeeze().transpose(1, 2, 0)\n    \n    if verbose:\n        print(f\"[{image_id}] Image shape: {image.shape}\")\n    \n    if scale:\n        new_size = (256, 256)\n        image = cv2.resize(image, new_size)\n        \n        if verbose:\n            print(f\"[{image_id}] Resized Image shape: {image.shape}\")\n        \n    return image\n\n\ndef plot_image_and_mask(image, mask, image_id, cmap):\n    plt.figure(figsize=(16, 10))\n    \n    plt.subplot(1, 3, 1)\n    plt.imshow(image)\n    plt.grid(visible=False)\n    plt.title(f\"Image {image_id}\", fontsize=18)\n    \n    plt.subplot(1, 3, 2)\n    plt.imshow(image)\n    plt.grid(visible=False)\n    plt.imshow(mask, cmap=cmap, alpha=0.5)\n    plt.title(f\"Image {image_id} + mask\", fontsize=18)    \n    \n    plt.subplot(1, 3, 3)\n    plt.grid(visible=False)\n    plt.imshow(mask, cmap=cmap)\n    plt.title(f\"Mask\", fontsize=18)    \n\n    plt.show()\n    \n    \ndef plot_grid_image_with_mask(image, mask):\n    plt.figure(figsize=(16, 16))\n    \n    w_len = image.shape[0]\n    h_len = image.shape[1]\n    \n    min_len = min(w_len, h_len)\n    w_start = (w_len - min_len) // 2\n    h_start = (h_len - min_len) // 2\n    \n    plt.imshow(image[w_start : w_start + min_len, h_start : h_start + min_len])\n    plt.imshow(\n        mask[w_start : w_start + min_len, h_start : h_start + min_len], cmap=\"hot\", alpha=0.5,\n    )\n    plt.axis(\"off\")\n            \n    plt.show()\n    \n\ndef plot_slice_image_and_mask(image, mask, start_h, end_h, start_w, end_w, cmap):\n    plt.figure(figsize=(16, 5))\n    \n    sub_image = image[start_h:end_h, start_w:end_w, :]\n    sub_mask = mask[start_h:end_h, start_w:end_w]\n    \n    plt.subplot(1, 3, 1)\n    plt.imshow(sub_image)\n    plt.axis(\"off\")\n    \n    plt.subplot(1, 3, 2)\n    plt.imshow(sub_image)\n    plt.imshow(sub_mask, cmap=cmap, alpha=0.5)\n    plt.axis(\"off\")\n    \n    plt.subplot(1, 3, 3)\n    plt.imshow(sub_mask, cmap=cmap)\n    plt.axis(\"off\")\n    \n    plt.show()\n    \ndef rle_encode_less_memory(img):\n    #the image should be transposed\n    pixels = img.T.flatten()\n    \n    # This simplified method requires first and last pixel to be zero\n    pixels[0] = 0\n    pixels[-1] = 0\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 2\n    runs[1::2] -= runs[::2]\n    \n    return ' '.join(str(x) for x in runs)\n\n\ndef to_float(img):\n    divided_img = img/255\n    float_img = divided_img.astype(dtype = np.float32)\n    return float_img","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-09-29T18:03:20.044741Z","iopub.execute_input":"2022-09-29T18:03:20.045542Z","iopub.status.idle":"2022-09-29T18:03:20.073048Z","shell.execute_reply.started":"2022-09-29T18:03:20.045495Z","shell.execute_reply":"2022-09-29T18:03:20.072042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Data Preperation**","metadata":{}},{"cell_type":"code","source":"# Create zeroed np arrays to later store our test and train data.\n\nX_train = np.zeros((len(train_dir), 256, 256, 3), dtype=np.uint8)\nY_train = np.zeros((len(train_dir), 256, 256, 1), dtype=np.uint8)\n\nX_test = np.zeros((len(test_dir), 256, 256, 3), dtype=np.uint8)","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:03:25.505268Z","iopub.execute_input":"2022-09-29T18:03:25.506186Z","iopub.status.idle":"2022-09-29T18:03:25.513957Z","shell.execute_reply.started":"2022-09-29T18:03:25.506137Z","shell.execute_reply":"2022-09-29T18:03:25.512649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Take train images from dir and import them into np.arrays \n\nfor i, name in enumerate(train_dir):\n    s_name = name[slice(-5)]\n    s_name = int(s_name)\n    image, mask = read_image(s_name, scale = True)\n    img_segment_full = np.zeros((256, 256, 1), dtype=np.uint8)\n    img_segment = np.expand_dims(mask, axis=-1)\n    img_segment_full = np.maximum(img_segment_full, img_segment)\n    X_train[i] = image\n    Y_train[i] = img_segment_full","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:03:28.284446Z","iopub.execute_input":"2022-09-29T18:03:28.284857Z","iopub.status.idle":"2022-09-29T18:05:33.001885Z","shell.execute_reply.started":"2022-09-29T18:03:28.284824Z","shell.execute_reply":"2022-09-29T18:05:32.999882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Take test images from dir and import them into np.arrays \nId_store = []\nfor i, name in enumerate(test_dir):\n# take name of slice from test dir and make it into an array to make submission easier\n    s_name = name[slice(-5)]\n    s_name = int(s_name)\n    Id_store.append(s_name)\n# read images from the test dir and store them in our np test array\n    image = read_test_image(s_name, scale = True)\n    X_test[i] = image","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:06:07.359617Z","iopub.execute_input":"2022-09-29T18:06:07.360150Z","iopub.status.idle":"2022-09-29T18:06:07.762797Z","shell.execute_reply.started":"2022-09-29T18:06:07.360103Z","shell.execute_reply":"2022-09-29T18:06:07.761287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check to make sure images are stored properly in arrays\nplt.figure(figsize=(15, 32))\nplt.subplot(1,3,1)\nplt.imshow(X_train[3])\nplt.title('Original image')\nplt.subplot(1,3,2)\nplt.imshow(Y_train[3])\nplt.title('Predicted image')","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:06:10.386869Z","iopub.execute_input":"2022-09-29T18:06:10.387314Z","iopub.status.idle":"2022-09-29T18:06:10.837569Z","shell.execute_reply.started":"2022-09-29T18:06:10.387273Z","shell.execute_reply":"2022-09-29T18:06:10.836342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert the training dataset to float32, you have to do this because the loss funtions and metrics will not accept uint8\nnew_train = np.zeros((len(train_dir), 256, 256, 3), dtype=np.float32)\nnew_y = np.zeros((len(train_dir), 256, 256, 1), dtype=np.float32)\n\n\nfor i, name in enumerate(X_train):\n    new_img = X_train[i]/255\n    new_train[i] = new_img\n    \nfor i, name in enumerate(Y_train):\n    new_img = Y_train[i]/255\n    new_y[i] = new_img    \n\nprint(new_y.shape)","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:06:14.703740Z","iopub.execute_input":"2022-09-29T18:06:14.704944Z","iopub.status.idle":"2022-09-29T18:06:15.156307Z","shell.execute_reply.started":"2022-09-29T18:06:14.704888Z","shell.execute_reply":"2022-09-29T18:06:15.154991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_test = np.zeros((len(test_dir), 256, 256, 3), dtype=np.float32)\n\nfor i, name in enumerate(X_test):\n    new_img = X_test[i]/255\n    new_test[i] = new_img  ","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:56:28.068506Z","iopub.execute_input":"2022-09-29T18:56:28.068995Z","iopub.status.idle":"2022-09-29T18:56:28.076921Z","shell.execute_reply.started":"2022-09-29T18:56:28.068955Z","shell.execute_reply":"2022-09-29T18:56:28.075311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Confirm conversion to float32 did not degrade images\nplt.figure(figsize=(15, 32))\nplt.subplot(1,3,1)\nplt.imshow(new_train[3])\nplt.subplot(1,3,2)\nplt.imshow(new_y[3])","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:57:06.767557Z","iopub.execute_input":"2022-09-29T18:57:06.768040Z","iopub.status.idle":"2022-09-29T18:57:07.152754Z","shell.execute_reply.started":"2022-09-29T18:57:06.768002Z","shell.execute_reply":"2022-09-29T18:57:07.151394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Split training data into training and validation data\n\ntrain, val, y_train, y_val = train_test_split(new_train, new_y, test_size=0.2)","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:06:26.980626Z","iopub.execute_input":"2022-09-29T18:06:26.981446Z","iopub.status.idle":"2022-09-29T18:06:27.135878Z","shell.execute_reply.started":"2022-09-29T18:06:26.981406Z","shell.execute_reply":"2022-09-29T18:06:27.134766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define custom loss functions and metrics taken from notebook linked below\n# Credit: https://www.kaggle.com/code/maxitype/6-u-net-custom-iou-beginner\n\ndef iou(y_true, y_pred):\n    intersection = K.sum(K.abs(y_true * y_pred), axis=[1,2,3])\n    union = K.sum(y_true, axis=[1,2,3]) + K.sum(y_pred, axis=[1,2,3]) - intersection\n    iou = K.mean((intersection + 1) / (union + 1), axis=0)\n    return iou\n\ndef mean_iou(y_true, y_pred):\n    results = []   \n    for t in np.arange(0.5, 1, 0.05):\n        t_y_pred = tf.cast((y_pred > t), tf.float32)\n        pred = iou(y_true, t_y_pred)\n        results.append(pred)\n        \n    return K.mean(K.stack(results), axis=0)\n\n\ndef dice_loss(y_true, y_pred):\n    intersection = K.sum(K.abs(y_true * y_pred), axis=[1,2,3])\n    union = K.sum(y_true, axis=[1,2,3]) + K.sum(y_pred, axis=[1,2,3])\n    dice = K.mean((2. * intersection + 1) / (union + 1), axis=0)\n    return 1. - dice","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:06:29.649823Z","iopub.execute_input":"2022-09-29T18:06:29.650253Z","iopub.status.idle":"2022-09-29T18:06:29.662324Z","shell.execute_reply.started":"2022-09-29T18:06:29.650212Z","shell.execute_reply":"2022-09-29T18:06:29.660766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Model Creation**\n\nThis is a U-net model by [Ronneberger et al](https://arxiv.org/abs/1505.04597). \n\nCode was abopted from: https://www.kaggle.com/code/maxitype/6-u-net-custom-iou-beginner","metadata":{}},{"cell_type":"code","source":"inputs = Input((256, 256, 3))\ns = tf.keras.layers.Lambda(lambda x: x/255.0)(inputs)\n\nconv1 = Conv2D(32, (3, 3), activation='relu', padding='same')(inputs)\nconv1 = Conv2D(32, (3, 3), activation='relu', padding='same')(conv1)\npool1 = MaxPooling2D(pool_size=(2, 2))(conv1)\n\nconv2 = Conv2D(64, (3, 3), activation='relu', padding='same')(pool1)\nconv2 = Conv2D(64, (3, 3), activation='relu', padding='same')(conv2)\npool2 = MaxPooling2D(pool_size=(2, 2))(conv2)\n\nconv3 = Conv2D(128, (3, 3), activation='relu', padding='same')(pool2)\nconv3 = Conv2D(128, (3, 3), activation='relu', padding='same')(conv3)\npool3 = MaxPooling2D(pool_size=(2, 2))(conv3)\n\nconv4 = Conv2D(256, (3, 3), activation='relu', padding='same')(pool3)\nconv4 = Conv2D(256, (3, 3), activation='relu', padding='same')(conv4)\npool4 = MaxPooling2D(pool_size=(2, 2))(conv4)\n\nconv5 = Conv2D(512, (3, 3), activation='relu', padding='same')(pool4)\nconv5 = Conv2D(512, (3, 3), activation='relu', padding='same')(conv5)\nconv5 = Conv2D(512, (3, 3), activation='relu', padding='same')(conv5)\n\nup6 = UpSampling2D(size=(2,2))(conv5)\nup6 = concatenate([up6, conv4])\nconv6 = Conv2D(256, (3, 3), activation='relu', padding='same')(up6)\nconv6 = Conv2D(256, (3, 3), activation='relu', padding='same')(conv6)\n\nup7 = UpSampling2D(size=(2,2))(conv6)\nup7 = concatenate([up7, conv3])\nconv7 = Conv2D(128, (3, 3), activation='relu', padding='same')(up7)\nconv7 = Conv2D(128, (3, 3), activation='relu', padding='same')(conv7)\n\nup8 = UpSampling2D(size=(2,2))(conv7)\nup8 = concatenate([up8, conv2])\nconv8 = Conv2D(64, (3, 3), activation='relu', padding='same')(up8)\nconv8 = Conv2D(64, (3, 3), activation='relu', padding='same')(conv8)\n\nup9 = UpSampling2D(size=(2,2))(conv8)\nup9 = concatenate([up9, conv1])\nconv9 = Conv2D(32, (3, 3), activation='relu', padding='same')(up9)\nconv9 = Conv2D(32, (3, 3), activation='relu', padding='same')(conv9)\n\nconv10 = Conv2D(1, (1, 1), activation='sigmoid')(conv9)\n\nmodel = models.Model(inputs=[inputs], outputs=[conv10])\n\nmodel.compile(optimizer=optimizers.Adam(learning_rate=2e-4), loss= dice_loss, metrics= mean_iou)\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:06:32.918656Z","iopub.execute_input":"2022-09-29T18:06:32.919932Z","iopub.status.idle":"2022-09-29T18:06:33.415310Z","shell.execute_reply.started":"2022-09-29T18:06:32.919885Z","shell.execute_reply":"2022-09-29T18:06:33.414353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Model Training**","metadata":{}},{"cell_type":"code","source":"history = model.fit(x= train, y = y_train,\n                    steps_per_epoch=len(train)/8,\n                    validation_data= (val, y_val),\n                    validation_steps=len(val)/8,\n                    epochs=5\n                   )","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:06:40.718421Z","iopub.execute_input":"2022-09-29T18:06:40.719446Z","iopub.status.idle":"2022-09-29T18:31:16.400109Z","shell.execute_reply.started":"2022-09-29T18:06:40.719407Z","shell.execute_reply":"2022-09-29T18:31:16.399029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_frame = pd.DataFrame(history.history)\nhistory_frame.loc[:, ['loss', 'val_loss']].plot()\nhistory_frame.loc[:, ['mean_iou', 'val_mean_iou']].plot();","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:45:51.592575Z","iopub.execute_input":"2022-09-29T18:45:51.593087Z","iopub.status.idle":"2022-09-29T18:45:52.074412Z","shell.execute_reply.started":"2022-09-29T18:45:51.593048Z","shell.execute_reply":"2022-09-29T18:45:52.073066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Model Prediction and Data Preperation for Submission**","metadata":{}},{"cell_type":"code","source":"test_predict = model.predict(new_test, verbose =1)","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:57:15.432600Z","iopub.execute_input":"2022-09-29T18:57:15.433035Z","iopub.status.idle":"2022-09-29T18:57:15.919302Z","shell.execute_reply.started":"2022-09-29T18:57:15.432996Z","shell.execute_reply":"2022-09-29T18:57:15.918120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 32))\nplt.subplot(1,3,1)\nplt.imshow(new_test[0])\nplt.title('Original image')\nplt.subplot(1,3,2)\nplt.imshow(np.squeeze(test_predict[0]))\nplt.title('Predicted image')","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:58:05.442686Z","iopub.execute_input":"2022-09-29T18:58:05.443416Z","iopub.status.idle":"2022-09-29T18:58:05.805817Z","shell.execute_reply.started":"2022-09-29T18:58:05.443374Z","shell.execute_reply":"2022-09-29T18:58:05.804418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# threshold the value of the prediction pixel to reduce noise in the predicted image. \npred_rle = []\nfor i in range(len(test_predict)):\n    squeeze_img = test_predict[i]\n    threshold = 0.5\n    threshold_img = np.where(squeeze_img < threshold, 0, 1)\n    pred_rle.append(rle_encode_less_memory(threshold_img))","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:58:10.947203Z","iopub.execute_input":"2022-09-29T18:58:10.948269Z","iopub.status.idle":"2022-09-29T18:58:10.958402Z","shell.execute_reply.started":"2022-09-29T18:58:10.948206Z","shell.execute_reply":"2022-09-29T18:58:10.957066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# visualize the results of my model\nplt.figure(figsize=(15, 32))\nplt.subplot(1,3,1)\nplt.imshow(X_test[0])\nplt.title('Original image')\nplt.subplot(1,3,2)\nplt.imshow(threshold_img)\nplt.title('Predicted image')","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:58:13.348053Z","iopub.execute_input":"2022-09-29T18:58:13.348463Z","iopub.status.idle":"2022-09-29T18:58:13.711006Z","shell.execute_reply.started":"2022-09-29T18:58:13.348430Z","shell.execute_reply":"2022-09-29T18:58:13.709939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are clearly some issues with this model, as there are no predicted pixels. \n\nAreas of improvement: \n1. Build a simple model from scratch in order to quickly iterate what works and what doesn't. \n2. Try a different prebuilt model that will better adapt to the segmentation in these images.\n3. I'll want to check the sucessful submission for potential pitfalls that I missed when creating this submission. \n4. I need to figure out why I have zero predictided pixels when I switch my loss function from binary cross entropy to dice loss. Also, this likely contributes to my loss function plateauing. ","metadata":{}},{"cell_type":"code","source":"# Store data in a df and convert the df to a csv file for submission\ndf = pd.DataFrame({'id':Id_store,'rle':pred_rle})\ndf.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-09-29T18:58:23.609833Z","iopub.execute_input":"2022-09-29T18:58:23.611261Z","iopub.status.idle":"2022-09-29T18:58:23.620943Z","shell.execute_reply.started":"2022-09-29T18:58:23.611200Z","shell.execute_reply":"2022-09-29T18:58:23.619399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}