{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5", "execution": { "iopub.execute_input": "2025-01-15T16:40:25.626866Z", "iopub.status.busy": "2025-01-15T16:40:25.626492Z", "iopub.status.idle": "2025-01-15T16:40:41.396765Z", "shell.execute_reply": "2025-01-15T16:40:41.395976Z", "shell.execute_reply.started": "2025-01-15T16:40:25.626835Z" }, "trusted": true }, "outputs": [ { "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, 512, 512, 3) │ 0 │ - │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d (Conv2D) │ (None, 512, 512, 64) │ 1,792 │ input_layer[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization │ (None, 512, 512, 64) │ 256 │ conv2d[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation (Activation) │ (None, 512, 512, 64) │ 0 │ batch_normalization[0… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_1 (Conv2D) │ (None, 512, 512, 64) │ 36,928 │ activation[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_1 │ (None, 512, 512, 64) │ 256 │ conv2d_1[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_1 (Activation) │ (None, 512, 512, 64) │ 0 │ batch_normalization_1… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ max_pooling2d │ (None, 256, 256, 64) │ 0 │ activation_1[0][0] │\n",
"│ (MaxPooling2D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_2 (Conv2D) │ (None, 256, 256, 128) │ 73,856 │ max_pooling2d[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_2 │ (None, 256, 256, 128) │ 512 │ conv2d_2[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_2 (Activation) │ (None, 256, 256, 128) │ 0 │ batch_normalization_2… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_3 (Conv2D) │ (None, 256, 256, 128) │ 147,584 │ activation_2[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_3 │ (None, 256, 256, 128) │ 512 │ conv2d_3[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_3 (Activation) │ (None, 256, 256, 128) │ 0 │ batch_normalization_3… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ max_pooling2d_1 │ (None, 128, 128, 128) │ 0 │ activation_3[0][0] │\n",
"│ (MaxPooling2D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_4 (Conv2D) │ (None, 128, 128, 256) │ 295,168 │ max_pooling2d_1[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_4 │ (None, 128, 128, 256) │ 1,024 │ conv2d_4[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_4 (Activation) │ (None, 128, 128, 256) │ 0 │ batch_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_5 (Conv2D) │ (None, 128, 128, 256) │ 590,080 │ activation_4[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_5 │ (None, 128, 128, 256) │ 1,024 │ conv2d_5[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_5 (Activation) │ (None, 128, 128, 256) │ 0 │ batch_normalization_5… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ max_pooling2d_2 │ (None, 64, 64, 256) │ 0 │ activation_5[0][0] │\n",
"│ (MaxPooling2D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_6 (Conv2D) │ (None, 64, 64, 512) │ 1,180,160 │ max_pooling2d_2[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_6 │ (None, 64, 64, 512) │ 2,048 │ conv2d_6[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_6 (Activation) │ (None, 64, 64, 512) │ 0 │ batch_normalization_6… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_7 (Conv2D) │ (None, 64, 64, 512) │ 2,359,808 │ activation_6[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_7 │ (None, 64, 64, 512) │ 2,048 │ conv2d_7[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_7 (Activation) │ (None, 64, 64, 512) │ 0 │ batch_normalization_7… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ max_pooling2d_3 │ (None, 32, 32, 512) │ 0 │ activation_7[0][0] │\n",
"│ (MaxPooling2D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_8 (Conv2D) │ (None, 32, 32, 1024) │ 4,719,616 │ max_pooling2d_3[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_8 │ (None, 32, 32, 1024) │ 4,096 │ conv2d_8[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_8 (Activation) │ (None, 32, 32, 1024) │ 0 │ batch_normalization_8… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_9 (Conv2D) │ (None, 32, 32, 1024) │ 9,438,208 │ activation_8[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_9 │ (None, 32, 32, 1024) │ 4,096 │ conv2d_9[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_9 (Activation) │ (None, 32, 32, 1024) │ 0 │ batch_normalization_9… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_transpose │ (None, 64, 64, 512) │ 2,097,664 │ activation_9[0][0] │\n",
"│ (Conv2DTranspose) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate (Concatenate) │ (None, 64, 64, 1024) │ 0 │ conv2d_transpose[0][0… │\n",
"│ │ │ │ activation_7[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_10 (Conv2D) │ (None, 64, 64, 512) │ 4,719,104 │ concatenate[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_10 │ (None, 64, 64, 512) │ 2,048 │ conv2d_10[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_10 │ (None, 64, 64, 512) │ 0 │ batch_normalization_1… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_11 (Conv2D) │ (None, 64, 64, 512) │ 2,359,808 │ activation_10[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_11 │ (None, 64, 64, 512) │ 2,048 │ conv2d_11[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_11 │ (None, 64, 64, 512) │ 0 │ batch_normalization_1… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_transpose_1 │ (None, 128, 128, 256) │ 524,544 │ activation_11[0][0] │\n",
"│ (Conv2DTranspose) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_1 │ (None, 128, 128, 512) │ 0 │ conv2d_transpose_1[0]… │\n",
"│ (Concatenate) │ │ │ activation_5[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_12 (Conv2D) │ (None, 128, 128, 256) │ 1,179,904 │ concatenate_1[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_12 │ (None, 128, 128, 256) │ 1,024 │ conv2d_12[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_12 │ (None, 128, 128, 256) │ 0 │ batch_normalization_1… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_13 (Conv2D) │ (None, 128, 128, 256) │ 590,080 │ activation_12[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_13 │ (None, 128, 128, 256) │ 1,024 │ conv2d_13[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_13 │ (None, 128, 128, 256) │ 0 │ batch_normalization_1… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_transpose_2 │ (None, 256, 256, 128) │ 131,200 │ activation_13[0][0] │\n",
"│ (Conv2DTranspose) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_2 │ (None, 256, 256, 256) │ 0 │ conv2d_transpose_2[0]… │\n",
"│ (Concatenate) │ │ │ activation_3[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_14 (Conv2D) │ (None, 256, 256, 128) │ 295,040 │ concatenate_2[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_14 │ (None, 256, 256, 128) │ 512 │ conv2d_14[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_14 │ (None, 256, 256, 128) │ 0 │ batch_normalization_1… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_15 (Conv2D) │ (None, 256, 256, 128) │ 147,584 │ activation_14[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_15 │ (None, 256, 256, 128) │ 512 │ conv2d_15[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_15 │ (None, 256, 256, 128) │ 0 │ batch_normalization_1… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_transpose_3 │ (None, 512, 512, 64) │ 32,832 │ activation_15[0][0] │\n",
"│ (Conv2DTranspose) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_3 │ (None, 512, 512, 128) │ 0 │ conv2d_transpose_3[0]… │\n",
"│ (Concatenate) │ │ │ activation_1[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_16 (Conv2D) │ (None, 512, 512, 64) │ 73,792 │ concatenate_3[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_16 │ (None, 512, 512, 64) │ 256 │ conv2d_16[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_16 │ (None, 512, 512, 64) │ 0 │ batch_normalization_1… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_17 (Conv2D) │ (None, 512, 512, 64) │ 36,928 │ activation_16[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_17 │ (None, 512, 512, 64) │ 256 │ conv2d_17[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_17 │ (None, 512, 512, 64) │ 0 │ batch_normalization_1… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_18 (Conv2D) │ (None, 512, 512, 11) │ 715 │ activation_17[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;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m3\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;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m1,792\u001b[0m │ input_layer[\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;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\u001b[0m │ conv2d[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization[\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;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m36,928\u001b[0m │ activation[\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;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\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",
"│ activation_1 (\u001b[38;5;33mActivation\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ max_pooling2d │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ activation_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_2 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m73,856\u001b[0m │ max_pooling2d[\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;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\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",
"│ activation_2 (\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;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_2… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_3 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m147,584\u001b[0m │ activation_2[\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;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\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",
"│ activation_3 (\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;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_3… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ max_pooling2d_1 │ (\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 │ activation_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_4 (\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;34m256\u001b[0m) │ \u001b[38;5;34m295,168\u001b[0m │ max_pooling2d_1[\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;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\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",
"│ activation_4 (\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;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_5 (\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;34m256\u001b[0m) │ \u001b[38;5;34m590,080\u001b[0m │ activation_4[\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;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │ conv2d_5[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_5 (\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;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_5… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ max_pooling2d_2 │ (\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 │ activation_5[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_6 (\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;34m512\u001b[0m) │ \u001b[38;5;34m1,180,160\u001b[0m │ max_pooling2d_2[\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;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │ conv2d_6[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_6 (\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;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_6… │\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;34m512\u001b[0m) │ \u001b[38;5;34m2,359,808\u001b[0m │ activation_6[\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;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\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",
"│ 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;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_7… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ max_pooling2d_3 │ (\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 │ activation_7[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ │ │ │\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;34m1024\u001b[0m) │ \u001b[38;5;34m4,719,616\u001b[0m │ max_pooling2d_3[\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;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m4,096\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",
"│ activation_8 (\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;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_8… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_9 (\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;34m1024\u001b[0m) │ \u001b[38;5;34m9,438,208\u001b[0m │ activation_8[\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;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m4,096\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",
"│ activation_9 (\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;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_9… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_transpose │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,097,664\u001b[0m │ activation_9[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate (\u001b[38;5;33mConcatenate\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d_transpose[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m… │\n",
"│ │ │ │ activation_7[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_10 (\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;34m512\u001b[0m) │ \u001b[38;5;34m4,719,104\u001b[0m │ concatenate[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_10 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\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",
"│ activation_10 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"│ (\u001b[38;5;33mActivation\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_11 (\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;34m512\u001b[0m) │ \u001b[38;5;34m2,359,808\u001b[0m │ activation_10[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_11 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\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",
"│ activation_11 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"│ (\u001b[38;5;33mActivation\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_transpose_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m524,544\u001b[0m │ activation_11[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d_transpose_1[\u001b[38;5;34m0\u001b[0m]… │\n",
"│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ activation_5[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_12 (\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;34m256\u001b[0m) │ \u001b[38;5;34m1,179,904\u001b[0m │ concatenate_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_12 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\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",
"│ activation_12 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"│ (\u001b[38;5;33mActivation\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_13 (\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;34m256\u001b[0m) │ \u001b[38;5;34m590,080\u001b[0m │ activation_12[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_13 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │ conv2d_13[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_13 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"│ (\u001b[38;5;33mActivation\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_transpose_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m131,200\u001b[0m │ activation_13[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d_transpose_2[\u001b[38;5;34m0\u001b[0m]… │\n",
"│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ activation_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_14 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m295,040\u001b[0m │ concatenate_2[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_14 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │ conv2d_14[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_14 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"│ (\u001b[38;5;33mActivation\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_15 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m147,584\u001b[0m │ activation_14[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_15 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │ conv2d_15[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_15 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m256\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"│ (\u001b[38;5;33mActivation\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_transpose_3 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m32,832\u001b[0m │ activation_15[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mConv2DTranspose\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_3 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ conv2d_transpose_3[\u001b[38;5;34m0\u001b[0m]… │\n",
"│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ activation_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_16 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m73,792\u001b[0m │ concatenate_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_16 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\u001b[0m │ conv2d_16[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_16 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"│ (\u001b[38;5;33mActivation\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_17 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m36,928\u001b[0m │ activation_16[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_17 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\u001b[0m │ conv2d_17[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_17 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ batch_normalization_1… │\n",
"│ (\u001b[38;5;33mActivation\u001b[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv2d_18 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m512\u001b[0m, \u001b[38;5;34m11\u001b[0m) │ \u001b[38;5;34m715\u001b[0m │ activation_17[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n",
"└───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"Total params: 31,055,947 (118.47 MB)\n", "\n" ], "text/plain": [ "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m31,055,947\u001b[0m (118.47 MB)\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Trainable params: 31,044,171 (118.42 MB)\n", "\n" ], "text/plain": [ "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m31,044,171\u001b[0m (118.42 MB)\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Non-trainable params: 11,776 (46.00 KB)\n", "\n" ], "text/plain": [ "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m11,776\u001b[0m (46.00 KB)\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import os\n", "\n", "from tensorflow.keras.layers import Conv2D, BatchNormalization, Activation, MaxPool2D, Conv2DTranspose, Concatenate, Input\n", "from tensorflow.keras.models import Model\n", "import numpy as np\n", "import cv2\n", "from glob import glob\n", "import tensorflow as tf\n", "from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, EarlyStopping, CSVLogger\n", "\n", "def conv_block(inputs, num_filters):\n", " x = Conv2D(num_filters, 3, padding=\"same\")(inputs)\n", " x = BatchNormalization()(x)\n", " x = Activation(\"relu\")(x)\n", "\n", " x = Conv2D(num_filters, 3, padding=\"same\")(x)\n", " x = BatchNormalization()(x)\n", " x = Activation(\"relu\")(x)\n", "\n", " return x\n", "\n", "def encoder_block(inputs, num_filters):\n", " x = conv_block(inputs, num_filters)\n", " p = MaxPool2D((2, 2))(x)\n", " return x, p\n", "\n", "def decoder_block(inputs, skip, num_filters):\n", " x = Conv2DTranspose(num_filters, (2, 2), strides=2, padding=\"same\")(inputs)\n", " x = Concatenate()([x, skip])\n", " x = conv_block(x, num_filters)\n", " return x\n", "\n", "def build_unet(input_shape, num_classes):\n", " inputs = Input(input_shape)\n", "\n", " s1, p1 = encoder_block(inputs, 64)\n", " s2, p2 = encoder_block(p1, 128)\n", " s3, p3 = encoder_block(p2, 256)\n", " s4, p4 = encoder_block(p3, 512)\n", "\n", " b1 = conv_block(p4, 1024)\n", "\n", " d1 = decoder_block(b1, s4, 512)\n", " d2 = decoder_block(d1, s3, 256)\n", " d3 = decoder_block(d2, s2, 128)\n", " d4 = decoder_block(d3, s1, 64)\n", "\n", " outputs = Conv2D(num_classes, 1, padding=\"same\", activation=\"softmax\")(d4)\n", "\n", " model = Model(inputs, outputs)\n", " return model\n", "\n", "\n", "if __name__ == \"__main__\":\n", " input_shape = (512, 512, 3)\n", " model = build_unet(input_shape, 11)\n", " model.summary()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2025-01-15T16:40:48.430014Z", "iopub.status.busy": "2025-01-15T16:40:48.429449Z", "iopub.status.idle": "2025-01-15T21:46:53.922844Z", "shell.execute_reply": "2025-01-15T21:46:53.921909Z", "shell.execute_reply.started": "2025-01-15T16:40:48.429985Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Train: 18168/18168 - Valid: 2000/2000 - Test: 2000/2000\n", "\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8dee4daa95c34b6a8c673af5025c5f29", "version_major": 2, "version_minor": 0 }, "text/plain": [ "0epoch [00:00, ?epoch/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "0batch [00:00, ?batch/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Epoch 1/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 772ms/step - loss: 0.8056\n", "Epoch 1: val_loss improved from inf to 0.32581, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1896s\u001b[0m 803ms/step - loss: 0.8054 - val_loss: 0.3258 - learning_rate: 1.0000e-04\n", "Epoch 2/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 775ms/step - loss: 0.2419\n", "Epoch 2: val_loss improved from 0.32581 to 0.24630, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1827s\u001b[0m 804ms/step - loss: 0.2418 - val_loss: 0.2463 - learning_rate: 1.0000e-04\n", "Epoch 3/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 774ms/step - loss: 0.1912\n", "Epoch 3: val_loss improved from 0.24630 to 0.21250, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1826s\u001b[0m 804ms/step - loss: 0.1912 - val_loss: 0.2125 - learning_rate: 1.0000e-04\n", "Epoch 4/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 775ms/step - loss: 0.1659\n", "Epoch 4: val_loss improved from 0.21250 to 0.17604, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1829s\u001b[0m 805ms/step - loss: 0.1659 - val_loss: 0.1760 - learning_rate: 1.0000e-04\n", "Epoch 5/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 776ms/step - loss: 0.1521\n", "Epoch 5: val_loss improved from 0.17604 to 0.16554, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1830s\u001b[0m 806ms/step - loss: 0.1521 - val_loss: 0.1655 - learning_rate: 1.0000e-04\n", "Epoch 6/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 776ms/step - loss: 0.1422\n", "Epoch 6: val_loss improved from 0.16554 to 0.16303, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1831s\u001b[0m 806ms/step - loss: 0.1422 - val_loss: 0.1630 - learning_rate: 1.0000e-04\n", "Epoch 7/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 777ms/step - loss: 0.1324\n", "Epoch 7: val_loss improved from 0.16303 to 0.15426, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1832s\u001b[0m 807ms/step - loss: 0.1324 - val_loss: 0.1543 - learning_rate: 1.0000e-04\n", "Epoch 8/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 777ms/step - loss: 0.1257\n", "Epoch 8: val_loss improved from 0.15426 to 0.14793, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1831s\u001b[0m 806ms/step - loss: 0.1257 - val_loss: 0.1479 - learning_rate: 1.0000e-04\n", "Epoch 9/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 777ms/step - loss: 0.1170\n", "Epoch 9: val_loss improved from 0.14793 to 0.14369, saving model to /kaggle/working/model.keras\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1832s\u001b[0m 807ms/step - loss: 0.1170 - val_loss: 0.1437 - learning_rate: 1.0000e-04\n", "Epoch 10/10\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 777ms/step - loss: 0.1107\n", "Epoch 10: val_loss did not improve from 0.14369\n", "\u001b[1m2271/2271\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1830s\u001b[0m 806ms/step - loss: 0.1106 - val_loss: 0.1497 - learning_rate: 1.0000e-04\n" ] } ], "source": [ "\n", "from tqdm.keras import TqdmCallback\n", "global image_h\n", "global image_w\n", "global num_classes\n", "global classes\n", "global rgb_codes\n", "\n", "def create_dir(path):\n", " if not os.path.exists(path):\n", " os.makedirs(path)\n", "\n", "def load_dataset(path):\n", " train_x = sorted(glob(os.path.join(path, \"train\", \"images\", \"*.jpg\")))\n", " train_y = sorted(glob(os.path.join(path, \"train\", \"labels\", \"*.png\")))\n", "\n", " valid_x = sorted(glob(os.path.join(path, \"val\", \"images\", \"*.jpg\")))\n", " valid_y = sorted(glob(os.path.join(path, \"val\", \"labels\", \"*.png\")))\n", "\n", " test_x = sorted(glob(os.path.join(path, \"test\", \"images\", \"*.jpg\")))\n", " test_y = sorted(glob(os.path.join(path, \"test\", \"labels\", \"*.png\")))\n", "\n", " return (train_x, train_y), (valid_x, valid_y), (test_x, test_y)\n", "\n", "def read_image_mask(x, y):\n", " \"\"\" Image \"\"\"\n", " x = cv2.imread(x, cv2.IMREAD_COLOR)\n", " x = cv2.resize(x, (image_w, image_h))\n", " x = x/255.0\n", " x = x.astype(np.float32)\n", "\n", " \"\"\" Mask \"\"\"\n", " y = cv2.imread(y, cv2.IMREAD_GRAYSCALE)\n", " y = cv2.resize(y, (image_w, image_h))\n", " y = y.astype(np.int32)\n", "\n", " return x, y\n", "\n", "def preprocess(x, y):\n", " def f(x, y):\n", " x = x.decode()\n", " y = y.decode()\n", " return read_image_mask(x, y)\n", "\n", " image, mask = tf.numpy_function(f, [x, y], [tf.float32, tf.int32])\n", " mask = tf.one_hot(mask, num_classes)\n", "\n", " image.set_shape([image_h, image_w, 3])\n", " mask.set_shape([image_h, image_w, num_classes])\n", "\n", " return image, mask\n", "\n", "def tf_dataset(X, Y, batch=8):\n", " ds = tf.data.Dataset.from_tensor_slices((X, Y))\n", " ds = ds.shuffle(buffer_size=5000).map(preprocess)\n", " ds = ds.batch(batch).prefetch(2)\n", " return ds\n", "\n", "if __name__ == \"__main__\":\n", " \"\"\" Seeding \"\"\"\n", " np.random.seed(42)\n", " tf.random.set_seed(42)\n", "\n", " \"\"\" Directory for storing files \"\"\"\n", " create_dir(\"files\")\n", "\n", " \"\"\" Hyperparameters \"\"\"\n", " image_h = 512\n", " image_w = 512\n", " num_classes = 11\n", " input_shape = (image_h, image_w, 3)\n", " batch_size = 8\n", " lr = 1e-4 ## 0.0001\n", " num_epochs = 10\n", "\n", " \"\"\" Paths \"\"\"\n", " dataset_path = \"/kaggle/input/lapa-face-parsing-dataset/LaPa\"\n", " model_path = \"/kaggle/working/model.keras\"\n", " csv_path = \"/kaggle/working/data.csv\"\n", "\n", " \"\"\" RGB Code and Classes \"\"\"\n", " rgb_codes = [\n", " [0, 0, 0], [0, 153, 255], [102, 255, 153], [0, 204, 153],\n", " [255, 255, 102], [255, 255, 204], [255, 153, 0], [255, 102, 255],\n", " [102, 0, 51], [255, 204, 255], [255, 0, 102]\n", " ]\n", "\n", " classes = [\n", " \"background\", \"skin\", \"left eyebrow\", \"right eyebrow\",\n", " \"left eye\", \"right eye\", \"nose\", \"upper lip\", \"inner mouth\",\n", " \"lower lip\", \"hair\"\n", " ]\n", "\n", " \"\"\" Loading the dataset \"\"\"\n", " (train_x, train_y), (valid_x, valid_y), (test_x, test_y) = load_dataset(dataset_path)\n", " print(f\"Train: {len(train_x)}/{len(train_y)} - Valid: {len(valid_x)}/{len(valid_y)} - Test: {len(test_x)}/{len(test_x)}\")\n", " print(\"\")\n", "\n", " \"\"\" Dataset Pipeline \"\"\"\n", " train_ds = tf_dataset(train_x, train_y, batch=batch_size)\n", " valid_ds = tf_dataset(valid_x, valid_y, batch=batch_size)\n", "\n", " \"\"\" Model \"\"\"\n", " model = build_unet(input_shape, num_classes)\n", " model.compile(\n", " loss=\"categorical_crossentropy\",\n", " optimizer=tf.keras.optimizers.Adam(lr)\n", " )\n", "\n", " \"\"\" Training \"\"\"\n", " callbacks = [\n", " TqdmCallback(verbose=1),\n", " ModelCheckpoint(model_path, verbose=1, save_best_only=True, monitor='val_loss'),\n", " ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=5, min_lr=1e-7, verbose=1),\n", " CSVLogger(csv_path, append=True),\n", " EarlyStopping(monitor='val_loss', patience=20, restore_best_weights=False)\n", " ]\n", "\n", " model.fit(train_ds,\n", " validation_data=valid_ds,\n", " epochs=num_epochs,\n", " callbacks=callbacks\n", " )" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2025-01-15T16:40:07.961852Z", "iopub.status.busy": "2025-01-15T16:40:07.961461Z", "iopub.status.idle": "2025-01-15T16:40:07.969384Z", "shell.execute_reply": "2025-01-15T16:40:07.968327Z", "shell.execute_reply.started": "2025-01-15T16:40:07.961825Z" }, "jupyter": { "source_hidden": true }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The directory /kaggle/working/output does not exist.\n" ] } ], "source": [ "# import shutil\n", "\n", "# # Path to the Kaggle output directory\n", "# output_dir = \"/kaggle/working/output\"\n", "\n", "# try:\n", "# # Delete the directory and its contents\n", "# shutil.rmtree(output_dir)\n", "# print(f\"Successfully deleted the directory: {output_dir}\")\n", "# except FileNotFoundError:\n", "# print(f\"The directory {output_dir} does not exist.\")\n", "# except PermissionError:\n", "# print(f\"Permission denied to delete the directory: {output_dir}\")\n", "# except Exception as e:\n", "# print(f\"An error occurred: {e}\")\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2025-01-18T12:55:04.971403Z", "iopub.status.busy": "2025-01-18T12:55:04.971062Z", "iopub.status.idle": "2025-01-18T12:55:16.714889Z", "shell.execute_reply": "2025-01-18T12:55:16.714231Z", "shell.execute_reply.started": "2025-01-18T12:55:04.971379Z" }, "trusted": true }, "outputs": [], "source": [ "import numpy as np\n", "import tensorflow as tf\n", "import cv2\n", "import matplotlib.pyplot as plt\n", "import imutils\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2025-02-11T14:54:49.075579Z", "iopub.status.busy": "2025-02-11T14:54:49.075283Z", "iopub.status.idle": "2025-02-11T15:13:41.597827Z", "shell.execute_reply": "2025-02-11T15:13:41.596973Z", "shell.execute_reply.started": "2025-02-11T14:54:49.075559Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Train: 18168/18168 - Valid: 2000/2000 - Test: 2000/2000\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 2000/2000 [18:47<00:00, 1.77it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Class F1 Jaccard \n", "-----------------------------------\n", "background : 0.97259 - 0.94849\n", "skin : 0.94535 - 0.89980\n", "left eyebrow : 0.55470 - 0.41518\n", "right eyebrow : 0.60111 - 0.46519\n", "left eye : 0.55648 - 0.41848\n", "right eye : 0.56165 - 0.42519\n", "nose : 0.91613 - 0.85186\n", "upper lip : 0.69397 - 0.54920\n", "inner mouth : 0.49528 - 0.39525\n", "lower lip : 0.72589 - 0.59049\n", "hair : 0.86952 - 0.79818\n", "-----------------------------------\n", "Mean : 0.71751 - 0.61430\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "\n", "import os\n", "\n", "import numpy as np\n", "import cv2\n", "import pandas as pd\n", "from glob import glob\n", "from tqdm import tqdm\n", "import tensorflow as tf\n", "from sklearn.metrics import f1_score, jaccard_score\n", "\n", "global image_h\n", "global image_w\n", "global num_classes\n", "global classes\n", "global rgb_codes\n", "\n", "\n", "def load_dataset(path):\n", " train_x = sorted(glob(os.path.join(path, \"train\", \"images\", \"*.jpg\")))\n", " train_y = sorted(glob(os.path.join(path, \"train\", \"labels\", \"*.png\")))\n", "\n", " valid_x = sorted(glob(os.path.join(path, \"val\", \"images\", \"*.jpg\")))\n", " valid_y = sorted(glob(os.path.join(path, \"val\", \"labels\", \"*.png\")))\n", "\n", " test_x = sorted(glob(os.path.join(path, \"test\", \"images\", \"*.jpg\")))\n", " test_y = sorted(glob(os.path.join(path, \"test\", \"labels\", \"*.png\")))\n", "\n", " return (train_x, train_y), (valid_x, valid_y), (test_x, test_y)\n", "\n", "def grayscale_to_rgb(mask, rgb_codes):\n", " h, w = mask.shape[0], mask.shape[1]\n", " mask = mask.astype(np.int32)\n", " output = []\n", "\n", " for i, pixel in enumerate(mask.flatten()):\n", " output.append(rgb_codes[pixel])\n", "\n", " output = np.reshape(output, (h, w, 3))\n", " return output\n", "\n", "def save_results(image_x, mask, pred, save_image_path):\n", " mask = np.expand_dims(mask, axis=-1)\n", " mask = grayscale_to_rgb(mask, rgb_codes)\n", "\n", " pred = np.expand_dims(pred, axis=-1)\n", " pred = grayscale_to_rgb(pred, rgb_codes)\n", "\n", " line = np.ones((image_x.shape[0], 10, 3)) * 255\n", "\n", " cat_images = np.concatenate([image_x, line, mask, line, pred], axis=1)\n", " cv2.imwrite(save_image_path, cat_images)\n", "\n", "if __name__ == \"__main__\":\n", " \"\"\" Seeding \"\"\"\n", " np.random.seed(42)\n", " tf.random.set_seed(42)\n", "\n", "\n", " \"\"\" Hyperparameters \"\"\"\n", " image_h = 512\n", " image_w = 512\n", " num_classes = 11\n", "\n", " \"\"\" Paths \"\"\"\n", " dataset_path = \"/kaggle/input/lapa-face-parsing-dataset/LaPa\"\n", " model_path = \"/kaggle/input/trained-model/10epoch model.h5\"\n", "\n", " \"\"\" RGB Code and Classes \"\"\"\n", " rgb_codes = [\n", " [0, 0, 0], [0, 153, 255], [102, 255, 153], [0, 204, 153],\n", " [255, 255, 102], [255, 255, 204], [255, 153, 0], [255, 102, 255],\n", " [102, 0, 51], [255, 204, 255], [255, 0, 102]\n", " ]\n", "\n", " classes = [\n", " \"background\", \"skin\", \"left eyebrow\", \"right eyebrow\",\n", " \"left eye\", \"right eye\", \"nose\", \"upper lip\", \"inner mouth\",\n", " \"lower lip\", \"hair\"\n", " ]\n", "\n", " \"\"\" Loading the dataset \"\"\"\n", " (train_x, train_y), (valid_x, valid_y), (test_x, test_y) = load_dataset(dataset_path)\n", " print(f\"Train: {len(train_x)}/{len(train_y)} - Valid: {len(valid_x)}/{len(valid_y)} - Test: {len(test_x)}/{len(test_x)}\")\n", " print(\"\")\n", "\n", " \"\"\" Load the model \"\"\"\n", " model = tf.keras.models.load_model(model_path)\n", "\n", " \"\"\" Prediction & Evaluation \"\"\"\n", " SCORE = []\n", " for x, y in tqdm(zip(test_x, test_y), total=len(test_x)):\n", " \"\"\" Extract the name \"\"\"\n", " name = x.split(\"/\")[-1].split(\".\")[0]\n", "\n", " \"\"\" Reading the image \"\"\"\n", " image = cv2.imread(x, cv2.IMREAD_COLOR)\n", " image = cv2.resize(image, (image_w, image_h))\n", " image_x = image\n", " image = image/255.0 ## (H, W, 3)\n", " image = np.expand_dims(image, axis=0) ## [1, H, W, 3]\n", " image = image.astype(np.float32)\n", "\n", " \"\"\" Reading the mask \"\"\"\n", " mask = cv2.imread(y, cv2.IMREAD_GRAYSCALE)\n", " mask = cv2.resize(mask, (image_w, image_h))\n", " mask = mask.astype(np.int32)\n", "\n", " \"\"\" Prediction \"\"\"\n", " pred = model.predict(image, verbose=0)[0]\n", " pred = np.argmax(pred, axis=-1) ## [0.1, 0.2, 0.1, 0.6] -> 3\n", " pred = pred.astype(np.int32)\n", "\n", " ## cv2.imwrite(\"pred.png\", pred * (255/11))\n", "\n", " # rgb_mask = grayscale_to_rgb(pred, rgb_codes)\n", " # cv2.imwrite(\"pred.png\", rgb_mask)\n", "\n", " \"\"\" Save the results \"\"\"\n", " save_image_path = f\"results/{name}.png\"\n", " save_results(image_x, mask, pred, save_image_path)\n", "\n", " \"\"\" Flatten the array \"\"\"\n", " mask = mask.flatten()\n", " pred = pred.flatten()\n", "\n", " labels = [i for i in range(num_classes)]\n", "\n", " \"\"\" Calculating the metrics values \"\"\"\n", " f1_value = f1_score(mask, pred, labels=labels, average=None, zero_division=0)\n", " jac_value = jaccard_score(mask, pred, labels=labels, average=None, zero_division=0)\n", "\n", " SCORE.append([f1_value, jac_value])\n", "\n", " score = np.array(SCORE)\n", " score = np.mean(score, axis=0)\n", "\n", " f = open(\"/kaggle/working/scores.csv\", \"w\")\n", " f.write(\"Class,F1,Jaccard\\n\")\n", "\n", " l = [\"Class\", \"F1\", \"Jaccard\"]\n", " print(f\"{l[0]:15s} {l[1]:10s} {l[2]:10s}\")\n", " print(\"-\"*35)\n", "\n", " for i in range(num_classes):\n", " class_name = classes[i]\n", " f1 = score[0, i]\n", " jac = score[1, i]\n", " dstr = f\"{class_name:15s}: {f1:1.5f} - {jac:1.5f}\"\n", " print(dstr)\n", " f.write(f\"{class_name:15s},{f1:1.5f},{jac:1.5f}\\n\")\n", "\n", " print(\"-\"*35)\n", " class_mean = np.mean(score, axis=-1)\n", " class_name = \"Mean\"\n", "\n", " f1 = class_mean[0]\n", " jac = class_mean[1]\n", "\n", " dstr = f\"{class_name:15s}: {f1:1.5f} - {jac:1.5f}\"\n", " print(dstr)\n", " f.write(f\"{class_name:15s},{f1:1.5f},{jac:1.5f}\\n\")\n", "\n", " f.close()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2025-02-11T14:54:17.543580Z", "iopub.status.busy": "2025-02-11T14:54:17.543248Z", "iopub.status.idle": "2025-02-11T14:54:17.554890Z", "shell.execute_reply": "2025-02-11T14:54:17.554276Z", "shell.execute_reply.started": "2025-02-11T14:54:17.543560Z" }, "trusted": true }, "outputs": [], "source": [ "dfq = pd.DataFrame(list())\n", "dfq.to_csv('scores.csv')" ] } ], "metadata": { "kaggle": { "accelerator": "gpu", "dataSources": [ { "datasetId": 4705085, "sourceId": 7992059, "sourceType": "datasetVersion" }, { "datasetId": 6491422, "sourceId": 10484428, "sourceType": "datasetVersion" } ], "dockerImageVersionId": 30839, "isGpuEnabled": true, "isInternetEnabled": true, "language": "python", "sourceType": "notebook" }, "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 }