diff --git "a/benchmark/NBspecific_15/NBspecific_15_reproduced.ipynb" "b/benchmark/NBspecific_15/NBspecific_15_reproduced.ipynb" new file mode 100644--- /dev/null +++ "b/benchmark/NBspecific_15/NBspecific_15_reproduced.ipynb" @@ -0,0 +1,1235 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "eB2K6ltwQz19" + }, + "outputs": [], + "source": [ + "\"\"\"Required Liberaries\"\"\"\n", + "from numpy import zeros\n", + "from numpy import ones\n", + "from numpy.random import randint\n", + "from tensorflow.keras.optimizers import Adam\n", + "from keras.initializers import RandomNormal\n", + "from keras.models import Model\n", + "from keras.layers import Conv2D , Input\n", + "from keras.layers import Conv2DTranspose\n", + "from keras.layers import LeakyReLU\n", + "from keras.layers import Activation\n", + "from keras.layers import Concatenate\n", + "from keras.layers import Dropout\n", + "from keras.layers import BatchNormalization\n", + "from matplotlib import pyplot as plt\n", + "from tensorflow.keras.utils import plot_model\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "Sb5-0wCHRNkg" + }, + "outputs": [], + "source": [ + "def define_discriminator(image_shape):\n", + " \n", + "\t# weight initialization\n", + "\tinit = RandomNormal(stddev=0.02) #As described in the original paper\n", + " \n", + "\t# source image input\n", + "\tin_src_image = Input(shape=image_shape) #Image we want to convert to another image\n", + "\t# target image input\n", + "\tin_target_image = Input(shape=image_shape) #Image we want to generate after training. \n", + " \n", + "\t# concatenate images, channel-wise\n", + "\tmerged = Concatenate()([in_src_image, in_target_image])\n", + " \n", + "\t# C64: 4x4 kernel Stride 2x2\n", + "\td = Conv2D(64, (4,4), strides=(2,2), padding='same', kernel_initializer=init)(merged)\n", + "\td = LeakyReLU(alpha=0.2)(d)\n", + "\t# C128: 4x4 kernel Stride 2x2\n", + "\td = Conv2D(128, (4,4), strides=(2,2), padding='same', kernel_initializer=init)(d)\n", + "\td = BatchNormalization()(d)\n", + "\td = LeakyReLU(alpha=0.2)(d)\n", + "\t# C256: 4x4 kernel Stride 2x2\n", + "\td = Conv2D(256, (4,4), strides=(2,2), padding='same', kernel_initializer=init)(d)\n", + "\td = BatchNormalization()(d)\n", + "\td = LeakyReLU(alpha=0.2)(d)\n", + "\t# C512: 4x4 kernel Stride 2x2 \n", + " # Not in the original paper. Comment this block if you want.\n", + "\td = Conv2D(512, (4,4), strides=(2,2), padding='same', kernel_initializer=init)(d)\n", + "\td = BatchNormalization()(d)\n", + "\td = LeakyReLU(alpha=0.2)(d)\n", + "\t# second last output layer : 4x4 kernel but Stride 1x1\n", + "\td = Conv2D(512, (4,4), padding='same', kernel_initializer=init)(d)\n", + "\td = BatchNormalization()(d)\n", + "\td = LeakyReLU(alpha=0.2)(d)\n", + "\t# patch output\n", + "\td = Conv2D(1, (4,4), padding='same', kernel_initializer=init)(d)\n", + "\tpatch_out = Activation('sigmoid')(d)\n", + "\t# define model\n", + "\tmodel = Model([in_src_image, in_target_image], patch_out)\n", + "\t# compile model\n", + " #The model is trained with a batch size of one image and Adam opt. \n", + " #with a small learning rate and 0.5 beta. \n", + " #The loss for the discriminator is weighted by 50% for each model update.\n", + " \n", + "\topt = Adam(0.0002, beta_1=0.5)\n", + "\tmodel.compile(loss='binary_crossentropy', optimizer=opt, loss_weights=[0.5])\n", + "\treturn model" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "qiLL7X4vSk8k", + "outputId": "88668f7f-39c7-476b-dd4c-5a07d4385f5f" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.10/dist-packages/keras/src/layers/activations/leaky_relu.py:41: UserWarning: Argument `alpha` is deprecated. Use `negative_slope` instead.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "text/html": [ + "
Model: \"functional\"\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1mModel: \"functional\"\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
+       "┃ Layer (type)               Output Shape                   Param #  Connected to           ┃\n",
+       "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
+       "│ input_layer (InputLayer)  │ (None, 256, 256, 3)    │              0 │ -                      │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ input_layer_1             │ (None, 256, 256, 3)    │              0 │ -                      │\n",
+       "│ (InputLayer)              │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ concatenate (Concatenate) │ (None, 256, 256, 6)    │              0 │ input_layer[0][0],     │\n",
+       "│                           │                        │                │ input_layer_1[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d (Conv2D)           │ (None, 128, 128, 64)   │          6,208 │ concatenate[0][0]      │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu (LeakyReLU)   │ (None, 128, 128, 64)   │              0 │ conv2d[0][0]           │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_1 (Conv2D)         │ (None, 64, 64, 128)    │        131,200 │ leaky_re_lu[0][0]      │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization       │ (None, 64, 64, 128)    │            512 │ conv2d_1[0][0]         │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_1 (LeakyReLU) │ (None, 64, 64, 128)    │              0 │ batch_normalization[0… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_2 (Conv2D)         │ (None, 32, 32, 256)    │        524,544 │ leaky_re_lu_1[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_1     │ (None, 32, 32, 256)    │          1,024 │ conv2d_2[0][0]         │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───���───────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_2 (LeakyReLU) │ (None, 32, 32, 256)    │              0 │ batch_normalization_1… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_3 (Conv2D)         │ (None, 16, 16, 512)    │      2,097,664 │ leaky_re_lu_2[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_2     │ (None, 16, 16, 512)    │          2,048 │ conv2d_3[0][0]         │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_3 (LeakyReLU) │ (None, 16, 16, 512)    │              0 │ batch_normalization_2… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_4 (Conv2D)         │ (None, 16, 16, 512)    │      4,194,816 │ leaky_re_lu_3[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_3     │ (None, 16, 16, 512)    │          2,048 │ conv2d_4[0][0]         │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_4 (LeakyReLU) │ (None, 16, 16, 512)    │              0 │ batch_normalization_3… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_5 (Conv2D)         │ (None, 16, 16, 1)      │          8,193 │ leaky_re_lu_4[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation (Activation)   │ (None, 16, 16, 1)      │              0 │ conv2d_5[0][0]         │\n",
+       "└───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘\n",
+       "
\n" + ], + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ input_layer (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m3\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "├─────────���─────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ input_layer_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m3\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "│ (\u001b[38;5;33mInputLayer\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ concatenate (\u001b[38;5;33mConcatenate\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m6\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ input_layer[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", + "│ │ │ │ input_layer_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m6,208\u001b[0m │ concatenate[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_1 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m131,200\u001b[0m │ leaky_re_lu[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │ conv2d_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_1 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization[\u001b[38;5;34m0\u001b[0m… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_2 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m524,544\u001b[0m │ leaky_re_lu_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │ conv2d_2[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_2 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_3 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,097,664\u001b[0m │ leaky_re_lu_2[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_3 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_2… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_4 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m4,194,816\u001b[0m │ leaky_re_lu_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_3 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_4[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_4 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_3… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_5 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m1\u001b[0m) │ \u001b[38;5;34m8,193\u001b[0m │ leaky_re_lu_4[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m1\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d_5[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "└───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
 Total params: 6,968,257 (26.58 MB)\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m6,968,257\u001b[0m (26.58 MB)\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
 Trainable params: 6,965,441 (26.57 MB)\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m6,965,441\u001b[0m (26.57 MB)\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
 Non-trainable params: 2,816 (11.00 KB)\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m2,816\u001b[0m (11.00 KB)\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "test_dis = define_discriminator((256 , 256 ,3))\n", + "test_dis.summary()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "io9d_N2DSpm1" + }, + "outputs": [], + "source": [ + "def define_encoder_block(layer_in, n_filters, batchnorm=True):\n", + "\t# weight initialization\n", + "\tinit = RandomNormal(stddev=0.02)\n", + "\t# add downsampling layer\n", + "\tg = Conv2D(n_filters, (4,4), strides=(2,2), padding='same', kernel_initializer=init)(layer_in)\n", + "\t# conditionally add batch normalization\n", + "\tif batchnorm:\n", + "\t\tg = BatchNormalization()(g, training=True)\n", + "\t# leaky relu activation\n", + "\tg = LeakyReLU(alpha=0.2)(g)\n", + "\treturn g\n", + "\n", + "# define a decoder block to be used in generator\n", + "def decoder_block(layer_in, skip_in, n_filters, dropout=True):\n", + "\t# weight initialization\n", + "\tinit = RandomNormal(stddev=0.02)\n", + "\t# add upsampling layer\n", + "\tg = Conv2DTranspose(n_filters, (4,4), strides=(2,2), padding='same', kernel_initializer=init)(layer_in)\n", + "\t# add batch normalization\n", + "\tg = BatchNormalization()(g, training=True)\n", + "\t# conditionally add dropout\n", + "\tif dropout:\n", + "\t\tg = Dropout(0.5)(g, training=True)\n", + "\t# merge with skip connection\n", + "\tg = Concatenate()([g, skip_in])\n", + "\t# relu activation\n", + "\tg = Activation('relu')(g)\n", + "\treturn g\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "jXb5ESZQUbGs" + }, + "outputs": [], + "source": [ + "def decoder_block(layer_in , skip_in , n_filter , dropout = True): \n", + " init = RandomNormal(stddev = 0.02) \n", + " g = Conv2DTranspose(n_filter , (4,4) , strides = (2,2) , padding = \"same\" , kernel_initializer=init)(layer_in) \n", + " g = BatchNormalization()(g , training = True) \n", + " if dropout:\n", + " g = Dropout(0.5)(g , training = True) \n", + " g = Concatenate()([g , skip_in]) \n", + " g = Activation(\"relu\")(g) \n", + " return g " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "6OP68XhtVQCD" + }, + "outputs": [], + "source": [ + "def define_generator(image_shape=(256,256,3)):\n", + "\t# weight initialization\n", + "\tinit = RandomNormal(stddev=0.02)\n", + "\t# image input\n", + "\tin_image = Input(shape=image_shape)\n", + "\t# encoder model: C64-C128-C256-C512-C512-C512-C512-C512\n", + "\te1 = define_encoder_block(in_image, 64, batchnorm=False)\n", + "\te2 = define_encoder_block(e1, 128)\n", + "\te3 = define_encoder_block(e2, 256)\n", + "\te4 = define_encoder_block(e3, 512)\n", + "\te5 = define_encoder_block(e4, 512)\n", + "\te6 = define_encoder_block(e5, 512)\n", + "\te7 = define_encoder_block(e6, 512)\n", + "\t# bottleneck, no batch norm and relu\n", + "\tb = Conv2D(512, (4,4), strides=(2,2), padding='same', kernel_initializer=init)(e7)\n", + "\tb = Activation('relu')(b)\n", + "\t# decoder model: CD512-CD512-CD512-C512-C256-C128-C64\n", + "\td1 = decoder_block(b, e7, 512)\n", + "\td2 = decoder_block(d1, e6, 512)\n", + "\td3 = decoder_block(d2, e5, 512)\n", + "\td4 = decoder_block(d3, e4, 512, dropout=False)\n", + "\td5 = decoder_block(d4, e3, 256, dropout=False)\n", + "\td6 = decoder_block(d5, e2, 128, dropout=False)\n", + "\td7 = decoder_block(d6, e1, 64, dropout=False)\n", + "\t# output\n", + "\tg = Conv2DTranspose(image_shape[2], (4,4), strides=(2,2), padding='same', kernel_initializer=init)(d7) #Modified \n", + "\tout_image = Activation('tanh')(g) #Generates images in the range -1 to 1. So change inputs also to -1 to 1\n", + "\t# define model\n", + "\tmodel = Model(in_image, out_image)\n", + "\treturn model" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "1er0fKiprHQR", + "outputId": "7d6511b7-b683-4270-ed2a-8a38943ddcee" + }, + "outputs": [ + { + "data": { + "text/html": [ + "
Model: \"functional_1\"\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1mModel: \"functional_1\"\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
+       "┃ Layer (type)               Output Shape                   Param #  Connected to           ┃\n",
+       "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
+       "│ input_layer_2             │ (None, 256, 256, 3)    │              0 │ -                      │\n",
+       "│ (InputLayer)              │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_6 (Conv2D)         ��� (None, 128, 128, 64)   │          3,136 │ input_layer_2[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_5 (LeakyReLU) │ (None, 128, 128, 64)   │              0 │ conv2d_6[0][0]         │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_7 (Conv2D)         │ (None, 64, 64, 128)    │        131,200 │ leaky_re_lu_5[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_4     │ (None, 64, 64, 128)    │            512 │ conv2d_7[0][0]         │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_6 (LeakyReLU) │ (None, 64, 64, 128)    │              0 │ batch_normalization_4… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_8 (Conv2D)         │ (None, 32, 32, 256)    │        524,544 │ leaky_re_lu_6[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_5     │ (None, 32, 32, 256)    │          1,024 │ conv2d_8[0][0]         │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_7 (LeakyReLU) │ (None, 32, 32, 256)    │              0 │ batch_normalization_5… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_9 (Conv2D)         │ (None, 16, 16, 512)    │      2,097,664 │ leaky_re_lu_7[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_6     │ (None, 16, 16, 512)    │          2,048 │ conv2d_9[0][0]         │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_8 (LeakyReLU) │ (None, 16, 16, 512)    │              0 │ batch_normalization_6… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_10 (Conv2D)        │ (None, 8, 8, 512)      │      4,194,816 │ leaky_re_lu_8[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_7     │ (None, 8, 8, 512)      │          2,048 │ conv2d_10[0][0]        │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_9 (LeakyReLU) │ (None, 8, 8, 512)      │              0 │ batch_normalization_7… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_11 (Conv2D)        │ (None, 4, 4, 512)      │      4,194,816 │ leaky_re_lu_9[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_8     │ (None, 4, 4, 512)      │          2,048 │ conv2d_11[0][0]        │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_10            │ (None, 4, 4, 512)      │              0 │ batch_normalization_8… │\n",
+       "│ (LeakyReLU)               │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_12 (Conv2D)        │ (None, 2, 2, 512)      │      4,194,816 │ leaky_re_lu_10[0][0]   │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_9     │ (None, 2, 2, 512)      │          2,048 │ conv2d_12[0][0]        │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ leaky_re_lu_11            │ (None, 2, 2, 512)      │              0 │ batch_normalization_9… │\n",
+       "│ (LeakyReLU)               │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_13 (Conv2D)        │ (None, 1, 1, 512)      │      4,194,816 │ leaky_re_lu_11[0][0]   │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_1 (Activation) │ (None, 1, 1, 512)      │              0 │ conv2d_13[0][0]        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_transpose          │ (None, 2, 2, 512)      │      4,194,816 │ activation_1[0][0]     │\n",
+       "│ (Conv2DTranspose)         │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_10    │ (None, 2, 2, 512)      │          2,048 │ conv2d_transpose[0][0] │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ dropout (Dropout)         │ (None, 2, 2, 512)      │              0 │ batch_normalization_1… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ concatenate_1             │ (None, 2, 2, 1024)     │              0 │ dropout[0][0],         │\n",
+       "│ (Concatenate)             │                        │                │ leaky_re_lu_11[0][0]   │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_2 (Activation) │ (None, 2, 2, 1024)     │              0 │ concatenate_1[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_transpose_1        │ (None, 4, 4, 512)      │      8,389,120 │ activation_2[0][0]     │\n",
+       "│ (Conv2DTranspose)         │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_11    │ (None, 4, 4, 512)      │          2,048 │ conv2d_transpose_1[0]… │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ dropout_1 (Dropout)       │ (None, 4, 4, 512)      │              0 │ batch_normalization_1… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ concatenate_2             │ (None, 4, 4, 1024)     │              0 │ dropout_1[0][0],       │\n",
+       "│ (Concatenate)             │                        │                │ leaky_re_lu_10[0][0]   │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_3 (Activation) │ (None, 4, 4, 1024)     │              0 │ concatenate_2[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_transpose_2        │ (None, 8, 8, 512)      │      8,389,120 │ activation_3[0][0]     │\n",
+       "│ (Conv2DTranspose)         │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_12    │ (None, 8, 8, 512)      │          2,048 │ conv2d_transpose_2[0]… │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ dropout_2 (Dropout)       │ (None, 8, 8, 512)      │              0 │ batch_normalization_1… │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ concatenate_3             │ (None, 8, 8, 1024)     │              0 │ dropout_2[0][0],       │\n",
+       "│ (Concatenate)             │                        │                │ leaky_re_lu_9[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_4 (Activation) │ (None, 8, 8, 1024)     │              0 │ concatenate_3[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_transpose_3        │ (None, 16, 16, 512)    │      8,389,120 │ activation_4[0][0]     │\n",
+       "│ (Conv2DTranspose)         │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_13    │ (None, 16, 16, 512)    │          2,048 │ conv2d_transpose_3[0]… │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ concatenate_4             │ (None, 16, 16, 1024)   │              0 │ batch_normalization_1… │\n",
+       "│ (Concatenate)             │                        │                │ leaky_re_lu_8[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_5 (Activation) │ (None, 16, 16, 1024)   │              0 │ concatenate_4[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_transpose_4        │ (None, 32, 32, 256)    │      4,194,560 │ activation_5[0][0]     │\n",
+       "│ (Conv2DTranspose)         │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_14    │ (None, 32, 32, 256)    │          1,024 │ conv2d_transpose_4[0]… │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ concatenate_5             │ (None, 32, 32, 512)    │              0 │ batch_normalization_1… │\n",
+       "│ (Concatenate)             │                        │                │ leaky_re_lu_7[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_6 (Activation) │ (None, 32, 32, 512)    │              0 │ concatenate_5[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_transpose_5        │ (None, 64, 64, 128)    │      1,048,704 │ activation_6[0][0]     │\n",
+       "│ (Conv2DTranspose)         │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_15    │ (None, 64, 64, 128)    │            512 │ conv2d_transpose_5[0]… │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ concatenate_6             │ (None, 64, 64, 256)    │              0 │ batch_normalization_1… │\n",
+       "│ (Concatenate)             │                        │                │ leaky_re_lu_6[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_7 (Activation) │ (None, 64, 64, 256)    │              0 │ concatenate_6[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_transpose_6        │ (None, 128, 128, 64)   │        262,208 │ activation_7[0][0]     │\n",
+       "│ (Conv2DTranspose)         │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ batch_normalization_16    │ (None, 128, 128, 64)   │            256 │ conv2d_transpose_6[0]… │\n",
+       "│ (BatchNormalization)      │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ concatenate_7             │ (None, 128, 128, 128)  │              0 │ batch_normalization_1… │\n",
+       "│ (Concatenate)             │                        │                │ leaky_re_lu_5[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_8 (Activation) │ (None, 128, 128, 128)  │              0 │ concatenate_7[0][0]    │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ conv2d_transpose_7        │ (None, 256, 256, 3)    │          6,147 │ activation_8[0][0]     │\n",
+       "│ (Conv2DTranspose)         │                        │                │                        │\n",
+       "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
+       "│ activation_9 (Activation) │ (None, 256, 256, 3)    │              0 │ conv2d_transpose_7[0]… │\n",
+       "└───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘\n",
+       "
\n" + ], + "text/plain": [ + "┏━━━━━━━━━━━━━━━���━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓\n", + "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩\n", + "│ input_layer_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m3\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n", + "│ (\u001b[38;5;33mInputLayer\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_6 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m3,136\u001b[0m │ input_layer_2[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_5 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d_6[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_7 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m131,200\u001b[0m │ leaky_re_lu_5[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_4 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │ conv2d_7[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_6 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_4… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_8 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m524,544\u001b[0m │ leaky_re_lu_6[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_5 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │ conv2d_8[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_7 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_5… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_9 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,097,664\u001b[0m │ leaky_re_lu_7[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_6 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_9[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_8 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_6… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_10 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m4,194,816\u001b[0m │ leaky_re_lu_8[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_7 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_10[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_9 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_7… │\n", + "├───────────────────────���───┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_11 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m4,194,816\u001b[0m │ leaky_re_lu_9[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_8 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_11[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_10 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_8… │\n", + "│ (\u001b[38;5;33mLeakyReLU\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_12 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m4,194,816\u001b[0m │ leaky_re_lu_10[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_9 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_12[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ leaky_re_lu_11 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_9… │\n", + "│ (\u001b[38;5;33mLeakyReLU\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_13 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1\u001b[0m, \u001b[38;5;34m1\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m4,194,816\u001b[0m │ leaky_re_lu_11[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_1 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1\u001b[0m, \u001b[38;5;34m1\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d_13[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_transpose │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m4,194,816\u001b[0m │ activation_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_10 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_transpose[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ dropout (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ concatenate_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ dropout[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", + "│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ leaky_re_lu_11[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_2 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m2\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ concatenate_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_transpose_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m8,389,120\u001b[0m │ activation_2[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_11 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_transpose_1[\u001b[38;5;34m0\u001b[0m]… │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ dropout_1 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ concatenate_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ dropout_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", + "│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ leaky_re_lu_10[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_3 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m4\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ concatenate_2[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_transpose_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m8,389,120\u001b[0m │ activation_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_12 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_transpose_2[\u001b[38;5;34m0\u001b[0m]… │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ dropout_2 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ concatenate_3 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ dropout_2[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n", + "│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ leaky_re_lu_9[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_4 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ concatenate_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_transpose_3 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m8,389,120\u001b[0m │ activation_4[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_13 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_transpose_3[\u001b[38;5;34m0\u001b[0m]… │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ concatenate_4 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n", + "│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ leaky_re_lu_8[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_5 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ concatenate_4[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_transpose_4 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m4,194,560\u001b[0m │ activation_5[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_14 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │ conv2d_transpose_4[\u001b[38;5;34m0\u001b[0m]… │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ concatenate_5 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n", + "│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ leaky_re_lu_7[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├──────��────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_6 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ concatenate_5[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_transpose_5 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m1,048,704\u001b[0m │ activation_6[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_15 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │ conv2d_transpose_5[\u001b[38;5;34m0\u001b[0m]… │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ concatenate_6 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n", + "│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ leaky_re_lu_6[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_7 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ concatenate_6[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_transpose_6 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m262,208\u001b[0m │ activation_7[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ batch_normalization_16 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\u001b[0m │ conv2d_transpose_6[\u001b[38;5;34m0\u001b[0m]… │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────��\n", + "│ concatenate_7 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n", + "│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ leaky_re_lu_5[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_8 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ concatenate_7[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ conv2d_transpose_7 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m3\u001b[0m) │ \u001b[38;5;34m6,147\u001b[0m │ activation_8[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n", + "│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n", + "├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n", + "│ activation_9 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m3\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d_transpose_7[\u001b[38;5;34m0\u001b[0m]… │\n", + "└───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
 Total params: 54,429,315 (207.63 MB)\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m54,429,315\u001b[0m (207.63 MB)\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
 Trainable params: 54,419,459 (207.59 MB)\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m54,419,459\u001b[0m (207.59 MB)\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
 Non-trainable params: 9,856 (38.50 KB)\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m9,856\u001b[0m (38.50 KB)\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "test_gen = define_generator((256 ,256 , 3)) \n", + "test_gen.summary()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "giYNfNLEruOI" + }, + "outputs": [], + "source": [ + "# define the combined generator and discriminator model, for updating the generator\n", + "def define_gan(g_model, d_model, image_shape):\n", + "\t# make weights in the discriminator not trainable\n", + "\tfor layer in d_model.layers:\n", + "\t\tif not isinstance(layer, BatchNormalization):\n", + "\t\t\tlayer.trainable = False #Descriminator layers set to untrainable in the combined GAN but \n", + " #standalone descriminator will be trainable.\n", + " \n", + "\t# define the source image\n", + "\tin_src = Input(shape=image_shape)\n", + "\t# suppy the image as input to the generator \n", + "\tgen_out = g_model(in_src)\n", + "\t# supply the input image and generated image as inputs to the discriminator\n", + "\tdis_out = d_model([in_src, gen_out])\n", + "\t# src image as input, generated image and disc. output as outputs\n", + "\tmodel = Model(in_src, [dis_out, gen_out])\n", + "\t# compile model\n", + "\topt = Adam(lr=0.0002, beta_1=0.5)\n", + " \n", + " #Total loss is the weighted sum of adversarial loss (BCE) and L1 loss (MAE)\n", + " #Authors suggested weighting BCE vs L1 as 1:100.\n", + "\tmodel.compile(loss=['binary_crossentropy', 'mae'], \n", + " optimizer=opt, loss_weights=[1,100])\n", + "\treturn model\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "_5L-U36isiO0" + }, + "outputs": [], + "source": [ + "def generate_real_samples(dataset, n_samples, patch_shape):\n", + "\t# unpack dataset\n", + "\ttrainA, trainB = dataset\n", + "\t# choose random instances\n", + "\tix = randint(0, trainA.shape[0], n_samples)\n", + "\t# retrieve selected images\n", + "\tX1, X2 = trainA[ix], trainB[ix]\n", + "\t# generate 'real' class labels (1)\n", + "\ty = ones((n_samples, patch_shape, patch_shape, 1))\n", + "\treturn [X1, X2], y\n", + "\n", + "# generate a batch of images, returns images and targets\n", + "def generate_fake_samples(g_model, samples, patch_shape):\n", + "\t# generate fake instance\n", + "\tX = g_model.predict(samples)\n", + "\t# create 'fake' class labels (0)\n", + "\ty = zeros((len(X), patch_shape, patch_shape, 1))\n", + "\treturn X, y\n", + "\n", + "\n", + "def summarize_performance(step, g_model, dataset, n_samples=3):\n", + "\t# select a sample of input images\n", + "\t[X_realA, X_realB], _ = generate_real_samples(dataset, n_samples, 1)\n", + "\t# generate a batch of fake samples\n", + "\tX_fakeB, _ = generate_fake_samples(g_model, X_realA, 1)\n", + "\t# scale all pixels from [-1,1] to [0,1]\n", + "\tX_realA = (X_realA + 1) / 2.0\n", + "\tX_realB = (X_realB + 1) / 2.0\n", + "\tX_fakeB = (X_fakeB + 1) / 2.0\n", + "\t# plot real source images\n", + "\tfor i in range(n_samples):\n", + "\t\tplt.subplot(3, n_samples, 1 + i)\n", + "\t\tplt.axis('off')\n", + "\t\tplt.imshow(X_realA[i])\n", + "\t# plot generated target image\n", + "\tfor i in range(n_samples):\n", + "\t\tplt.subplot(3, n_samples, 1 + n_samples + i)\n", + "\t\tplt.axis('off')\n", + "\t\tplt.imshow(X_fakeB[i])\n", + "\t# plot real target image\n", + "\tfor i in range(n_samples):\n", + "\t\tplt.subplot(3, n_samples, 1 + n_samples*2 + i)\n", + "\t\tplt.axis('off')\n", + "\t\tplt.imshow(X_realB[i])\n", + "\t# save plot to file\n", + "\tfilename1 = 'plot_%06d.png' % (step+1)\n", + "\tplt.savefig(filename1)\n", + "\tplt.close()\n", + "\t# save the generator model\n", + "\tfilename2 = 'model_%06d.h5' % (step+1)\n", + "\tg_model.save(filename2)\n", + "\tprint('>Saved: %s and %s' % (filename1, filename2))" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "Lm4_UhTRslnU" + }, + "outputs": [], + "source": [ + "def train(d_model, g_model, gan_model, dataset, n_epochs=100, n_batch=1):\n", + "\tn_patch = d_model.output_shape[1]\n", + "\ttrainA, trainB = dataset\n", + "\tbat_per_epo = int(len(trainA) / n_batch)\n", + "\tn_steps = bat_per_epo * n_epochs\n", + "\tfor i in range(n_steps):\n", + "\t\t[X_realA, X_realB], y_real = generate_real_samples(dataset, n_batch, n_patch)\n", + "\t\tX_fakeB, y_fake = generate_fake_samples(g_model, X_realA, n_patch)\n", + "\t\td_loss1 = d_model.train_on_batch([X_realA, X_realB], y_real)\n", + "\t\td_loss2 = d_model.train_on_batch([X_realA, X_fakeB], y_fake)\n", + "\t\tg_loss, _, _ = gan_model.train_on_batch(X_realA, [y_real, X_realB])\n", + "\t\tprint('>%d, d1[%.3f] d2[%.3f] g[%.3f]' % (i+1, d_loss1, d_loss2, g_loss))\n", + "\t\tif (i+1) % (bat_per_epo * 10) == 0:\n", + "\t\t\tsummarize_performance(i, g_model, dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "aORbU08Qs8fq", + "outputId": "8ced4695-b502-4bcf-ec5b-95a155601fcc" + }, + "outputs": [], + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "7T-Op6lZsn-b" + }, + "outputs": [], + "source": [ + "\n", + "from tensorflow.keras.utils import normalize\n", + "import os\n", + "import glob\n", + "import cv2\n", + "import numpy as np\n", + "from matplotlib import pyplot \n", + "\n", + "\n", + "SIZE_X = 256\n", + "SIZE_Y = 256\n", + "\n", + "tar_images = []\n", + "\n", + "for directory_path in glob.glob(\"data_small/tar_images/\"):\n", + " for img_path in sorted(glob.glob(os.path.join(directory_path, \"*.jpg\"))):\n", + " img = cv2.imread(img_path, 1) \n", + " img = cv2.resize(img, (SIZE_Y, SIZE_X))\n", + " tar_images.append(img)\n", + "tar_images = np.array(tar_images)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "JySlPYd-tCtG" + }, + "outputs": [], + "source": [ + "from sklearn.utils import resample \n", + "tar_image = resample(tar_images , \n", + " replace = False , \n", + " n_samples = 50, \n", + " random_state=42)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "A3jTM9tctiD6", + "outputId": "015250cc-08b8-40ec-be0e-41921f4a564e" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(50, 256, 256, 3)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tar_image.shape" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "GR4slYpCtki8" + }, + "outputs": [], + "source": [ + "src_images = []\n", + "\n", + "for directory_path in glob.glob(\"data_small/src_images/\"):\n", + " for img_path in sorted(glob.glob(os.path.join(directory_path, \"*.jpg\"))):\n", + " img = cv2.imread(img_path, 1) \n", + " img = cv2.resize(img, (SIZE_Y, SIZE_X))\n", + " src_images.append(img)\n", + "src_images = np.array(src_images)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "04vh-g9Htyjs" + }, + "outputs": [], + "source": [ + "from sklearn.utils import resample \n", + "src_image = resample(src_images , \n", + " replace = False , \n", + " n_samples = 50, \n", + " random_state=42)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "p2v7U9v1t8yB", + "outputId": "91805f0c-7949-471f-99c9-17b1a3d00a8d" + }, + "outputs": [], + "source": [ + "src_image.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 447 + }, + "id": "il2bLfNWt-Wy", + "outputId": "78d0be0e-7df2-43c5-c71a-6c4c3244dde0" + }, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'src_images' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mrandom_img\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m \u001b[0;34m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msrc_images\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mfig\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m16\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m16\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0msrc_img\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msrc_images\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mrandom_img\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m256\u001b[0m \u001b[0;34m,\u001b[0m \u001b[0;36m256\u001b[0m \u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'src_images' is not defined" + ] + } + ], + "source": [ + "import numpy as np\n", + "import cv2\n", + "random_img = np.random.randint(0 , len(src_images))\n", + "fig = plt.figure(figsize = (16, 16))\n", + "src_img = np.reshape(src_images[random_img] , (256 , 256 ,3))\n", + "\n", + "tar_img = np.reshape(tar_images[random_img] , (256 , 256 ,3))\n", + "plt.subplot(121)\n", + "plt.imshow(cv2.cvtColor(src_img , cv2.COLOR_BGR2RGB))\n", + "plt.subplot(122)\n", + "plt.imshow(cv2.cvtColor(tar_img , cv2.COLOR_BGR2RGB))\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 768 + }, + "id": "OqNeVV8DuBkd", + "outputId": "4ecb0dd6-3d39-4eae-fb2c-1780dfdb131e" + }, + "outputs": [], + "source": [ + "n_samples = 3\n", + "fig = plt.figure(figsize = (16,16))\n", + "for i in range(n_samples):\n", + "\tpyplot.subplot(2, n_samples, 1 + i)\n", + "\tpyplot.axis('off')\n", + "\tpyplot.imshow(cv2.cvtColor(src_image[i] , cv2.COLOR_BGR2RGB))\n", + "for i in range(n_samples):\n", + "\tpyplot.subplot(2, n_samples, 1 + n_samples + i)\n", + "\tpyplot.axis('off')\n", + "\tpyplot.imshow(cv2.cvtColor(tar_image[i] , cv2.COLOR_BGR2RGB))\n", + "pyplot.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dPHV9FTfuPOt", + "outputId": "66b2565a-3d25-4e82-9a13-028decd3e06c" + }, + "outputs": [], + "source": [ + "image_shape = src_image.shape[1:]\n", + "d_model = define_discriminator(image_shape)\n", + "g_model = define_generator(image_shape)\n", + "gan_model = define_gan(g_model, d_model, image_shape)\n", + "\n", + "data = [src_image, tar_image]\n", + "\n", + "def preprocess_data(data):\n", + "\tX1, X2 = data[0], data[1]\n", + "\tX1 = (X1 - 127.5) / 127.5\n", + "\tX2 = (X2 - 127.5) / 127.5\n", + "\tX1 = X1.astype(\"float32\")\n", + "\tX2 = X2.astype(\"float32\")\n", + "\treturn [X1, X2]\n", + "\n", + "dataset = preprocess_data(data)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "bzmqekSTuRTo", + "outputId": "0a59ad0d-f3aa-4454-e1d9-ad5a5685d34c" + }, + "outputs": [], + "source": [ + "from datetime import datetime\n", + "start1 = datetime.now\n", + "train(d_model, g_model, gan_model, dataset, n_epochs=100, n_batch=1)\n", + "stop1 =datetime.now() \n", + "execution = stop1 - start1 \n", + "print(\"execution : \" ,execution)\n", + "g_model.save('data_small/model_weights.h5')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "ploQDQdkVksS", + "outputId": "1c6c0dbd-01fb-4c52-930f-87f4cba24e9b" + }, + "outputs": [], + "source": [ + "from keras.models import load_model\n", + "model = load_model(\"model_050000.h5\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0fTnvXZaOuPH" + }, + "outputs": [], + "source": [ + "def plot_images(src_images , tar_images , gen_images):\n", + " images = np.vstack((src_images , tar_images , gen_images)) \n", + " images = (images + 1 ) / 2.0\n", + " titles = [\"src_images\" , \"tar_imiages\" , \"gen_images\"] \n", + " for i in range(len(images)):\n", + " plt.subplot(1 , len(images) , i+1) \n", + " plt.axis(\"off\") \n", + " plt.imshow(cv2.cvtColor(images[i] , cv2.COLOR_BGR2RGB)) \n", + " plt.title(titles[i]) \n", + " plt.show() " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 326 + }, + "id": "UHCD4L0ZPjJg", + "outputId": "3c67b49f-bd6c-4dc1-f5a3-9c58406b5ab3" + }, + "outputs": [], + "source": [ + "[X1, X2] = dataset\n", + "# select random example\n", + "fig = plt.figure(figsize = (16,16))\n", + "ix = randint(0, len(X1), 1)\n", + "src_image, tar_image = X1[ix], X2[ix]\n", + "# generate image from source\n", + "gen_image = model.predict(src_image)\n", + "# plot all three images\n", + "plot_images(src_image, tar_image, gen_image)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "mrPvMoOSRDcC" + }, + "outputs": [], + "source": [ + "import numpy as np \n", + "import matplotlib.pyplot as plt \n", + "import cv2 \n", + "SIZE_X = 256\n", + "SIZE_Y = 256\n", + "img = cv2.imread(\"data_small/src_images/img-12.jpg\",1)\n", + "test_img = cv2.resize(img , (SIZE_X , SIZE_Y) , interpolation = cv2.INTER_NEAREST)\n", + "test_img = (test_img - 127.5) / 127.5 \n", + "test_img = np.expand_dims(test_img , axis = 0)\n", + "\n", + "for i in range(1):\n", + " gen_image = model.predict(test_img)\n", + " gen_image = (gen_image+1) / 2.0 \n", + " gen_image = gen_image.astype(\"float32\")\n", + " fig = plt.figure(figsize = (20,20))\n", + " plt.subplot(121)\n", + " plt.title(\"BLUE WATER IMAGE\")\n", + " plt.imshow(cv2.cvtColor(img , cv2.COLOR_BGR2RGB))\n", + " plt.subplot(122)\n", + " plt.title(\"RESTORED_ENHANCED_IMAGE\")\n", + " plt.imshow(cv2.cvtColor(gen_image[0] , cv2.COLOR_BGR2RGB))\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "collapsed_sections": [], + "name": "Welcome to Colaboratory", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}