{"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":"Author : Aadya Aneesh Chinubhai \n\nKey Steps :\nBuild U-Net Class,\nDefine Activation function candidates,\nCompare Accuracy & Training time.","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport tensorflow as tf\nfrom tensorflow.keras import backend as K\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Dropout, Conv2DTranspose, concatenate\nfrom tensorflow.keras.models import Model\nfrom keras import metrics\nimport keras\nimport os\nimport random\nfrom tqdm import tqdm \nfrom zipfile import ZipFile\nfrom skimage.io import imread, imshow\nfrom skimage.transform import resize\nimport matplotlib.pyplot as plt\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:01:19.525444Z","iopub.execute_input":"2023-04-15T11:01:19.526106Z","iopub.status.idle":"2023-04-15T11:01:19.537737Z","shell.execute_reply.started":"2023-04-15T11:01:19.526011Z","shell.execute_reply":"2023-04-15T11:01:19.535511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class UNet:\n    \n    def __init__(self, input_shape_,  activation_ = \"relu\"):\n        self.activation = activation_\n        self.input_shape = input_shape_\n    \n    def dice_coef(self, y_true, y_pred, smooth=100):\n        y_true = tf.cast(y_true, tf.float32)\n        y_pred = tf.cast(y_pred, tf.float32)\n        \n        y_true_f = K.flatten(y_true)\n        y_pred_f = K.flatten(y_pred)\n        intersection = K.sum(y_true_f * y_pred_f)\n        dice = (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)\n        return dice\n    \n    def dice_coef_loss(self, y_true, y_pred):\n        return -self.dice_coef(y_true, y_pred)\n    \n    def iou(self, y_true, y_pred):\n        y_true = tf.cast(y_true, tf.float32)\n        y_pred = tf.cast(y_pred, tf.float32)\n\n        def f(y_true, y_pred):\n            intersection = (y_true * y_pred).sum()\n            union = y_true.sum() + y_pred.sum() - intersection\n            x = (intersection + 1e-15) / (union + 1e-15)\n            x = x.astype(np.float32)\n            return x\n        \n        return tf.numpy_function(f, [y_true, y_pred], tf.float32)\n\n    def buildModel(self):\n        \n        # Lets create the DownSampling Blocks \n        kernel_initializer =  'he_uniform'\n         \n        inputs = tf.keras.Input(shape = self.input_shape)\n        \n        # Block - 1\n    \n        s = inputs\n\n        #Contraction path\n        c1 = Conv2D(16, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(s)\n#         c1 = Dropout(0.1)(c1)\n        c1 = Conv2D(16, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c1)\n        p1 = MaxPooling2D((2, 2))(c1)\n\n        c2 = Conv2D(32, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(p1)\n#         c2 = Dropout(0.1)(c2)\n        c2 = Conv2D(32, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c2)\n        p2 = MaxPooling2D((2, 2))(c2)\n\n        c3 = Conv2D(64, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(p2)\n#         c3 = Dropout(0.2)(c3)\n        c3 = Conv2D(64, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c3)\n        p3 = MaxPooling2D((2, 2))(c3)\n\n        c4 = Conv2D(128, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(p3)\n#         c4 = Dropout(0.2)(c4)\n        c4 = Conv2D(128, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c4)\n        p4 = MaxPooling2D(pool_size=(2, 2))(c4)\n\n        c5 = Conv2D(256, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(p4)\n#         c5 = Dropout(0.3)(c5)\n        c5 = Conv2D(256, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c5)\n\n        #Expansive path \n        u6 = Conv2DTranspose(128, (2, 2), strides=(2, 2), padding='same')(c5)\n        u6 = concatenate([u6, c4])\n        c6 = Conv2D(128, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(u6)\n#         c6 = Dropout(0.2)(c6)\n        c6 = Conv2D(128, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c6)\n\n        u7 = Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same')(c6)\n        u7 = concatenate([u7, c3])\n        c7 = Conv2D(64, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(u7)\n#         c7 = Dropout(0.2)(c7)\n        c7 = Conv2D(64, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c7)\n\n        u8 = Conv2DTranspose(32, (2, 2), strides=(2, 2), padding='same')(c7)\n        u8 = concatenate([u8, c2])\n        c8 = Conv2D(32, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(u8)\n#         c8 = Dropout(0.1)(c8)\n        c8 = Conv2D(32, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c8)\n\n        u9 = Conv2DTranspose(16, (2, 2), strides=(2, 2), padding='same')(c8)\n        u9 = concatenate([u9, c1])\n        c9 = Conv2D(16, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(u9)\n#         c9 = Dropout(0.1)(c9)\n        c9 = Conv2D(16, (3, 3), activation= self.activation, kernel_initializer=kernel_initializer, padding='same')(c9)\n\n        outputs = Conv2D(1, (1, 1), activation='sigmoid')(c9)\n\n        model = Model(inputs=[inputs], outputs=[outputs])\n        #compile model outside of this function to make it flexible. \n        model.summary()\n\n        return model\n \n    \n    def CompileandSummarize(self, model_):\n        model_.compile(optimizer = tf.keras.optimizers.Adam(), loss = self.dice_coef_loss, metrics = self.iou)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:01:19.553423Z","iopub.execute_input":"2023-04-15T11:01:19.554242Z","iopub.status.idle":"2023-04-15T11:01:19.600793Z","shell.execute_reply.started":"2023-04-15T11:01:19.554155Z","shell.execute_reply":"2023-04-15T11:01:19.598876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''Defining callbacks to calculate training time '''\n\nfrom timeit import default_timer as timer\n\nclass TimingCallback(keras.callbacks.Callback):\n    def __init__(self, logs={}):\n        self.logs=[]\n    def on_epoch_begin(self, epoch, logs={}):\n        self.starttime = timer()\n    def on_epoch_end(self, epoch, logs={}):\n        self.logs.append(timer()-self.starttime)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:01:19.606153Z","iopub.execute_input":"2023-04-15T11:01:19.609278Z","iopub.status.idle":"2023-04-15T11:01:19.623218Z","shell.execute_reply.started":"2023-04-15T11:01:19.608967Z","shell.execute_reply":"2023-04-15T11:01:19.620649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Now lets focus on preparing the data\n\nwith ZipFile(\"../input/data-science-bowl-2018/stage1_train.zip\",\"r\") as zip_ref:\n    zip_ref.extractall(\"./stage1_train\")\n    \nwith ZipFile(\"../input/data-science-bowl-2018/stage1_test.zip\",\"r\") as zip_ref:\n    zip_ref.extractall(\"./stage1_test\")    ","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:01:19.628025Z","iopub.execute_input":"2023-04-15T11:01:19.630120Z","iopub.status.idle":"2023-04-15T11:01:26.048979Z","shell.execute_reply.started":"2023-04-15T11:01:19.629995Z","shell.execute_reply":"2023-04-15T11:01:26.047999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"seed = 42\nnp.random.seed = seed\n\nIMG_WIDTH = 96\nIMG_HEIGHT = 96\nIMG_CHANNELS = 3\n\nTRAIN_PATH = './stage1_train/'\nTEST_PATH = './stage1_test/'","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:01:26.050279Z","iopub.execute_input":"2023-04-15T11:01:26.051110Z","iopub.status.idle":"2023-04-15T11:01:26.057019Z","shell.execute_reply.started":"2023-04-15T11:01:26.051071Z","shell.execute_reply":"2023-04-15T11:01:26.055993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ids = next(os.walk(TRAIN_PATH))[1]\ntest_ids = next(os.walk(TEST_PATH))[1]\n\ntrain_ids[:5]","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:01:26.060695Z","iopub.execute_input":"2023-04-15T11:01:26.061420Z","iopub.status.idle":"2023-04-15T11:01:26.070797Z","shell.execute_reply.started":"2023-04-15T11:01:26.061385Z","shell.execute_reply":"2023-04-15T11:01:26.069753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = np.zeros((len(train_ids), IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS), dtype=np.uint8)\nY_train = np.zeros((len(train_ids), IMG_HEIGHT, IMG_WIDTH, 1), dtype=np.bool)\n\nprint('Resizing training images and masks')\nfor n, file_name in tqdm(enumerate(train_ids)):   \n    path = TRAIN_PATH + file_name\n    img = imread(path + '/images/' + file_name + '.png')[:,:,:IMG_CHANNELS]  \n    img = resize(img, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)\n    X_train[n] = img  #Fill empty X_train with values from img\n    mask = np.zeros((IMG_HEIGHT, IMG_WIDTH, 1), dtype=np.bool)\n    for mask_file in next(os.walk(path + '/masks/'))[2]:\n        mask_ = imread(path + '/masks/' + mask_file)\n        mask_ = np.expand_dims(resize(mask_, (IMG_HEIGHT, IMG_WIDTH), mode='constant',  \n                                      preserve_range=True), axis=-1)\n        mask = np.maximum(mask, mask_)  \n            \n    Y_train[n] = mask","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:01:26.072532Z","iopub.execute_input":"2023-04-15T11:01:26.073057Z","iopub.status.idle":"2023-04-15T11:06:05.261411Z","shell.execute_reply.started":"2023-04-15T11:01:26.073002Z","shell.execute_reply":"2023-04-15T11:06:05.260374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 5% Validation Images (34 Images)\nX_test, y_test  = X_train[536:], Y_train[536:]\nX_train, Y_train = X_train[0: 536], Y_train[0:536]","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.263259Z","iopub.execute_input":"2023-04-15T11:06:05.263988Z","iopub.status.idle":"2023-04-15T11:06:05.269601Z","shell.execute_reply.started":"2023-04-15T11:06:05.263929Z","shell.execute_reply":"2023-04-15T11:06:05.268493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(X_train.shape, Y_train.shape), (X_test.shape, y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.271326Z","iopub.execute_input":"2023-04-15T11:06:05.271695Z","iopub.status.idle":"2023-04-15T11:06:05.282231Z","shell.execute_reply.started":"2023-04-15T11:06:05.271659Z","shell.execute_reply":"2023-04-15T11:06:05.281055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_x = random.randint(0, 636)\nimshow(X_train[image_x])\nplt.show()\nimshow(np.squeeze(Y_train[image_x]))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.283921Z","iopub.execute_input":"2023-04-15T11:06:05.284415Z","iopub.status.idle":"2023-04-15T11:06:05.894395Z","shell.execute_reply.started":"2023-04-15T11:06:05.284375Z","shell.execute_reply":"2023-04-15T11:06:05.893502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class MexicanReLU(tf.keras.layers.Layer):\n    def __init__(self, alpha=1.0, sigma=1.0, mu=0.0):\n        super(MexicanReLU, self).__init__()\n        self.alpha = tf.Variable(alpha, trainable=True)\n        self.sigma = tf.Variable(sigma, trainable=True)\n        self.mu = tf.Variable(mu, trainable=True)\n\n    def call(self, inputs):\n        relu = tf.nn.relu(inputs)\n        gaussian = self.alpha * tf.exp(-tf.square(inputs - self.mu) / (2 * tf.square(self.sigma))) * (inputs - self.mu)\n        return relu + gaussian\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.895888Z","iopub.execute_input":"2023-04-15T11:06:05.896303Z","iopub.status.idle":"2023-04-15T11:06:05.903960Z","shell.execute_reply.started":"2023-04-15T11:06:05.896268Z","shell.execute_reply":"2023-04-15T11:06:05.902927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# class SymmetricGaLU(tf.keras.layers.Layer):\n#     def __init__(self, **kwargs):\n#         super(SymmetricGaLU, self).__init__(**kwargs)\n\n#     def call(self, x):\n#         a, b = tf.split(x, 2, axis=-1)\n#         return tf.multiply(tf.nn.tanh(a), tf.nn.sigmoid(b))\n\n#     def get_config(self):\n#         config = super(SymmetricGaLU, self).get_config()\n#         return config\n\nclass Gelu(tf.keras.layers.Layer):\n    def __init__(self):\n        super(Gelu, self).__init__()\n\n    def call(self, inputs):\n        cdf = 0.5 * (1.0 + tf.math.erf(inputs / tf.sqrt(2.0)))\n        return inputs * cdf\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.905635Z","iopub.execute_input":"2023-04-15T11:06:05.906335Z","iopub.status.idle":"2023-04-15T11:06:05.913531Z","shell.execute_reply.started":"2023-04-15T11:06:05.906297Z","shell.execute_reply":"2023-04-15T11:06:05.912922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Swish(tf.keras.layers.Layer):\n    def __init__(self):\n        super(Swish, self).__init__()\n\n    def call(self, inputs):\n        return inputs * tf.keras.backend.sigmoid(inputs)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.914864Z","iopub.execute_input":"2023-04-15T11:06:05.915516Z","iopub.status.idle":"2023-04-15T11:06:05.926918Z","shell.execute_reply.started":"2023-04-15T11:06:05.915483Z","shell.execute_reply":"2023-04-15T11:06:05.926087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class TrainableLeakyReLU(tf.keras.layers.Layer):\n    def __init__(self, alpha_initializer=tf.initializers.constant(0.2), **kwargs):\n        super(TrainableLeakyReLU, self).__init__(**kwargs)\n        self.alpha_initializer = tf.keras.initializers.get(alpha_initializer)\n    \n    def build(self, input_shape):\n        self.alpha = self.add_weight(shape=(), initializer=self.alpha_initializer, trainable=True, name=\"alpha\")\n        super(TrainableLeakyReLU, self).build(input_shape)\n    \n    def call(self, inputs):\n        return tf.maximum(inputs, self.alpha * inputs)\n    \n    def get_config(self):\n        config = super(TrainableLeakyReLU, self).get_config()\n        config.update({\"alpha_initializer\": self.alpha_initializer})\n        return config","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.928528Z","iopub.execute_input":"2023-04-15T11:06:05.928889Z","iopub.status.idle":"2023-04-15T11:06:05.938100Z","shell.execute_reply.started":"2023-04-15T11:06:05.928857Z","shell.execute_reply":"2023-04-15T11:06:05.937097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class ISRU(tf.keras.layers.Layer):\n    def __init__(self, alpha=1.0, **kwargs):\n        super(ISRU, self).__init__(**kwargs)\n        self.alpha = tf.Variable(initial_value=alpha, trainable=True, name='alpha')\n\n    def call(self, inputs):\n        return inputs / tf.sqrt(1.0 + self.alpha * tf.square(inputs))\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.943997Z","iopub.execute_input":"2023-04-15T11:06:05.944311Z","iopub.status.idle":"2023-04-15T11:06:05.950798Z","shell.execute_reply.started":"2023-04-15T11:06:05.944287Z","shell.execute_reply":"2023-04-15T11:06:05.949280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Mish(tf.keras.layers.Layer):\n    def __init__(self, **kwargs):\n        super(Mish, self).__init__(**kwargs)\n\n    def call(self, inputs):\n        return inputs * tf.math.tanh(tf.math.softplus(inputs))\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.952726Z","iopub.execute_input":"2023-04-15T11:06:05.953787Z","iopub.status.idle":"2023-04-15T11:06:05.960169Z","shell.execute_reply.started":"2023-04-15T11:06:05.953749Z","shell.execute_reply":"2023-04-15T11:06:05.959216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.layers import Layer\n\nclass gated_swish(Layer):\n    \n    def __init__(self):\n        super(gated_swish, self).__init__()\n\n    def call(self, inputs):\n\n        \"\"\"\n        Gated Swish activation function.\n        \"\"\"\n        gate = tf.math.sigmoid(inputs)\n        activation = tf.nn.swish(inputs)\n        \n        return gate * activation","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.961743Z","iopub.execute_input":"2023-04-15T11:06:05.962211Z","iopub.status.idle":"2023-04-15T11:06:05.974645Z","shell.execute_reply.started":"2023-04-15T11:06:05.962179Z","shell.execute_reply":"2023-04-15T11:06:05.973709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class SeLU(tf.keras.layers.Layer):\n    def __init__(self, alpha=1.6732632423543772848170429916717, scale=1.0507009873554804934193349852946, **kwargs):\n        super().__init__(**kwargs)\n        self.alpha = alpha\n        self.scale = scale\n\n    def call(self, inputs):\n        return self.scale * tf.where(inputs > 0.0, inputs, self.alpha * tf.exp(inputs) - self.alpha)\n\n    def get_config(self):\n        config = super().get_config()\n        config.update({'alpha': self.alpha, 'scale': self.scale})\n        return config\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.976138Z","iopub.execute_input":"2023-04-15T11:06:05.976555Z","iopub.status.idle":"2023-04-15T11:06:05.985955Z","shell.execute_reply.started":"2023-04-15T11:06:05.976523Z","shell.execute_reply":"2023-04-15T11:06:05.985081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\n\nclass LearnableSwish(tf.keras.layers.Layer):\n    def __init__(self, **kwargs):\n        super(LearnableSwish, self).__init__(**kwargs)\n\n    def build(self, input_shape):\n        self.beta = self.add_weight(shape=(1, ), initializer=\"ones\", trainable=True)\n        super(LearnableSwish, self).build(input_shape)\n\n    def call(self, inputs):\n        return tf.nn.swish(inputs * self.beta)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.987415Z","iopub.execute_input":"2023-04-15T11:06:05.987811Z","iopub.status.idle":"2023-04-15T11:06:05.996089Z","shell.execute_reply.started":"2023-04-15T11:06:05.987779Z","shell.execute_reply":"2023-04-15T11:06:05.995100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class SRS(tf.keras.layers.Layer):\n    def __init__(self, alpha=1.0, **kwargs):\n        super(SRS, self).__init__(**kwargs)\n        self.alpha = alpha\n\n    def call(self, inputs):\n        return tf.maximum(inputs, self.alpha * (tf.sigmoid(inputs) - 0.5))\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:05.997380Z","iopub.execute_input":"2023-04-15T11:06:05.997901Z","iopub.status.idle":"2023-04-15T11:06:06.006488Z","shell.execute_reply.started":"2023-04-15T11:06:05.997868Z","shell.execute_reply":"2023-04-15T11:06:06.005416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class TanELU(tf.keras.layers.Layer):\n    def __init__(self, alpha=1.0, **kwargs):\n        super(TanELU, self).__init__(**kwargs)\n        self.alpha = alpha\n\n    def call(self, inputs):\n        pos = tf.nn.relu(inputs)\n        neg = self.alpha * (tf.exp(inputs) - 1)\n        return tf.where(inputs > 0, tf.tanh(pos), tf.tanh(neg))","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:06.007502Z","iopub.execute_input":"2023-04-15T11:06:06.007739Z","iopub.status.idle":"2023-04-15T11:06:06.016820Z","shell.execute_reply.started":"2023-04-15T11:06:06.007717Z","shell.execute_reply":"2023-04-15T11:06:06.016073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !mkdir /kaggle/working/logs","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:06.017898Z","iopub.execute_input":"2023-04-15T11:06:06.018583Z","iopub.status.idle":"2023-04-15T11:06:06.029454Z","shell.execute_reply.started":"2023-04-15T11:06:06.018549Z","shell.execute_reply":"2023-04-15T11:06:06.028723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tb_1 = tf.keras.callbacks.TensorBoard(log_dir='/kaggle/working/logs', profile_batch=(5, 8))","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:06.030618Z","iopub.execute_input":"2023-04-15T11:06:06.031581Z","iopub.status.idle":"2023-04-15T11:06:06.275140Z","shell.execute_reply.started":"2023-04-15T11:06:06.031548Z","shell.execute_reply":"2023-04-15T11:06:06.274190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_inferences={}","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:06.276936Z","iopub.execute_input":"2023-04-15T11:06:06.277374Z","iopub.status.idle":"2023-04-15T11:06:06.281715Z","shell.execute_reply.started":"2023-04-15T11:06:06.277337Z","shell.execute_reply":"2023-04-15T11:06:06.280770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet_1 = UNet((96, 96, 3), activation_= MexicanReLU())\nmodel1 = UNet_1.buildModel()\nUNet_1.CompileandSummarize(model1)\nresults1 = model1.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150, callbacks = [cb,tb_1],  validation_data = (X_test, y_test))\n\ntraining_inferences['MexicanReLU'] = sum(cb.logs)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:06:06.283470Z","iopub.execute_input":"2023-04-15T11:06:06.284176Z","iopub.status.idle":"2023-04-15T11:09:31.619979Z","shell.execute_reply.started":"2023-04-15T11:06:06.284142Z","shell.execute_reply":"2023-04-15T11:09:31.618930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_inferences","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:09:31.621744Z","iopub.execute_input":"2023-04-15T11:09:31.622235Z","iopub.status.idle":"2023-04-15T11:09:31.629239Z","shell.execute_reply.started":"2023-04-15T11:09:31.622185Z","shell.execute_reply":"2023-04-15T11:09:31.628086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet_2 = UNet((96, 96, 3), activation_= Swish())\nmodel2 = UNet_2.buildModel()\nUNet_2.CompileandSummarize(model2)\nresults2 = model2.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150, callbacks = [cb,tb_1],  validation_data = (X_test, y_test))\n\ntraining_inferences['Swish'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:09:31.630859Z","iopub.execute_input":"2023-04-15T11:09:31.631479Z","iopub.status.idle":"2023-04-15T11:12:55.409325Z","shell.execute_reply.started":"2023-04-15T11:09:31.631434Z","shell.execute_reply":"2023-04-15T11:12:55.408338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet_3 = UNet((96, 96, 3), activation_= TrainableLeakyReLU())\nmodel3 = UNet_3.buildModel()\nUNet_3.CompileandSummarize(model3)\nresults3 = model3.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150, callbacks = [cb,tb_1], validation_data = (X_test, y_test))\n\ntraining_inferences['TrainableLeakyReLU'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:12:55.411249Z","iopub.execute_input":"2023-04-15T11:12:55.411650Z","iopub.status.idle":"2023-04-15T11:16:19.656436Z","shell.execute_reply.started":"2023-04-15T11:12:55.411613Z","shell.execute_reply":"2023-04-15T11:16:19.655424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_inferences","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:16:19.658106Z","iopub.execute_input":"2023-04-15T11:16:19.658500Z","iopub.status.idle":"2023-04-15T11:16:19.666397Z","shell.execute_reply.started":"2023-04-15T11:16:19.658462Z","shell.execute_reply":"2023-04-15T11:16:19.664571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet_4 = UNet((96, 96, 3), activation_= ISRU())\nmodel4 = UNet_4.buildModel()\nUNet_4.CompileandSummarize(model4)\nresults4 = model4.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150,callbacks = [cb,tb_1], validation_data = (X_test, y_test))\n\ntraining_inferences['ISRU'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:16:19.668086Z","iopub.execute_input":"2023-04-15T11:16:19.669172Z","iopub.status.idle":"2023-04-15T11:19:06.162136Z","shell.execute_reply.started":"2023-04-15T11:16:19.669113Z","shell.execute_reply":"2023-04-15T11:19:06.161165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet_5 = UNet((96, 96, 3), activation_= Mish())\nmodel5 = UNet_5.buildModel()\nUNet_5.CompileandSummarize(model5)\nresults5 = model5.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150, callbacks = [cb,tb_1], validation_data = (X_test, y_test))\n\ntraining_inferences['Mish'] = sum(cb.logs)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:19:06.163501Z","iopub.execute_input":"2023-04-15T11:19:06.164350Z","iopub.status.idle":"2023-04-15T11:22:30.061467Z","shell.execute_reply.started":"2023-04-15T11:19:06.164309Z","shell.execute_reply":"2023-04-15T11:22:30.060436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet_6 = UNet((96, 96, 3), activation_= gated_swish())\nmodel6 = UNet_6.buildModel()\nUNet_6.CompileandSummarize(model6)\nresults6 = model6.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150,callbacks = [cb,tb_1], validation_data = (X_test, y_test))\n\ntraining_inferences['gated_swish'] = sum(cb.logs)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:22:30.062959Z","iopub.execute_input":"2023-04-15T11:22:30.063573Z","iopub.status.idle":"2023-04-15T11:25:54.451991Z","shell.execute_reply.started":"2023-04-15T11:22:30.063536Z","shell.execute_reply":"2023-04-15T11:25:54.450954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet__ = UNet((96, 96, 3), activation_= \"relu\")\nmodel_ = UNet__.buildModel()\nUNet__.CompileandSummarize(model_)\nresults_ = model5.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150, callbacks = [cb,tb_1], validation_data = (X_test, y_test))\n\ntraining_inferences['relu'] = sum(cb.logs)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:25:54.453677Z","iopub.execute_input":"2023-04-15T11:25:54.454261Z","iopub.status.idle":"2023-04-15T11:29:16.756671Z","shell.execute_reply.started":"2023-04-15T11:25:54.454221Z","shell.execute_reply":"2023-04-15T11:29:16.755634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet_ls = UNet((96, 96, 3), activation_= LearnableSwish())\nmodells = UNet_ls.buildModel()\nUNet_ls.CompileandSummarize(modells)\nresultsls = modells.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150, callbacks = [cb,tb_1], validation_data = (X_test, y_test))\n\ntraining_inferences['LearnableSwish'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:29:16.758357Z","iopub.execute_input":"2023-04-15T11:29:16.758872Z","iopub.status.idle":"2023-04-15T11:32:41.180439Z","shell.execute_reply.started":"2023-04-15T11:29:16.758833Z","shell.execute_reply":"2023-04-15T11:32:41.179366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cb = TimingCallback()\n\nUNet_srs = UNet((96, 96, 3), activation_= SRS())\nmodelsrs = UNet_srs.buildModel()\nUNet_srs.CompileandSummarize(modelsrs)\nresultssrs = modells.fit(x = X_train, y = Y_train, batch_size = 8, epochs=150, callbacks = [cb,tb_1], validation_data = (X_test, y_test))\n\ntraining_inferences['SRS'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:32:41.181865Z","iopub.execute_input":"2023-04-15T11:32:41.183085Z","iopub.status.idle":"2023-04-15T11:36:03.592974Z","shell.execute_reply.started":"2023-04-15T11:32:41.183016Z","shell.execute_reply":"2023-04-15T11:36:03.592011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_inferences","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:36:03.594745Z","iopub.execute_input":"2023-04-15T11:36:03.595417Z","iopub.status.idle":"2023-04-15T11:36:03.608295Z","shell.execute_reply.started":"2023-04-15T11:36:03.595381Z","shell.execute_reply":"2023-04-15T11:36:03.607328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = []\ny = []\n\nfor i in training_inferences:\n    x.append(i)\n    y.append(training_inferences[i])","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:36:03.609466Z","iopub.execute_input":"2023-04-15T11:36:03.610532Z","iopub.status.idle":"2023-04-15T11:36:03.619260Z","shell.execute_reply.started":"2023-04-15T11:36:03.610493Z","shell.execute_reply":"2023-04-15T11:36:03.618234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#'Comparision of training times in different activation functions\nfig, ax = plt.subplots()\nplt.bar(range(len(y)), y, tick_label=x)\nplt.xticks(rotation='vertical')\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:36:03.620801Z","iopub.execute_input":"2023-04-15T11:36:03.621506Z","iopub.status.idle":"2023-04-15T11:36:03.934190Z","shell.execute_reply.started":"2023-04-15T11:36:03.621473Z","shell.execute_reply":"2023-04-15T11:36:03.933334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\n\n\n# Create a figure with 2 rows and 4 columns of subplots\nfig, axs = plt.subplots(nrows=3, ncols=3, figsize=(12, 8))\n\n# Plot the data on the subplots\naxs[0, 0].plot(results1.history['loss'])\naxs[0, 1].plot(results2.history['loss'])\naxs[0, 2].plot(results3.history['loss'])\naxs[1, 0].plot(results4.history['loss'])\naxs[1, 1].plot(results5.history['loss'])\naxs[1, 2].plot(results6.history['loss'])\naxs[2, 0].plot(results_.history['loss'])\naxs[2, 1].plot(resultsls.history['loss'])\naxs[2,2].plot(resultssrs.history['loss'])\n\n# Add titles to the subplots\naxs[0, 0].set_title('Mexican_Relu')\naxs[0, 1].set_title('Swish')\naxs[0, 2].set_title('TrainableLeakyReLU')\naxs[1, 0].set_title('ISRU')\naxs[1, 1].set_title('Mish')\naxs[1, 2].set_title('Gated_Swish')\naxs[2, 0].set_title('ReLu')\naxs[2, 1].set_title('LearnableSwish')\naxs[2, 2].set_title('SRS')\n\n# Add x and y axis labels\nfor ax in axs.flat:\n    ax.set(xlabel='Epoch', ylabel='Loss')\n\n# Add a main title to the figure\nfig.suptitle('8 Subplots')\n\n# Adjust the spacing between subplots\nfig.tight_layout()\n\n# Display the figure\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:36:53.951790Z","iopub.execute_input":"2023-04-15T11:36:53.952530Z","iopub.status.idle":"2023-04-15T11:36:55.049559Z","shell.execute_reply.started":"2023-04-15T11:36:53.952482Z","shell.execute_reply":"2023-04-15T11:36:55.048448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\n\n\n# Create a figure with 2 rows and 4 columns of subplots\nfig, axs = plt.subplots(nrows=3, ncols=3, figsize=(12, 8))\n\n# Plot the data on the subplots\naxs[0, 0].plot(results1.history['val_loss'])\naxs[0, 1].plot(results2.history['val_loss'])\naxs[0, 2].plot(results3.history['val_loss'])\naxs[1, 0].plot(results4.history['val_loss'])\naxs[1, 1].plot(results5.history['val_loss'])\naxs[1, 2].plot(results6.history['val_loss'])\naxs[2, 0].plot(results_.history['val_loss'])\naxs[2, 1].plot(resultsls.history['val_loss'])\naxs[2,2].plot(resultssrs.history['val_loss'])\n\n# Add titles to the subplots\naxs[0, 0].set_title('Mexican_Relu')\naxs[0, 1].set_title('Swish')\naxs[0, 2].set_title('TrainableLeakyReLU')\naxs[1, 0].set_title('ISRU')\naxs[1, 1].set_title('Mish')\naxs[1, 2].set_title('Gated_Swish')\naxs[2, 0].set_title('ReLu')\naxs[2, 1].set_title('LearnableSwish')\naxs[2, 2].set_title('SRS')\n\n# Add x and y axis labels\nfor ax in axs.flat:\n    ax.set(xlabel='Epoch', ylabel='Val_Loss')\n\n# Add a main title to the figure\nfig.suptitle('8 Subplots')\n\n# Adjust the spacing between subplots\nfig.tight_layout()\n\n# Display the figure\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:43:12.160901Z","iopub.execute_input":"2023-04-15T11:43:12.161489Z","iopub.status.idle":"2023-04-15T11:43:13.146432Z","shell.execute_reply.started":"2023-04-15T11:43:12.161454Z","shell.execute_reply":"2023-04-15T11:43:13.145389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\n# Assuming 'x' is your input tensor with shape (32, 96, 3)\nbatch_size = X_test.shape[0]  # Get the batch size\nheight, width, channels = 96, 96, 3  # Set the height, width, and channels\n\n# Reshape the input tensor to match the expected shape\nX_test_reshaped = np.reshape(X_test, (batch_size, height, width, channels))\n\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:51:22.664392Z","iopub.execute_input":"2023-04-15T11:51:22.664761Z","iopub.status.idle":"2023-04-15T11:51:22.670361Z","shell.execute_reply.started":"2023-04-15T11:51:22.664730Z","shell.execute_reply":"2023-04-15T11:51:22.669338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#MexicanRelu","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model1.predict(X_test_reshaped)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T11:53:16.619693Z","iopub.execute_input":"2023-04-15T11:53:16.620071Z","iopub.status.idle":"2023-04-15T11:53:17.433808Z","shell.execute_reply.started":"2023-04-15T11:53:16.620017Z","shell.execute_reply":"2023-04-15T11:53:17.432819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_classes = np.argmax(y_pred, axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:05:06.595142Z","iopub.execute_input":"2023-04-15T12:05:06.595516Z","iopub.status.idle":"2023-04-15T12:05:06.603339Z","shell.execute_reply.started":"2023-04-15T12:05:06.595486Z","shell.execute_reply":"2023-04-15T12:05:06.602088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# Assuming you have already made predictions on your test data and you have the predicted masks in a variable y_pred\n\n# Choose a random image from the test set to plot\nindex = 10 # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:33:41.259579Z","iopub.execute_input":"2023-04-15T12:33:41.259936Z","iopub.status.idle":"2023-04-15T12:33:41.716474Z","shell.execute_reply.started":"2023-04-15T12:33:41.259904Z","shell.execute_reply":"2023-04-15T12:33:41.715389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Swish\ny_pred2=model2.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred2, axis=1)\n# Assuming you have already made predictions on your test data and you have the predicted masks in a variable y_pred\n\n# Choose a random image from the test set to plot\nindex = 10  # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred2[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:10:22.036275Z","iopub.execute_input":"2023-04-15T12:10:22.036630Z","iopub.status.idle":"2023-04-15T12:10:22.740968Z","shell.execute_reply.started":"2023-04-15T12:10:22.036600Z","shell.execute_reply":"2023-04-15T12:10:22.739946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#TrainableLekyRelu\ny_pred3=model3.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred3, axis=1)\n# Assuming you have already made predictions on your test data and you have the predicted masks in a variable y_pred\n\n# Choose a random image from the test set to plot\nindex = 10  # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred3[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:11:40.602733Z","iopub.execute_input":"2023-04-15T12:11:40.603119Z","iopub.status.idle":"2023-04-15T12:11:41.310174Z","shell.execute_reply.started":"2023-04-15T12:11:40.603083Z","shell.execute_reply":"2023-04-15T12:11:41.308970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#ISRU\ny_pred4=model4.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred4, axis=1)\n# Assuming you have already made predictions on your test data and you have the predicted masks in a variable y_pred\n\n# Choose a random image from the test set to plot\nindex = 10  # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred4[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:12:12.800003Z","iopub.execute_input":"2023-04-15T12:12:12.801046Z","iopub.status.idle":"2023-04-15T12:12:13.649873Z","shell.execute_reply.started":"2023-04-15T12:12:12.800994Z","shell.execute_reply":"2023-04-15T12:12:13.648943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Mish\ny_pred5=model5.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred5, axis=1)\n# Assuming you have already made predictions on your test data and you have the predicted masks in a variable y_pred\n\n# Choose a random image from the test set to plot\nindex = 10  # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred5[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:13:08.054207Z","iopub.execute_input":"2023-04-15T12:13:08.054861Z","iopub.status.idle":"2023-04-15T12:13:08.770059Z","shell.execute_reply.started":"2023-04-15T12:13:08.054825Z","shell.execute_reply":"2023-04-15T12:13:08.769158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Gated Swish\ny_pred6=model6.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred6, axis=1)\n# Choose a random image from the test set to plot\nindex = 10  # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred6[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:13:37.348648Z","iopub.execute_input":"2023-04-15T12:13:37.349043Z","iopub.status.idle":"2023-04-15T12:13:37.796878Z","shell.execute_reply.started":"2023-04-15T12:13:37.348995Z","shell.execute_reply":"2023-04-15T12:13:37.795947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#relu\ny_pred7=model_.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred7, axis=1)\n# Choose a random image from the test set to plot\nindex = 10  # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred7[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:30:08.319642Z","iopub.execute_input":"2023-04-15T12:30:08.320131Z","iopub.status.idle":"2023-04-15T12:30:09.033856Z","shell.execute_reply.started":"2023-04-15T12:30:08.320089Z","shell.execute_reply":"2023-04-15T12:30:09.032938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Learnable Swish\ny_pred8=modells.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred8, axis=1)\n# Choose a random image from the test set to plot\nindex = 10  # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred8[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:30:55.500729Z","iopub.execute_input":"2023-04-15T12:30:55.501126Z","iopub.status.idle":"2023-04-15T12:30:56.376330Z","shell.execute_reply.started":"2023-04-15T12:30:55.501093Z","shell.execute_reply":"2023-04-15T12:30:56.375283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#SRS\ny_pred9=modelsrs.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred9, axis=1)\n# Choose a random image from the test set to plot\nindex = 10  # Change this to the index of the image you want to plot\nimage = X_test[index]  # Get the original image data\nmask_true = y_test[index]  # Get the true mask for the image\nmask_pred = y_pred9[index]  # Get the predicted mask for the image\n\n# Create a subplot with three columns to plot the original image, true mask and predicted mask side by side\nfig, ax = plt.subplots(1, 3, figsize=(15, 5))\n\n# Plot the original image in the first column\nax[0].imshow(image)\nax[0].set_title(\"Original Image\")\n\n# Plot the true mask in the second column\nax[1].imshow(mask_true, cmap='gray')\nax[1].set_title(\"True Mask\")\n\n# Plot the predicted mask in the third column\nax[2].imshow(mask_pred, cmap='gray')\nax[2].set_title(\"Predicted Mask\")\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-15T12:31:26.381497Z","iopub.execute_input":"2023-04-15T12:31:26.381861Z","iopub.status.idle":"2023-04-15T12:31:27.226057Z","shell.execute_reply.started":"2023-04-15T12:31:26.381829Z","shell.execute_reply":"2023-04-15T12:31:27.224881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}