{"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":"!pip install split-folders tqdm","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:49:46.495589Z","iopub.execute_input":"2021-05-20T09:49:46.495983Z","iopub.status.idle":"2021-05-20T09:49:53.919010Z","shell.execute_reply.started":"2021-05-20T09:49:46.495879Z","shell.execute_reply":"2021-05-20T09:49:53.918057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport math\nimport cv2\nimport shutil\nimport numpy as np\nimport pandas as pd\nimport skimage.io\nfrom PIL import Image\nfrom tqdm.notebook import tqdm\nimport zipfile\nimport tifffile\nimport matplotlib.pyplot as plt\nimport matplotlib.image as img\nimport splitfolders","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:49:57.126094Z","iopub.execute_input":"2021-05-20T09:49:57.126429Z","iopub.status.idle":"2021-05-20T09:49:57.788352Z","shell.execute_reply.started":"2021-05-20T09:49:57.126398Z","shell.execute_reply":"2021-05-20T09:49:57.787548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# making output directories\n\nos.mkdir('./Images')\nos.mkdir('./Masks')","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:50:00.295243Z","iopub.execute_input":"2021-05-20T09:50:00.295641Z","iopub.status.idle":"2021-05-20T09:50:00.301337Z","shell.execute_reply.started":"2021-05-20T09:50:00.295601Z","shell.execute_reply":"2021-05-20T09:50:00.300362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"splitfolders.ratio(\"../input/copy-of-iafoss-dataset-256x256/train\", output=\"./Images\", seed=1337, ratio=(.8, .1, .1), group_prefix=None)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:50:02.675636Z","iopub.execute_input":"2021-05-20T09:50:02.675972Z","iopub.status.idle":"2021-05-20T09:50:47.518018Z","shell.execute_reply.started":"2021-05-20T09:50:02.675943Z","shell.execute_reply":"2021-05-20T09:50:47.516280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"splitfolders.ratio(\"../input/copy-of-iafoss-dataset-256x256/masks\", output=\"./Masks\", seed=1337, ratio=(.8, .1, .1), group_prefix=None)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-05-20T09:51:19.477699Z","iopub.execute_input":"2021-05-20T09:51:19.478043Z","iopub.status.idle":"2021-05-20T09:51:49.592230Z","shell.execute_reply.started":"2021-05-20T09:51:19.478011Z","shell.execute_reply":"2021-05-20T09:51:49.591211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir('./Images/')","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:52:16.738379Z","iopub.execute_input":"2021-05-20T09:52:16.738760Z","iopub.status.idle":"2021-05-20T09:52:16.749947Z","shell.execute_reply.started":"2021-05-20T09:52:16.738724Z","shell.execute_reply":"2021-05-20T09:52:16.748625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nlist = os.listdir('./Images/train/Images_01') # dir is your directory path\nnumber_files1 = len(list)\nprint(number_files1)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:52:18.853326Z","iopub.execute_input":"2021-05-20T09:52:18.853647Z","iopub.status.idle":"2021-05-20T09:52:18.864242Z","shell.execute_reply.started":"2021-05-20T09:52:18.853618Z","shell.execute_reply":"2021-05-20T09:52:18.863228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install git+https://github.com/qubvel/segmentation_models","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:52:21.213238Z","iopub.execute_input":"2021-05-20T09:52:21.213608Z","iopub.status.idle":"2021-05-20T09:52:29.903050Z","shell.execute_reply.started":"2021-05-20T09:52:21.213576Z","shell.execute_reply":"2021-05-20T09:52:29.902054Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%env SM_FRAMEWORK=tf.keras\n\nimport keras\nimport tensorflow as tf\nfrom segmentation_models import Unet\nfrom segmentation_models import get_preprocessing\nfrom segmentation_models.losses import bce_jaccard_loss\nfrom segmentation_models.losses import dice_loss\nfrom segmentation_models.metrics import iou_score\nfrom sklearn.model_selection import train_test_split\nfrom keras.optimizers import Adam\nfrom tensorflow.keras.losses import binary_crossentropy\nfrom keras.models import model_from_json\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras import layers\nfrom tensorflow.keras.callbacks import LearningRateScheduler\n\nfrom keras.layers import Input, Conv2D, Reshape\nfrom keras.models import Model\nfrom keras import backend as K","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:09.385910Z","iopub.execute_input":"2021-05-20T09:53:09.386940Z","iopub.status.idle":"2021-05-20T09:53:15.403365Z","shell.execute_reply.started":"2021-05-20T09:53:09.386863Z","shell.execute_reply":"2021-05-20T09:53:15.402331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Preprocessing 'train_images' for segmentation model\n\nBACKBONE = 'resnet34'\npreprocess_input = get_preprocessing(BACKBONE)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:18.077276Z","iopub.execute_input":"2021-05-20T09:53:18.077590Z","iopub.status.idle":"2021-05-20T09:53:18.082021Z","shell.execute_reply.started":"2021-05-20T09:53:18.077563Z","shell.execute_reply":"2021-05-20T09:53:18.080838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_gen_args = dict(\n#     featurewise_center=True,\n#                      featurewise_std_normalization=True,\n                     rotation_range=90,\n                     width_shift_range=0.1,\n                     height_shift_range=0.1,\n                     zoom_range=0.2)\n\nimage_datagen = preprocess_input(ImageDataGenerator(**data_gen_args))\nmask_datagen = preprocess_input(ImageDataGenerator(**data_gen_args))","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:20.510538Z","iopub.execute_input":"2021-05-20T09:53:20.510984Z","iopub.status.idle":"2021-05-20T09:53:20.516535Z","shell.execute_reply.started":"2021-05-20T09:53:20.510940Z","shell.execute_reply":"2021-05-20T09:53:20.515644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Provide the same seed and keyword arguments to the fit and flow methods\nseed = 1","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:22.769628Z","iopub.execute_input":"2021-05-20T09:53:22.770010Z","iopub.status.idle":"2021-05-20T09:53:22.776199Z","shell.execute_reply.started":"2021-05-20T09:53:22.769967Z","shell.execute_reply":"2021-05-20T09:53:22.775322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_generator = image_datagen.flow_from_directory(\n    './Images/train',\n    class_mode=None,\n    batch_size=32,\n    seed=seed)\ntrain_mask_generator = mask_datagen.flow_from_directory(\n    './Masks/train',\n    class_mode=None,\n    batch_size=32,\n    seed=seed)\n\n# combine generators into one which yields image and masks\ntrain_generator = zip(train_image_generator, train_mask_generator)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:24.741461Z","iopub.execute_input":"2021-05-20T09:53:24.741811Z","iopub.status.idle":"2021-05-20T09:53:25.380301Z","shell.execute_reply.started":"2021-05-20T09:53:24.741781Z","shell.execute_reply":"2021-05-20T09:53:25.379226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"validation_image_generator = image_datagen.flow_from_directory(\n    './Images/val',\n    class_mode=None,\n    batch_size=32,\n    seed=seed)\nvalidation_mask_generator = mask_datagen.flow_from_directory(\n    './Masks/val',\n    class_mode=None,\n    batch_size=32,\n    seed=seed)\n\n# combine generators into one which yields image and masks\nvalidation_generator = zip(validation_image_generator, validation_mask_generator)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:28.212860Z","iopub.execute_input":"2021-05-20T09:53:28.213216Z","iopub.status.idle":"2021-05-20T09:53:28.426563Z","shell.execute_reply.started":"2021-05-20T09:53:28.213186Z","shell.execute_reply":"2021-05-20T09:53:28.425630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Model Building using U-net (old)\n\nfrom keras.layers import Reshape\n\n# create the base pre-trained model\nbase_model = Unet(backbone_name='resnet34', encoder_weights='imagenet')\n\n# add a layer with defined input shape\ninput_base_model = Input(shape=(256, 256, 3))\n\n# # add a convolution layer with input data\nl1 = Conv2D(3, (1, 1))(input_base_model)\n\n# defining output layer shape\nout = base_model(l1)\n\nmodel = Model(input_base_model , out , name=base_model.name)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:32.068038Z","iopub.execute_input":"2021-05-20T09:53:32.068427Z","iopub.status.idle":"2021-05-20T09:53:37.810371Z","shell.execute_reply.started":"2021-05-20T09:53:32.068397Z","shell.execute_reply":"2021-05-20T09:53:37.809584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Model Building using U-net (updated)\n\nfrom keras.layers import Reshape\n\n# create the base pre-trained model\nbase_model = Unet(backbone_name='resnet34', encoder_weights='imagenet')\n\n# add a layer with defined input shape\ninput_base_model = Input(shape=(256, 256, 3))\n\n# add a convolution layer with input data\nl1 = Conv2D(3, (1, 1))(input_base_model)\n\n# defining output layer shape\nout = base_model(l1)\n\nout_1 = Conv2D(3, (1, 1) , activation=\"sigmoid\")(out)\nmodel = Model(input_base_model, out_1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:40.717292Z","iopub.execute_input":"2021-05-20T09:53:40.717625Z","iopub.status.idle":"2021-05-20T09:53:40.734745Z","shell.execute_reply.started":"2021-05-20T09:53:40.717587Z","shell.execute_reply":"2021-05-20T09:53:40.733713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# callbacks\n\nlr_schedule = keras.callbacks.LearningRateScheduler(lambda epoch: 1e-4 * 10**(epoch / 10))\n\nlr_check = keras.callbacks.ReduceLROnPlateau(patience = 4)\n\nearly_stopping = keras.callbacks.EarlyStopping(patience=8 , verbose = 1)\n\nmodel_checkpoint = keras.callbacks.ModelCheckpoint(\n                   '/kaggle/working/best_cnn.h5', \n                   save_best_only=True)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:43.477805Z","iopub.execute_input":"2021-05-20T09:53:43.478168Z","iopub.status.idle":"2021-05-20T09:53:43.483953Z","shell.execute_reply.started":"2021-05-20T09:53:43.478136Z","shell.execute_reply":"2021-05-20T09:53:43.482916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optimizer = keras.optimizers.Adam(learning_rate=0.0001, amsgrad=False)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:46.042529Z","iopub.execute_input":"2021-05-20T09:53:46.042873Z","iopub.status.idle":"2021-05-20T09:53:46.052775Z","shell.execute_reply.started":"2021-05-20T09:53:46.042840Z","shell.execute_reply":"2021-05-20T09:53:46.051318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Defining metrics\n\ndef dice_coefficient(y_true, y_pred):\n    numerator = 2 * tf.reduce_sum(y_true * y_pred)\n    denominator = tf.reduce_sum(y_true + y_pred)\n    return numerator / (denominator + tf.keras.backend.epsilon())","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:47.799256Z","iopub.execute_input":"2021-05-20T09:53:47.799639Z","iopub.status.idle":"2021-05-20T09:53:47.804836Z","shell.execute_reply.started":"2021-05-20T09:53:47.799605Z","shell.execute_reply":"2021-05-20T09:53:47.803569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Model Compiling\n\nmodel.compile(optimizer = optimizer, loss=dice_loss, metrics=[dice_coefficient])","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:50.175742Z","iopub.execute_input":"2021-05-20T09:53:50.176102Z","iopub.status.idle":"2021-05-20T09:53:50.198396Z","shell.execute_reply.started":"2021-05-20T09:53:50.176072Z","shell.execute_reply":"2021-05-20T09:53:50.197374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.test.is_gpu_available()","metadata":{"execution":{"iopub.status.busy":"2021-05-20T09:53:52.535274Z","iopub.execute_input":"2021-05-20T09:53:52.535617Z","iopub.status.idle":"2021-05-20T09:53:52.547033Z","shell.execute_reply.started":"2021-05-20T09:53:52.535587Z","shell.execute_reply":"2021-05-20T09:53:52.546133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Fit model\n\nhistory = model.fit(train_generator,steps_per_epoch = 32,\n                                  epochs=50, \n                                  validation_data=validation_generator,\n                                  validation_steps = 8,\n                                  callbacks=[lr_check, early_stopping, model_checkpoint]\n                                 )","metadata":{"execution":{"iopub.status.busy":"2021-05-20T10:03:03.875908Z","iopub.execute_input":"2021-05-20T10:03:03.876336Z","iopub.status.idle":"2021-05-20T10:33:14.384730Z","shell.execute_reply.started":"2021-05-20T10:03:03.876299Z","shell.execute_reply":"2021-05-20T10:33:14.383968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Fit model in order to determine best learning rate \n\nhistory = model.fit(train_generator,steps_per_epoch = 32,\n                                  epochs=3\n                                 )","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dice_coefficient = history.history['dice_coefficient']\nval_dice_coefficient = history.history['val_dice_coefficient']\n\ntrain_loss = history.history['loss']\nval_loss = history.history['val_loss']","metadata":{"execution":{"iopub.status.busy":"2021-05-20T10:33:57.587094Z","iopub.execute_input":"2021-05-20T10:33:57.587426Z","iopub.status.idle":"2021-05-20T10:33:57.593736Z","shell.execute_reply.started":"2021-05-20T10:33:57.587397Z","shell.execute_reply":"2021-05-20T10:33:57.592724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nplt.figure(figsize=(20, 10))\n\nplt.subplot(1, 2, 1)\nplt.plot(dice_coefficient, label='Dice coefficient')\nplt.plot(val_dice_coefficient, label='Validation Dice coefficient')\nplt.legend()\nplt.xlabel('Epochs')\nplt.title('Epochs vs. Training and Validation Dice coefficient')\n    \nplt.subplot(1, 2, 2)\nplt.plot(train_loss, label='Training Loss')\nplt.plot(val_loss, label='Validation Loss')\nplt.legend()\nplt.xlabel('Epochs')\nplt.title('Epochs vs. Training and Validation Loss')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-05-20T10:33:59.583269Z","iopub.execute_input":"2021-05-20T10:33:59.583612Z","iopub.status.idle":"2021-05-20T10:33:59.972870Z","shell.execute_reply.started":"2021-05-20T10:33:59.583583Z","shell.execute_reply":"2021-05-20T10:33:59.971810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image_datagen = preprocess_input(ImageDataGenerator())\ntest_mask_datagen = preprocess_input(ImageDataGenerator())","metadata":{"execution":{"iopub.status.busy":"2021-05-20T10:34:18.588500Z","iopub.execute_input":"2021-05-20T10:34:18.588854Z","iopub.status.idle":"2021-05-20T10:34:18.595808Z","shell.execute_reply.started":"2021-05-20T10:34:18.588823Z","shell.execute_reply":"2021-05-20T10:34:18.594702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image_generator = test_image_datagen.flow_from_directory(\n    './Images/test',\n    class_mode=None,\n    seed=seed)\ntest_mask_generator = test_mask_datagen.flow_from_directory(\n    './Masks/test',\n    class_mode=None,\n    seed=seed)\n\ntest_generator = zip (test_image_generator , test_mask_generator)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T10:34:21.882204Z","iopub.execute_input":"2021-05-20T10:34:21.882541Z","iopub.status.idle":"2021-05-20T10:34:22.096337Z","shell.execute_reply.started":"2021-05-20T10:34:21.882509Z","shell.execute_reply":"2021-05-20T10:34:22.095473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(test_generator)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Predicting using the model\n\npredictt = model.predict(test_image_generator)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T10:34:26.472692Z","iopub.execute_input":"2021-05-20T10:34:26.473152Z","iopub.status.idle":"2021-05-20T10:34:31.592839Z","shell.execute_reply.started":"2021-05-20T10:34:26.473107Z","shell.execute_reply":"2021-05-20T10:34:31.591744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image_generator.filenames[1]","metadata":{"execution":{"iopub.status.busy":"2021-05-20T11:28:18.043381Z","iopub.execute_input":"2021-05-20T11:28:18.043709Z","iopub.status.idle":"2021-05-20T11:28:18.048992Z","shell.execute_reply.started":"2021-05-20T11:28:18.043679Z","shell.execute_reply":"2021-05-20T11:28:18.048160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image[44]","metadata":{"execution":{"iopub.status.busy":"2021-05-20T11:53:11.434320Z","iopub.execute_input":"2021-05-20T11:53:11.434649Z","iopub.status.idle":"2021-05-20T11:53:11.440185Z","shell.execute_reply.started":"2021-05-20T11:53:11.434617Z","shell.execute_reply":"2021-05-20T11:53:11.439207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir('./Images/test/Images_01/')[45]","metadata":{"execution":{"iopub.status.busy":"2021-05-20T11:56:46.453314Z","iopub.execute_input":"2021-05-20T11:56:46.453786Z","iopub.status.idle":"2021-05-20T11:56:46.464345Z","shell.execute_reply.started":"2021-05-20T11:56:46.453737Z","shell.execute_reply":"2021-05-20T11:56:46.463115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Generating image 9th image using matplotlib\n\ntest_image = sorted(os.listdir('./Images/test/Images_01/'))\ntest_mask =  sorted(os.listdir('./Masks/test/Images_01/'))\n# reading png image file\n\nim = img.imread('./Images/test/Images_01/4ef6695ce_1568.png')\nmk = img.imread('./Masks/test/Images_01/4ef6695ce_1568.png')\n  \n# show image\n# # plt.figure(figsize=(5,5))\nplt.imshow(im)\nplt.imshow(mk , cmap='coolwarm', alpha=0.5)\n","metadata":{"execution":{"iopub.status.busy":"2021-05-20T11:56:52.101189Z","iopub.execute_input":"2021-05-20T11:56:52.101533Z","iopub.status.idle":"2021-05-20T11:56:52.287321Z","shell.execute_reply.started":"2021-05-20T11:56:52.101504Z","shell.execute_reply":"2021-05-20T11:56:52.286470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_1_predict = np.asarray(predictt[45])\nplt.imshow(image_1_predict)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T11:52:19.604505Z","iopub.execute_input":"2021-05-20T11:52:19.604865Z","iopub.status.idle":"2021-05-20T11:52:20.150527Z","shell.execute_reply.started":"2021-05-20T11:52:19.604831Z","shell.execute_reply":"2021-05-20T11:52:20.149627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(0,955):\n    image_1_predict = np.asarray(predictt[i])\n    plt.figure()\n    plt.imshow(image_1_predict)\n    plt.show()\n\n# plt.figure(figsize=(5,5))\n\nplt.imshow(image_1_predict)","metadata":{"execution":{"iopub.status.busy":"2021-05-20T11:58:47.009327Z","iopub.execute_input":"2021-05-20T11:58:47.009678Z","iopub.status.idle":"2021-05-20T12:01:00.570378Z","shell.execute_reply.started":"2021-05-20T11:58:47.009647Z","shell.execute_reply":"2021-05-20T12:01:00.569332Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def create_mask(pred_mask):\n  pred_mask = tf.argmax(pred_mask, axis=-1)\n  pred_mask = pred_mask[..., tf.newaxis]\n  return pred_mask[0]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_predictions(image, mask, num=1):\n  if image:\n    for image, mask in zip(image,mask):\n      pred_mask = model.predict(image)\n      display([image[0], mask[0], create_mask(pred_mask)])\n  else:\n    display([sample_image, sample_mask,\n             create_mask(model.predict(sample_image[tf.newaxis, ...]))])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_predictions(test_image_generator,test_mask_generator , 3)[0]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.metrics_names","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dir(history)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history.history","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot Learning Rate vs. Loss\n\nplt.plot(history.epoch, history.history['loss'])\n# plt.axis([1e-4, 1e-1, 0, 4])\nplt.xlabel('Epochs')\nplt.ylabel('Training Loss')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-05-20T12:18:41.173551Z","iopub.execute_input":"2021-05-20T12:18:41.174066Z","iopub.status.idle":"2021-05-20T12:18:41.395847Z","shell.execute_reply.started":"2021-05-20T12:18:41.174021Z","shell.execute_reply":"2021-05-20T12:18:41.394989Z"},"trusted":true},"execution_count":null,"outputs":[]}]}