{"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:Razin Karimi*<br>\nLearnings: UNet, Activaton functions, Segmentation\n","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-06-03T13:29:37.108028Z","iopub.execute_input":"2023-06-03T13:29:37.111343Z","iopub.status.idle":"2023-06-03T13:29:37.175265Z","shell.execute_reply.started":"2023-06-03T13:29:37.111243Z","shell.execute_reply":"2023-06-03T13:29:37.174003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import models,layers,datasets\n\nimport 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-06-03T13:29:37.177236Z","iopub.execute_input":"2023-06-03T13:29:37.177596Z","iopub.status.idle":"2023-06-03T13:29:47.509672Z","shell.execute_reply.started":"2023-06-03T13:29:37.177560Z","shell.execute_reply":"2023-06-03T13:29:47.508445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class UNet:\n    def __init__(self,input_shape_,activation_=\"relu\"):\n        self.input_shape=input_shape_\n        self.activation=activation_\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        \n        intersection=K.sum(y_true_f*y_pred_f)\n        \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        kernel_initializer='he_uniform'\n        inputs=tf.keras.Input(shape=self.input_shape)\n        s=inputs\n        #contraction\n        c1=Conv2D(16,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(s)\n        c1=Conv2D(16,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c1)\n        m1=MaxPooling2D(2,2)(c1)\n        m1=Dropout(0.25)(m1)\n        \n        c2=Conv2D(32,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(m1)\n        c2=Conv2D(32,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c2)\n        m2=MaxPooling2D(2,2)(c2)\n        m2=Dropout(0.25)(m2)\n        \n        c3=Conv2D(64,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(m2)\n        c3=Conv2D(64,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c3)\n        m3=MaxPooling2D(2,2)(c3)\n        m3=Dropout(0.25)(m3)\n        \n        \n        c4=Conv2D(128,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(m3)\n        c4=Conv2D(128,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c4)\n        m4=MaxPooling2D(2,2)(c4)\n        m4=Dropout(0.25)(m4)\n        \n        c5=Conv2D(256,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(m4)\n        c5=Conv2D(256,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c5)\n        m5=MaxPooling2D(2,2)(c5)\n        m5=Dropout(0.25)(m5)\n        \n        #middle layer\n        c6=Conv2D(512,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(m5)\n        c6=Conv2D(512,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c6)\n        \n        \n        #decontraction\n        \n        dc1=Conv2DTranspose(256,(2, 2), strides=(2, 2),padding='same')(c6)\n        dc1=concatenate([dc1,c5])\n        dc1=Dropout(0.25)(dc1)\n        c7=Conv2D(256,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(dc1)\n        c7=Conv2D(256,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c7)\n        \n        dc2=Conv2DTranspose(128,(2, 2), strides=(2, 2),padding='same')(c7)\n        dc2=concatenate([dc2,c4])\n        dc2=Dropout(0.25)(dc2)\n        c8=Conv2D(128,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(dc2)\n        c8=Conv2D(128,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c8)\n        \n        dc3=Conv2DTranspose(64,(2, 2), strides=(2, 2),padding='same')(c8)\n        dc3=concatenate([dc3,c3])\n        dc3=Dropout(0.25)(dc3)\n        c9=Conv2D(64,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(dc3)\n        c9=Conv2D(64,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c9)\n        \n        dc4=Conv2DTranspose(32,(2, 2), strides=(2, 2),padding='same')(c9)\n        dc4=concatenate([dc4,c2])\n        dc4=Dropout(0.25)(dc4)\n        c10=Conv2D(32,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(dc4)\n        c10=Conv2D(32,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c10)\n        \n        dc5=Conv2DTranspose(16,(2, 2), strides=(2, 2),padding='same')(c10)\n        dc5=concatenate([dc5,c1])\n        dc5=Dropout(0.25)(dc5)\n        c11=Conv2D(16,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(dc5)\n        c11=Conv2D(16,(3,3),activation=self.activation,kernel_initializer=kernel_initializer,padding='same')(c11)\n        \n        \n        outputs=Conv2D(1,(1,1),activation=\"sigmoid\")(c11)\n        \n        model=Model(inputs=[inputs],outputs=[outputs])\n        model.summary()\n        \n        return model\n    \n    def CompileandSummarize(self,model_):\n        model_.compile(optimizer=tf.keras.optimizers.Adam(),loss=self.dice_coef_loss,metrics=self.iou)\n        \n        \n        \n        \n        \n    \n        ","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.511565Z","iopub.execute_input":"2023-06-03T13:29:47.512505Z","iopub.status.idle":"2023-06-03T13:29:47.558870Z","shell.execute_reply.started":"2023-06-03T13:29:47.512454Z","shell.execute_reply":"2023-06-03T13:29:47.557594Z"},"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","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.562861Z","iopub.execute_input":"2023-06-03T13:29:47.563832Z","iopub.status.idle":"2023-06-03T13:29:47.573976Z","shell.execute_reply.started":"2023-06-03T13:29:47.563779Z","shell.execute_reply":"2023-06-03T13:29:47.572516Z"},"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)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.575988Z","iopub.execute_input":"2023-06-03T13:29:47.576471Z","iopub.status.idle":"2023-06-03T13:29:47.586827Z","shell.execute_reply.started":"2023-06-03T13:29:47.576423Z","shell.execute_reply":"2023-06-03T13:29:47.585586Z"},"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-06-03T13:29:47.590774Z","iopub.execute_input":"2023-06-03T13:29:47.591130Z","iopub.status.idle":"2023-06-03T13:29:47.602996Z","shell.execute_reply.started":"2023-06-03T13:29:47.591092Z","shell.execute_reply":"2023-06-03T13:29:47.601748Z"},"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))","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.604893Z","iopub.execute_input":"2023-06-03T13:29:47.605562Z","iopub.status.idle":"2023-06-03T13:29:47.616827Z","shell.execute_reply.started":"2023-06-03T13:29:47.605491Z","shell.execute_reply":"2023-06-03T13:29:47.615870Z"},"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))","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.618173Z","iopub.execute_input":"2023-06-03T13:29:47.620737Z","iopub.status.idle":"2023-06-03T13:29:47.629755Z","shell.execute_reply.started":"2023-06-03T13:29:47.620705Z","shell.execute_reply":"2023-06-03T13:29:47.628480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class gated_swish(tf.keras.layers.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-06-03T13:29:47.631278Z","iopub.execute_input":"2023-06-03T13:29:47.633396Z","iopub.status.idle":"2023-06-03T13:29:47.642927Z","shell.execute_reply.started":"2023-06-03T13:29:47.633348Z","shell.execute_reply":"2023-06-03T13:29:47.641882Z"},"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","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.649016Z","iopub.execute_input":"2023-06-03T13:29:47.649812Z","iopub.status.idle":"2023-06-03T13:29:47.659479Z","shell.execute_reply.started":"2023-06-03T13:29:47.649769Z","shell.execute_reply":"2023-06-03T13:29:47.658392Z"},"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-06-03T13:29:47.660906Z","iopub.execute_input":"2023-06-03T13:29:47.662214Z","iopub.status.idle":"2023-06-03T13:29:47.676249Z","shell.execute_reply.started":"2023-06-03T13:29:47.662114Z","shell.execute_reply":"2023-06-03T13:29:47.675282Z"},"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))","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.678296Z","iopub.execute_input":"2023-06-03T13:29:47.678821Z","iopub.status.idle":"2023-06-03T13:29:47.688189Z","shell.execute_reply.started":"2023-06-03T13:29:47.678778Z","shell.execute_reply":"2023-06-03T13:29:47.687039Z"},"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-06-03T13:29:47.690313Z","iopub.execute_input":"2023-06-03T13:29:47.690942Z","iopub.status.idle":"2023-06-03T13:29:47.699690Z","shell.execute_reply.started":"2023-06-03T13:29:47.690899Z","shell.execute_reply":"2023-06-03T13:29:47.698386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from timeit import default_timer as timer\nclass TimingCallback(keras.callbacks.Callback):\n    def __init__(self,logs={}):\n        self.logs=[]\n        \n        \n    def on_epoch_begin(self,epoch,logs={}):\n        self.starttime=timer()\n        \n    def on_epoch_end(self,epoch,logs={}):\n        self.logs.append(timer()-self.starttime)\n        \n        \n    \n    \n","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.701972Z","iopub.execute_input":"2023-06-03T13:29:47.702501Z","iopub.status.idle":"2023-06-03T13:29:47.712024Z","shell.execute_reply.started":"2023-06-03T13:29:47.702457Z","shell.execute_reply":"2023-06-03T13:29:47.710598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with ZipFile(\"../input/data-science-bowl-2018/stage1_train.zip\",\"r\") as zipref:\n    zipref.extractall(\"./stage1_train\")\n\nwith ZipFile(\"../input/data-science-bowl-2018/stage1_test.zip\",\"r\") as zipref:\n    zipref.extractall(\"./stage1_test\")","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:47.714453Z","iopub.execute_input":"2023-06-03T13:29:47.714926Z","iopub.status.idle":"2023-06-03T13:29:54.959814Z","shell.execute_reply.started":"2023-06-03T13:29:47.714882Z","shell.execute_reply":"2023-06-03T13:29:54.958505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"seed=42\nnp.random.seed=seed\n\nImage_height=96\nImage_width=96\nImage_channels=3\n\nTrain_path='./stage1_train/'\nTest_path='./stage1_test/'","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:54.961765Z","iopub.execute_input":"2023-06-03T13:29:54.962717Z","iopub.status.idle":"2023-06-03T13:29:54.971947Z","shell.execute_reply.started":"2023-06-03T13:29:54.962667Z","shell.execute_reply":"2023-06-03T13:29:54.968167Z"},"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]\ntrain_ids[:5]","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:54.973630Z","iopub.execute_input":"2023-06-03T13:29:54.974651Z","iopub.status.idle":"2023-06-03T13:29:55.000099Z","shell.execute_reply.started":"2023-06-03T13:29:54.974601Z","shell.execute_reply":"2023-06-03T13:29:54.998764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=np.zeros((len(train_ids),Image_height,Image_width,Image_channels),dtype=np.uint8)\ny_train=np.zeros((len(train_ids),Image_height,Image_width,1),dtype=np.bool)\nprint('Resizing images and masks')\n\nfor n,filename in tqdm(enumerate(train_ids)):\n    path=Train_path+filename\n    img=imread(path+'/images/'+filename+'.png')[:,:,:Image_channels]\n    img=resize(img,(Image_height,Image_width),mode='constant',preserve_range=True)\n    X_train[n]=img\n    mask=np.zeros((Image_height,Image_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_, (Image_height,Image_width), mode='constant',  \n                                      preserve_range=True), axis=-1)\n        mask = np.maximum(mask, mask_)  \n            \n    y_train[n] = mask\n\n\n","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:29:55.002732Z","iopub.execute_input":"2023-06-03T13:29:55.003486Z","iopub.status.idle":"2023-06-03T13:35:42.722674Z","shell.execute_reply.started":"2023-06-03T13:29:55.003441Z","shell.execute_reply":"2023-06-03T13:35:42.720225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = np.zeros((len(test_ids),Image_height , Image_width, Image_channels), dtype=np.uint8)\nsizes_test = []\nprint('Resizing test images') \nfor n, id_ in tqdm(enumerate(test_ids), total=len(test_ids)):\n    path = Test_path + id_\n    img = imread(path + '/images/' + id_ + '.png')[:,:,:Image_channels\n                                                  ]\n    sizes_test.append([img.shape[0], img.shape[1]])\n    img = resize(img, (Image_height, Image_width), mode='constant', preserve_range=True)\n    X_test[n] = img\n\nprint('Done!')","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:42.724922Z","iopub.execute_input":"2023-06-03T13:35:42.725438Z","iopub.status.idle":"2023-06-03T13:35:44.346273Z","shell.execute_reply.started":"2023-06-03T13:35:42.725384Z","shell.execute_reply":"2023-06-03T13:35:44.345038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imshow(X_train[0])\nplt.show()\nimshow(y_train[0])\nplt.show()\nimshow(np.squeeze(y_train[0]))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:44.348109Z","iopub.execute_input":"2023-06-03T13:35:44.349245Z","iopub.status.idle":"2023-06-03T13:35:45.112759Z","shell.execute_reply.started":"2023-06-03T13:35:44.349190Z","shell.execute_reply":"2023-06-03T13:35:45.111621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test,y_test=X_train[536:],y_train[536:]\nX_train,y_train=X_train[0:536],y_train[0:536]\n","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:45.114380Z","iopub.execute_input":"2023-06-03T13:35:45.115132Z","iopub.status.idle":"2023-06-03T13:35:45.123705Z","shell.execute_reply.started":"2023-06-03T13:35:45.115085Z","shell.execute_reply":"2023-06-03T13:35:45.122217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(X_train.shape,y_train.shape),(X_test.shape,y_test.shape)\n","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:45.125958Z","iopub.execute_input":"2023-06-03T13:35:45.126487Z","iopub.status.idle":"2023-06-03T13:35:45.140946Z","shell.execute_reply.started":"2023-06-03T13:35:45.126440Z","shell.execute_reply":"2023-06-03T13:35:45.139490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir /kaggle/working/logs\n\n","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:45.143057Z","iopub.execute_input":"2023-06-03T13:35:45.143469Z","iopub.status.idle":"2023-06-03T13:35:46.194382Z","shell.execute_reply.started":"2023-06-03T13:35:45.143435Z","shell.execute_reply":"2023-06-03T13:35:46.192673Z"},"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))\n","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:46.196765Z","iopub.execute_input":"2023-06-03T13:35:46.197638Z","iopub.status.idle":"2023-06-03T13:35:46.324327Z","shell.execute_reply.started":"2023-06-03T13:35:46.197586Z","shell.execute_reply":"2023-06-03T13:35:46.322980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class GCU(tf.keras.layers.Layer):\n    def __init__(self):\n        super(GCU, self).__init__()\n    \n    def call(self, x):\n        return tf.cast(tf.math.multiply(x , tf.math.cos(x))/tf.reduce_sum(x), tf.float32)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:46.327501Z","iopub.execute_input":"2023-06-03T13:35:46.328290Z","iopub.status.idle":"2023-06-03T13:35:46.336770Z","shell.execute_reply.started":"2023-06-03T13:35:46.328241Z","shell.execute_reply":"2023-06-03T13:35:46.335340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_inferences={}\n","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:46.338165Z","iopub.execute_input":"2023-06-03T13:35:46.339411Z","iopub.status.idle":"2023-06-03T13:35:46.348750Z","shell.execute_reply.started":"2023-06-03T13:35:46.339363Z","shell.execute_reply":"2023-06-03T13:35:46.347284Z"},"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, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)],  validation_data = (X_test, y_test))\n\ntraining_inferences['MexicanReLU'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:35:46.350857Z","iopub.execute_input":"2023-06-03T13:35:46.351514Z","iopub.status.idle":"2023-06-03T13:37:35.383704Z","shell.execute_reply.started":"2023-06-03T13:35:46.351471Z","shell.execute_reply":"2023-06-03T13:37:35.382492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results1.history.keys()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:37:35.394149Z","iopub.execute_input":"2023-06-03T13:37:35.394496Z","iopub.status.idle":"2023-06-03T13:37:35.402971Z","shell.execute_reply.started":"2023-06-03T13:37:35.394462Z","shell.execute_reply":"2023-06-03T13:37:35.401493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results1.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:37:35.405347Z","iopub.execute_input":"2023-06-03T13:37:35.406317Z","iopub.status.idle":"2023-06-03T13:37:35.666755Z","shell.execute_reply.started":"2023-06-03T13:37:35.406272Z","shell.execute_reply":"2023-06-03T13:37:35.665509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results1.history['iou'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:37:35.668785Z","iopub.execute_input":"2023-06-03T13:37:35.669671Z","iopub.status.idle":"2023-06-03T13:37:35.935892Z","shell.execute_reply.started":"2023-06-03T13:37:35.669622Z","shell.execute_reply":"2023-06-03T13:37:35.934584Z"},"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, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)],  validation_data = (X_test, y_test))\n\ntraining_inferences['Swish'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:37:35.938514Z","iopub.execute_input":"2023-06-03T13:37:35.939749Z","iopub.status.idle":"2023-06-03T13:38:59.079182Z","shell.execute_reply.started":"2023-06-03T13:37:35.939699Z","shell.execute_reply":"2023-06-03T13:38:59.075245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results2.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:38:59.082091Z","iopub.execute_input":"2023-06-03T13:38:59.083204Z","iopub.status.idle":"2023-06-03T13:39:03.685023Z","shell.execute_reply.started":"2023-06-03T13:38:59.083149Z","shell.execute_reply":"2023-06-03T13:39:03.683609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results2.history['iou'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:39:03.686638Z","iopub.execute_input":"2023-06-03T13:39:03.687491Z","iopub.status.idle":"2023-06-03T13:39:03.938049Z","shell.execute_reply.started":"2023-06-03T13:39:03.687439Z","shell.execute_reply":"2023-06-03T13:39:03.936777Z"},"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, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)],  validation_data = (X_test, y_test))\n\ntraining_inferences['TrainableLeakyReLU'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:39:03.939742Z","iopub.execute_input":"2023-06-03T13:39:03.941071Z","iopub.status.idle":"2023-06-03T13:39:35.223584Z","shell.execute_reply.started":"2023-06-03T13:39:03.941024Z","shell.execute_reply":"2023-06-03T13:39:35.222364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results3.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:39:35.225640Z","iopub.execute_input":"2023-06-03T13:39:35.226053Z","iopub.status.idle":"2023-06-03T13:39:52.053816Z","shell.execute_reply.started":"2023-06-03T13:39:35.226010Z","shell.execute_reply":"2023-06-03T13:39:52.052594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results3.history['iou'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:39:52.056847Z","iopub.execute_input":"2023-06-03T13:39:52.057938Z","iopub.status.idle":"2023-06-03T13:39:52.320724Z","shell.execute_reply.started":"2023-06-03T13:39:52.057888Z","shell.execute_reply":"2023-06-03T13:39:52.319585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_inferences","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:39:52.324443Z","iopub.execute_input":"2023-06-03T13:39:52.325608Z","iopub.status.idle":"2023-06-03T13:39:52.333936Z","shell.execute_reply.started":"2023-06-03T13:39:52.325522Z","shell.execute_reply":"2023-06-03T13:39:52.332577Z"},"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, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)], validation_data = (X_test, y_test))\n\ntraining_inferences['ISRU'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:39:52.336116Z","iopub.execute_input":"2023-06-03T13:39:52.336622Z","iopub.status.idle":"2023-06-03T13:41:51.473735Z","shell.execute_reply.started":"2023-06-03T13:39:52.336575Z","shell.execute_reply":"2023-06-03T13:41:51.472345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results4.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:41:51.477816Z","iopub.execute_input":"2023-06-03T13:41:51.478170Z","iopub.status.idle":"2023-06-03T13:42:21.678642Z","shell.execute_reply.started":"2023-06-03T13:41:51.478134Z","shell.execute_reply":"2023-06-03T13:42:21.677468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results4.history['iou'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:42:21.680857Z","iopub.execute_input":"2023-06-03T13:42:21.681748Z","iopub.status.idle":"2023-06-03T13:42:21.930731Z","shell.execute_reply.started":"2023-06-03T13:42:21.681702Z","shell.execute_reply":"2023-06-03T13:42:21.929540Z"},"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, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)], validation_data = (X_test, y_test))\n\ntraining_inferences['Mish'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:42:21.932799Z","iopub.execute_input":"2023-06-03T13:42:21.933259Z","iopub.status.idle":"2023-06-03T13:43:08.608076Z","shell.execute_reply.started":"2023-06-03T13:42:21.933204Z","shell.execute_reply":"2023-06-03T13:43:08.606835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results5.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:43:08.609627Z","iopub.execute_input":"2023-06-03T13:43:08.610355Z","iopub.status.idle":"2023-06-03T13:43:09.091822Z","shell.execute_reply.started":"2023-06-03T13:43:08.610319Z","shell.execute_reply":"2023-06-03T13:43:09.090501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results5.history['iou'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:43:09.093471Z","iopub.execute_input":"2023-06-03T13:43:09.094485Z","iopub.status.idle":"2023-06-03T13:43:09.748545Z","shell.execute_reply.started":"2023-06-03T13:43:09.094441Z","shell.execute_reply":"2023-06-03T13:43:09.747277Z"},"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, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)], validation_data = (X_test, y_test))\n\ntraining_inferences['gated_swish'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:43:09.750499Z","iopub.execute_input":"2023-06-03T13:43:09.751879Z","iopub.status.idle":"2023-06-03T13:44:28.973973Z","shell.execute_reply.started":"2023-06-03T13:43:09.751828Z","shell.execute_reply":"2023-06-03T13:44:28.972720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results6.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:44:28.976552Z","iopub.execute_input":"2023-06-03T13:44:28.977935Z","iopub.status.idle":"2023-06-03T13:44:29.248420Z","shell.execute_reply.started":"2023-06-03T13:44:28.977887Z","shell.execute_reply":"2023-06-03T13:44:29.247208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results6.history['iou'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:44:29.249997Z","iopub.execute_input":"2023-06-03T13:44:29.250949Z","iopub.status.idle":"2023-06-03T13:44:29.499736Z","shell.execute_reply.started":"2023-06-03T13:44:29.250901Z","shell.execute_reply":"2023-06-03T13:44:29.498573Z"},"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, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)], validation_data = (X_test, y_test))\n\ntraining_inferences['relu'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:44:29.501128Z","iopub.execute_input":"2023-06-03T13:44:29.501968Z","iopub.status.idle":"2023-06-03T13:44:48.760601Z","shell.execute_reply.started":"2023-06-03T13:44:29.501932Z","shell.execute_reply":"2023-06-03T13:44:48.759453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results_.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:44:48.762802Z","iopub.execute_input":"2023-06-03T13:44:48.763587Z","iopub.status.idle":"2023-06-03T13:44:51.036182Z","shell.execute_reply.started":"2023-06-03T13:44:48.763507Z","shell.execute_reply":"2023-06-03T13:44:51.035052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(results_.history['iou'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:44:51.040066Z","iopub.execute_input":"2023-06-03T13:44:51.040428Z","iopub.status.idle":"2023-06-03T13:44:51.288795Z","shell.execute_reply.started":"2023-06-03T13:44:51.040396Z","shell.execute_reply":"2023-06-03T13:44:51.287547Z"},"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, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)], validation_data = (X_test, y_test))\n\ntraining_inferences['LearnableSwish'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:44:51.291759Z","iopub.execute_input":"2023-06-03T13:44:51.292605Z","iopub.status.idle":"2023-06-03T13:47:04.848062Z","shell.execute_reply.started":"2023-06-03T13:44:51.292560Z","shell.execute_reply":"2023-06-03T13:47:04.846910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(resultsls.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:47:04.849893Z","iopub.execute_input":"2023-06-03T13:47:04.850875Z","iopub.status.idle":"2023-06-03T13:47:20.231800Z","shell.execute_reply.started":"2023-06-03T13:47:04.850829Z","shell.execute_reply":"2023-06-03T13:47:20.230543Z"},"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)\nresultsrs = modelsrs.fit(x = X_train, y = y_train, batch_size = 8, epochs=150, callbacks =  [cb, tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10)], validation_data = (X_test, y_test))\n\ntraining_inferences['SRS'] = sum(cb.logs)","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:47:20.233421Z","iopub.execute_input":"2023-06-03T13:47:20.234186Z","iopub.status.idle":"2023-06-03T13:49:22.418955Z","shell.execute_reply.started":"2023-06-03T13:47:20.234142Z","shell.execute_reply":"2023-06-03T13:49:22.417823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(resultsrs.history['loss'])","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:49:22.421812Z","iopub.execute_input":"2023-06-03T13:49:22.422717Z","iopub.status.idle":"2023-06-03T13:49:22.693792Z","shell.execute_reply.started":"2023-06-03T13:49:22.422669Z","shell.execute_reply":"2023-06-03T13:49:22.692580Z"},"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-06-03T13:49:22.696815Z","iopub.execute_input":"2023-06-03T13:49:22.697808Z","iopub.status.idle":"2023-06-03T13:49:22.704871Z","shell.execute_reply.started":"2023-06-03T13:49:22.697756Z","shell.execute_reply":"2023-06-03T13:49:22.703584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, 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-06-03T13:49:22.706682Z","iopub.execute_input":"2023-06-03T13:49:22.707540Z","iopub.status.idle":"2023-06-03T13:49:23.001807Z","shell.execute_reply.started":"2023-06-03T13:49:22.707472Z","shell.execute_reply":"2023-06-03T13:49:23.000566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"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(resultsrs.history['loss'])\n\n# Add titles to the subplots\naxs[0, 0].set_title('Symmetric_Galu')\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-06-03T13:49:23.005048Z","iopub.execute_input":"2023-06-03T13:49:23.005822Z","iopub.status.idle":"2023-06-03T13:49:24.412416Z","shell.execute_reply.started":"2023-06-03T13:49:23.005786Z","shell.execute_reply":"2023-06-03T13:49:24.411148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_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))","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:49:24.413789Z","iopub.execute_input":"2023-06-03T13:49:24.414231Z","iopub.status.idle":"2023-06-03T13:49:24.422484Z","shell.execute_reply.started":"2023-06-03T13:49:24.414185Z","shell.execute_reply":"2023-06-03T13:49:24.420846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n#Mexican_Relu\ny_pred = model1.predict(X_test_reshaped)\npredicted_classes = np.argmax(y_pred, axis=1)\nimport 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()","metadata":{"execution":{"iopub.status.busy":"2023-06-03T13:49:24.424960Z","iopub.execute_input":"2023-06-03T13:49:24.425639Z","iopub.status.idle":"2023-06-03T13:49:26.106690Z","shell.execute_reply.started":"2023-06-03T13:49:24.425585Z","shell.execute_reply":"2023-06-03T13:49:26.105318Z"},"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-06-03T13:49:26.108730Z","iopub.execute_input":"2023-06-03T13:49:26.110319Z","iopub.status.idle":"2023-06-03T13:49:27.292411Z","shell.execute_reply.started":"2023-06-03T13:49:26.110263Z","shell.execute_reply":"2023-06-03T13:49:27.291017Z"},"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-06-03T13:49:27.294798Z","iopub.execute_input":"2023-06-03T13:49:27.298820Z","iopub.status.idle":"2023-06-03T13:49:28.445711Z","shell.execute_reply.started":"2023-06-03T13:49:27.298734Z","shell.execute_reply":"2023-06-03T13:49:28.444495Z"},"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-06-03T13:49:28.447849Z","iopub.execute_input":"2023-06-03T13:49:28.448721Z","iopub.status.idle":"2023-06-03T13:49:29.638839Z","shell.execute_reply.started":"2023-06-03T13:49:28.448672Z","shell.execute_reply":"2023-06-03T13:49:29.637574Z"},"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-06-03T13:49:29.640934Z","iopub.execute_input":"2023-06-03T13:49:29.641410Z","iopub.status.idle":"2023-06-03T13:49:30.810014Z","shell.execute_reply.started":"2023-06-03T13:49:29.641364Z","shell.execute_reply":"2023-06-03T13:49:30.808762Z"},"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-06-03T13:49:30.815243Z","iopub.execute_input":"2023-06-03T13:49:30.818497Z","iopub.status.idle":"2023-06-03T13:49:32.348851Z","shell.execute_reply.started":"2023-06-03T13:49:30.818445Z","shell.execute_reply":"2023-06-03T13:49:32.347544Z"},"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-06-03T13:49:32.351156Z","iopub.execute_input":"2023-06-03T13:49:32.352127Z","iopub.status.idle":"2023-06-03T13:49:33.632764Z","shell.execute_reply.started":"2023-06-03T13:49:32.352046Z","shell.execute_reply":"2023-06-03T13:49:33.631573Z"},"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-06-03T13:49:33.634851Z","iopub.execute_input":"2023-06-03T13:49:33.635842Z","iopub.status.idle":"2023-06-03T13:49:34.801287Z","shell.execute_reply.started":"2023-06-03T13:49:33.635776Z","shell.execute_reply":"2023-06-03T13:49:34.799583Z"},"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-06-03T13:49:34.803141Z","iopub.execute_input":"2023-06-03T13:49:34.805826Z","iopub.status.idle":"2023-06-03T13:49:35.852773Z","shell.execute_reply.started":"2023-06-03T13:49:34.805773Z","shell.execute_reply":"2023-06-03T13:49:35.851408Z"},"trusted":true},"execution_count":null,"outputs":[]}]}