face_mask_detection/train_model.ipynb

1302 lines
102 KiB
Plaintext
Raw Normal View History

2022-02-16 02:14:07 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"id": "602ab916",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import glob\n",
"from os import walk"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a7492299",
"metadata": {},
"outputs": [],
"source": [
"TRAIN_DATA_DIR = \"./data/cropped_images\"\n",
"TRAIN_LABELS_PATH = \"./data/labels.txt\""
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "5239a585",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>label</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>without_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>without_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4067</th>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4068</th>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4069</th>\n",
" <td>mask_weared_incorrect</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4070</th>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4071</th>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>4072 rows × 1 columns</p>\n",
"</div>"
],
"text/plain": [
" label\n",
"0 without_mask\n",
"1 with_mask\n",
"2 without_mask\n",
"3 with_mask\n",
"4 with_mask\n",
"... ...\n",
"4067 with_mask\n",
"4068 with_mask\n",
"4069 mask_weared_incorrect\n",
"4070 with_mask\n",
"4071 with_mask\n",
"\n",
"[4072 rows x 1 columns]"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"labels = pd.read_csv(TRAIN_LABELS_PATH, sep=\" \", header=None)[0].to_numpy()\n",
"d = {'label':labels}\n",
"labels = pd.DataFrame(d)\n",
"labels"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "6672b327",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"label \n",
"with_mask 3232\n",
"without_mask 717\n",
"mask_weared_incorrect 123\n",
"dtype: int64"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"labels.value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "96dd03bc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['mask_weared_incorrect', 'with_mask', 'without_mask'], dtype=object)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"classes = np.unique(labels)\n",
"classes"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "9bbd7813",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>file_name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>4.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4067</th>\n",
" <td>4067.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4068</th>\n",
" <td>4068.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4069</th>\n",
" <td>4069.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4070</th>\n",
" <td>4070.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4071</th>\n",
" <td>4071.png</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>4072 rows × 1 columns</p>\n",
"</div>"
],
"text/plain": [
" file_name\n",
"0 0.png\n",
"1 1.png\n",
"2 2.png\n",
"3 3.png\n",
"4 4.png\n",
"... ...\n",
"4067 4067.png\n",
"4068 4068.png\n",
"4069 4069.png\n",
"4070 4070.png\n",
"4071 4071.png\n",
"\n",
"[4072 rows x 1 columns]"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"filenames = []\n",
"for i in range(len(labels)):\n",
" filenames.append(str(i) + '.png')\n",
"d = {'file_name':filenames}\n",
"filenames = pd.DataFrame(d)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "e84e5c50",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"X_train,X_test,Y_train,Y_test=train_test_split(filenames,labels,test_size=0.20,stratify=labels,random_state=42)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "2e9f5520",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(3257, 1) (815, 1)\n"
]
}
],
"source": [
"print(X_train.shape,X_test.shape)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "a20e7180",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"label \n",
"with_mask 2585\n",
"without_mask 574\n",
"mask_weared_incorrect 98\n",
"dtype: int64"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Y_train.value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "634ae5c2",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\Piotrek\\AppData\\Local\\Temp/ipykernel_1696/91195937.py:1: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" X_train['label']=Y_train\n",
"C:\\Users\\Piotrek\\AppData\\Local\\Temp/ipykernel_1696/91195937.py:2: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" X_test['label']=Y_test\n"
]
}
],
"source": [
"X_train['label']=Y_train\n",
"X_test['label']=Y_test"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "5ce58a3e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>file_name</th>\n",
" <th>label</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1660</th>\n",
" <td>1660.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2976</th>\n",
" <td>2976.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>920</th>\n",
" <td>920.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3984</th>\n",
" <td>3984.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3867</th>\n",
" <td>3867.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>530</th>\n",
" <td>530.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1344</th>\n",
" <td>1344.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1756</th>\n",
" <td>1756.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1196</th>\n",
" <td>1196.png</td>\n",
" <td>without_mask</td>\n",
" </tr>\n",
" <tr>\n",
" <th>364</th>\n",
" <td>364.png</td>\n",
" <td>with_mask</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>815 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" file_name label\n",
"1660 1660.png with_mask\n",
"2976 2976.png with_mask\n",
"920 920.png with_mask\n",
"3984 3984.png with_mask\n",
"3867 3867.png with_mask\n",
"... ... ...\n",
"530 530.png with_mask\n",
"1344 1344.png with_mask\n",
"1756 1756.png with_mask\n",
"1196 1196.png without_mask\n",
"364 364.png with_mask\n",
"\n",
"[815 rows x 2 columns]"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X_test"
]
},
{
"cell_type": "code",
"execution_count": 164,
"id": "54aa844d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found 3257 validated image filenames belonging to 3 classes.\n"
]
}
],
"source": [
"from keras_preprocessing.image import ImageDataGenerator\n",
"\n",
"image_target_size = (int(128), int(128))\n",
"\n",
"train_image_generator = ImageDataGenerator(rescale = 1. / 255.)\n",
"\n",
"train_generator = train_image_generator.flow_from_dataframe(\n",
" dataframe = X_train,\n",
" directory = TRAIN_DATA_DIR,\n",
" x_col = 'file_name',\n",
" y_col = 'label',\n",
" subset = 'training',\n",
" batch_size = 32,\n",
" seed = 42,\n",
" shuffle = True,\n",
" class_mode = 'categorical',\n",
" target_size = image_target_size\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 165,
"id": "4c8f1393",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'mask_weared_incorrect': 0, 'with_mask': 1, 'without_mask': 2}"
]
},
"execution_count": 165,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"class_ind=train_generator.class_indices\n",
"class_ind"
]
},
{
"cell_type": "code",
"execution_count": 166,
"id": "40429c13",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found 815 validated image filenames belonging to 3 classes.\n"
]
}
],
"source": [
"test_image_generator = ImageDataGenerator(rescale = 1. / 255.)\n",
"\n",
"test_generator = train_image_generator.flow_from_dataframe(\n",
" dataframe = X_test,\n",
" directory = TRAIN_DATA_DIR,\n",
" x_col = 'file_name',\n",
" y_col = 'label',\n",
" batch_size = 32,\n",
" seed = 42,\n",
" shuffle = True,\n",
" class_mode = 'categorical',\n",
" target_size = image_target_size\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 167,
"id": "f3dc7458",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'mask_weared_incorrect': 0, 'with_mask': 1, 'without_mask': 2}"
]
},
"execution_count": 167,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train_generator.class_indices"
]
},
{
"cell_type": "code",
"execution_count": 145,
"id": "e91a0899",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARNING:tensorflow:`input_shape` is undefined or non-square, or `rows` is not in [96, 128, 160, 192, 224]. Weights for input shape (224, 224) will be loaded as the default.\n"
]
}
],
"source": [
"from tensorflow.keras.applications import MobileNetV2\n",
"from tensorflow.keras.layers import Input\n",
"input_tensor = Input(shape=(128, 128, 3))\n",
"mobileNet = MobileNetV2(weights=\"imagenet\", include_top=False,input_tensor=input_tensor)"
]
},
{
"cell_type": "code",
"execution_count": 146,
"id": "9efeef8c",
"metadata": {},
"outputs": [],
"source": [
"from tensorflow.keras.layers import AveragePooling2D"
]
},
{
"cell_type": "code",
"execution_count": 150,
"id": "59fb5432",
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow import keras\n",
"from tensorflow.keras import layers\n",
"\n",
"x = mobileNet.output\n",
"x = AveragePooling2D(pool_size=(4, 4))(x)\n",
"x = layers.Flatten()(x)\n",
"x = layers.Dense(256, activation=\"relu\")(x)\n",
"x = layers.Dropout(0.5)(x)\n",
"x = layers.Dense(64, activation=\"relu\")(x)\n",
"outputs = layers.Dense(3,activation='softmax')(x)\n",
"model = keras.Model(inputs=mobileNet.input, outputs=outputs)"
]
},
{
"cell_type": "code",
"execution_count": 151,
"id": "4fb27b1f",
"metadata": {},
"outputs": [],
"source": [
"for layer in mobileNet.layers:\n",
" layer.trainable = False"
]
},
{
"cell_type": "code",
"execution_count": 152,
"id": "d06c0841",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/15\n",
"102/102 [==============================] - 31s 277ms/step - loss: 0.5791 - accuracy: 0.8001 - val_loss: 0.4123 - val_accuracy: 0.8466\n",
"Epoch 2/15\n",
"102/102 [==============================] - 27s 270ms/step - loss: 0.4334 - accuracy: 0.8342 - val_loss: 0.3737 - val_accuracy: 0.8466\n",
"Epoch 3/15\n",
"102/102 [==============================] - 28s 271ms/step - loss: 0.3859 - accuracy: 0.8505 - val_loss: 0.3362 - val_accuracy: 0.8847\n",
"Epoch 4/15\n",
"102/102 [==============================] - 28s 270ms/step - loss: 0.3585 - accuracy: 0.8591 - val_loss: 0.3520 - val_accuracy: 0.8540\n",
"Epoch 5/15\n",
"102/102 [==============================] - 28s 273ms/step - loss: 0.3224 - accuracy: 0.8806 - val_loss: 0.3561 - val_accuracy: 0.8503\n",
"Epoch 6/15\n",
"102/102 [==============================] - 27s 270ms/step - loss: 0.3080 - accuracy: 0.8766 - val_loss: 0.3010 - val_accuracy: 0.8798\n",
"Epoch 7/15\n",
"102/102 [==============================] - 30s 291ms/step - loss: 0.2779 - accuracy: 0.8870 - val_loss: 0.2870 - val_accuracy: 0.8982\n",
"Epoch 8/15\n",
"102/102 [==============================] - 32s 319ms/step - loss: 0.2697 - accuracy: 0.8971 - val_loss: 0.3190 - val_accuracy: 0.8847\n",
"Epoch 9/15\n",
"102/102 [==============================] - 32s 312ms/step - loss: 0.2526 - accuracy: 0.9011 - val_loss: 0.2778 - val_accuracy: 0.8945\n",
"Epoch 10/15\n",
"102/102 [==============================] - 31s 304ms/step - loss: 0.2416 - accuracy: 0.9073 - val_loss: 0.2891 - val_accuracy: 0.8883\n",
"Epoch 11/15\n",
"102/102 [==============================] - 31s 303ms/step - loss: 0.2325 - accuracy: 0.9100 - val_loss: 0.2945 - val_accuracy: 0.8933\n",
"Epoch 12/15\n",
"102/102 [==============================] - 31s 302ms/step - loss: 0.2156 - accuracy: 0.9128 - val_loss: 0.2748 - val_accuracy: 0.9067\n",
"Epoch 13/15\n",
"102/102 [==============================] - 33s 328ms/step - loss: 0.2105 - accuracy: 0.9211 - val_loss: 0.3212 - val_accuracy: 0.8994\n",
"Epoch 14/15\n",
"102/102 [==============================] - 32s 311ms/step - loss: 0.1986 - accuracy: 0.9171 - val_loss: 0.2914 - val_accuracy: 0.9043\n",
"Epoch 15/15\n",
"102/102 [==============================] - 32s 311ms/step - loss: 0.2002 - accuracy: 0.9254 - val_loss: 0.2541 - val_accuracy: 0.9117\n"
]
}
],
"source": [
"model.compile(loss = 'categorical_crossentropy',\n",
" optimizer = keras.optimizers.Adam(lr=0.001),\n",
" metrics = ['accuracy'])\n",
"\n",
"history_1 = model.fit(train_generator, epochs = 15, steps_per_epoch = len(train_generator),\n",
" validation_data = test_generator, validation_steps = len(test_generator))"
]
},
{
"cell_type": "code",
"execution_count": 162,
"id": "0225e0bd",
"metadata": {},
"outputs": [],
"source": [
"model.save('face_mask_detection2.h5')"
]
},
{
"cell_type": "code",
"execution_count": 163,
"id": "a2216268",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Model: \"model_8\"\n",
"__________________________________________________________________________________________________\n",
" Layer (type) Output Shape Param # Connected to \n",
"==================================================================================================\n",
" input_17 (InputLayer) [(None, 128, 128, 3 0 [] \n",
" )] \n",
" \n",
" Conv1 (Conv2D) (None, 64, 64, 32) 864 ['input_17[0][0]'] \n",
" \n",
" bn_Conv1 (BatchNormalization) (None, 64, 64, 32) 128 ['Conv1[0][0]'] \n",
" \n",
" Conv1_relu (ReLU) (None, 64, 64, 32) 0 ['bn_Conv1[0][0]'] \n",
" \n",
" expanded_conv_depthwise (Depth (None, 64, 64, 32) 288 ['Conv1_relu[0][0]'] \n",
" wiseConv2D) \n",
" \n",
" expanded_conv_depthwise_BN (Ba (None, 64, 64, 32) 128 ['expanded_conv_depthwise[0][0]']\n",
" tchNormalization) \n",
" \n",
" expanded_conv_depthwise_relu ( (None, 64, 64, 32) 0 ['expanded_conv_depthwise_BN[0][0\n",
" ReLU) ]'] \n",
" \n",
" expanded_conv_project (Conv2D) (None, 64, 64, 16) 512 ['expanded_conv_depthwise_relu[0]\n",
" [0]'] \n",
" \n",
" expanded_conv_project_BN (Batc (None, 64, 64, 16) 64 ['expanded_conv_project[0][0]'] \n",
" hNormalization) \n",
" \n",
" block_1_expand (Conv2D) (None, 64, 64, 96) 1536 ['expanded_conv_project_BN[0][0]'\n",
" ] \n",
" \n",
" block_1_expand_BN (BatchNormal (None, 64, 64, 96) 384 ['block_1_expand[0][0]'] \n",
" ization) \n",
" \n",
" block_1_expand_relu (ReLU) (None, 64, 64, 96) 0 ['block_1_expand_BN[0][0]'] \n",
" \n",
" block_1_pad (ZeroPadding2D) (None, 65, 65, 96) 0 ['block_1_expand_relu[0][0]'] \n",
" \n",
" block_1_depthwise (DepthwiseCo (None, 32, 32, 96) 864 ['block_1_pad[0][0]'] \n",
" nv2D) \n",
" \n",
" block_1_depthwise_BN (BatchNor (None, 32, 32, 96) 384 ['block_1_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_1_depthwise_relu (ReLU) (None, 32, 32, 96) 0 ['block_1_depthwise_BN[0][0]'] \n",
" \n",
" block_1_project (Conv2D) (None, 32, 32, 24) 2304 ['block_1_depthwise_relu[0][0]'] \n",
" \n",
" block_1_project_BN (BatchNorma (None, 32, 32, 24) 96 ['block_1_project[0][0]'] \n",
" lization) \n",
" \n",
" block_2_expand (Conv2D) (None, 32, 32, 144) 3456 ['block_1_project_BN[0][0]'] \n",
" \n",
" block_2_expand_BN (BatchNormal (None, 32, 32, 144) 576 ['block_2_expand[0][0]'] \n",
" ization) \n",
" \n",
" block_2_expand_relu (ReLU) (None, 32, 32, 144) 0 ['block_2_expand_BN[0][0]'] \n",
" \n",
" block_2_depthwise (DepthwiseCo (None, 32, 32, 144) 1296 ['block_2_expand_relu[0][0]'] \n",
" nv2D) \n",
" \n",
" block_2_depthwise_BN (BatchNor (None, 32, 32, 144) 576 ['block_2_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_2_depthwise_relu (ReLU) (None, 32, 32, 144) 0 ['block_2_depthwise_BN[0][0]'] \n",
" \n",
" block_2_project (Conv2D) (None, 32, 32, 24) 3456 ['block_2_depthwise_relu[0][0]'] \n",
" \n",
" block_2_project_BN (BatchNorma (None, 32, 32, 24) 96 ['block_2_project[0][0]'] \n",
" lization) \n",
" \n",
" block_2_add (Add) (None, 32, 32, 24) 0 ['block_1_project_BN[0][0]', \n",
" 'block_2_project_BN[0][0]'] \n",
" \n",
" block_3_expand (Conv2D) (None, 32, 32, 144) 3456 ['block_2_add[0][0]'] \n",
" \n",
" block_3_expand_BN (BatchNormal (None, 32, 32, 144) 576 ['block_3_expand[0][0]'] \n",
" ization) \n",
" \n",
" block_3_expand_relu (ReLU) (None, 32, 32, 144) 0 ['block_3_expand_BN[0][0]'] \n",
" \n",
" block_3_pad (ZeroPadding2D) (None, 33, 33, 144) 0 ['block_3_expand_relu[0][0]'] \n",
" \n",
" block_3_depthwise (DepthwiseCo (None, 16, 16, 144) 1296 ['block_3_pad[0][0]'] \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" nv2D) \n",
" \n",
" block_3_depthwise_BN (BatchNor (None, 16, 16, 144) 576 ['block_3_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_3_depthwise_relu (ReLU) (None, 16, 16, 144) 0 ['block_3_depthwise_BN[0][0]'] \n",
" \n",
" block_3_project (Conv2D) (None, 16, 16, 32) 4608 ['block_3_depthwise_relu[0][0]'] \n",
" \n",
" block_3_project_BN (BatchNorma (None, 16, 16, 32) 128 ['block_3_project[0][0]'] \n",
" lization) \n",
" \n",
" block_4_expand (Conv2D) (None, 16, 16, 192) 6144 ['block_3_project_BN[0][0]'] \n",
" \n",
" block_4_expand_BN (BatchNormal (None, 16, 16, 192) 768 ['block_4_expand[0][0]'] \n",
" ization) \n",
" \n",
" block_4_expand_relu (ReLU) (None, 16, 16, 192) 0 ['block_4_expand_BN[0][0]'] \n",
" \n",
" block_4_depthwise (DepthwiseCo (None, 16, 16, 192) 1728 ['block_4_expand_relu[0][0]'] \n",
" nv2D) \n",
" \n",
" block_4_depthwise_BN (BatchNor (None, 16, 16, 192) 768 ['block_4_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_4_depthwise_relu (ReLU) (None, 16, 16, 192) 0 ['block_4_depthwise_BN[0][0]'] \n",
" \n",
" block_4_project (Conv2D) (None, 16, 16, 32) 6144 ['block_4_depthwise_relu[0][0]'] \n",
" \n",
" block_4_project_BN (BatchNorma (None, 16, 16, 32) 128 ['block_4_project[0][0]'] \n",
" lization) \n",
" \n",
" block_4_add (Add) (None, 16, 16, 32) 0 ['block_3_project_BN[0][0]', \n",
" 'block_4_project_BN[0][0]'] \n",
" \n",
" block_5_expand (Conv2D) (None, 16, 16, 192) 6144 ['block_4_add[0][0]'] \n",
" \n",
" block_5_expand_BN (BatchNormal (None, 16, 16, 192) 768 ['block_5_expand[0][0]'] \n",
" ization) \n",
" \n",
" block_5_expand_relu (ReLU) (None, 16, 16, 192) 0 ['block_5_expand_BN[0][0]'] \n",
" \n",
" block_5_depthwise (DepthwiseCo (None, 16, 16, 192) 1728 ['block_5_expand_relu[0][0]'] \n",
" nv2D) \n",
" \n",
" block_5_depthwise_BN (BatchNor (None, 16, 16, 192) 768 ['block_5_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_5_depthwise_relu (ReLU) (None, 16, 16, 192) 0 ['block_5_depthwise_BN[0][0]'] \n",
" \n",
" block_5_project (Conv2D) (None, 16, 16, 32) 6144 ['block_5_depthwise_relu[0][0]'] \n",
" \n",
" block_5_project_BN (BatchNorma (None, 16, 16, 32) 128 ['block_5_project[0][0]'] \n",
" lization) \n",
" \n",
" block_5_add (Add) (None, 16, 16, 32) 0 ['block_4_add[0][0]', \n",
" 'block_5_project_BN[0][0]'] \n",
" \n",
" block_6_expand (Conv2D) (None, 16, 16, 192) 6144 ['block_5_add[0][0]'] \n",
" \n",
" block_6_expand_BN (BatchNormal (None, 16, 16, 192) 768 ['block_6_expand[0][0]'] \n",
" ization) \n",
" \n",
" block_6_expand_relu (ReLU) (None, 16, 16, 192) 0 ['block_6_expand_BN[0][0]'] \n",
" \n",
" block_6_pad (ZeroPadding2D) (None, 17, 17, 192) 0 ['block_6_expand_relu[0][0]'] \n",
" \n",
" block_6_depthwise (DepthwiseCo (None, 8, 8, 192) 1728 ['block_6_pad[0][0]'] \n",
" nv2D) \n",
" \n",
" block_6_depthwise_BN (BatchNor (None, 8, 8, 192) 768 ['block_6_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_6_depthwise_relu (ReLU) (None, 8, 8, 192) 0 ['block_6_depthwise_BN[0][0]'] \n",
" \n",
" block_6_project (Conv2D) (None, 8, 8, 64) 12288 ['block_6_depthwise_relu[0][0]'] \n",
" \n",
" block_6_project_BN (BatchNorma (None, 8, 8, 64) 256 ['block_6_project[0][0]'] \n",
" lization) \n",
" \n",
" block_7_expand (Conv2D) (None, 8, 8, 384) 24576 ['block_6_project_BN[0][0]'] \n",
" \n",
" block_7_expand_BN (BatchNormal (None, 8, 8, 384) 1536 ['block_7_expand[0][0]'] \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" ization) \n",
" \n",
" block_7_expand_relu (ReLU) (None, 8, 8, 384) 0 ['block_7_expand_BN[0][0]'] \n",
" \n",
" block_7_depthwise (DepthwiseCo (None, 8, 8, 384) 3456 ['block_7_expand_relu[0][0]'] \n",
" nv2D) \n",
" \n",
" block_7_depthwise_BN (BatchNor (None, 8, 8, 384) 1536 ['block_7_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_7_depthwise_relu (ReLU) (None, 8, 8, 384) 0 ['block_7_depthwise_BN[0][0]'] \n",
" \n",
" block_7_project (Conv2D) (None, 8, 8, 64) 24576 ['block_7_depthwise_relu[0][0]'] \n",
" \n",
" block_7_project_BN (BatchNorma (None, 8, 8, 64) 256 ['block_7_project[0][0]'] \n",
" lization) \n",
" \n",
" block_7_add (Add) (None, 8, 8, 64) 0 ['block_6_project_BN[0][0]', \n",
" 'block_7_project_BN[0][0]'] \n",
" \n",
" block_8_expand (Conv2D) (None, 8, 8, 384) 24576 ['block_7_add[0][0]'] \n",
" \n",
" block_8_expand_BN (BatchNormal (None, 8, 8, 384) 1536 ['block_8_expand[0][0]'] \n",
" ization) \n",
" \n",
" block_8_expand_relu (ReLU) (None, 8, 8, 384) 0 ['block_8_expand_BN[0][0]'] \n",
" \n",
" block_8_depthwise (DepthwiseCo (None, 8, 8, 384) 3456 ['block_8_expand_relu[0][0]'] \n",
" nv2D) \n",
" \n",
" block_8_depthwise_BN (BatchNor (None, 8, 8, 384) 1536 ['block_8_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_8_depthwise_relu (ReLU) (None, 8, 8, 384) 0 ['block_8_depthwise_BN[0][0]'] \n",
" \n",
" block_8_project (Conv2D) (None, 8, 8, 64) 24576 ['block_8_depthwise_relu[0][0]'] \n",
" \n",
" block_8_project_BN (BatchNorma (None, 8, 8, 64) 256 ['block_8_project[0][0]'] \n",
" lization) \n",
" \n",
" block_8_add (Add) (None, 8, 8, 64) 0 ['block_7_add[0][0]', \n",
" 'block_8_project_BN[0][0]'] \n",
" \n",
" block_9_expand (Conv2D) (None, 8, 8, 384) 24576 ['block_8_add[0][0]'] \n",
" \n",
" block_9_expand_BN (BatchNormal (None, 8, 8, 384) 1536 ['block_9_expand[0][0]'] \n",
" ization) \n",
" \n",
" block_9_expand_relu (ReLU) (None, 8, 8, 384) 0 ['block_9_expand_BN[0][0]'] \n",
" \n",
" block_9_depthwise (DepthwiseCo (None, 8, 8, 384) 3456 ['block_9_expand_relu[0][0]'] \n",
" nv2D) \n",
" \n",
" block_9_depthwise_BN (BatchNor (None, 8, 8, 384) 1536 ['block_9_depthwise[0][0]'] \n",
" malization) \n",
" \n",
" block_9_depthwise_relu (ReLU) (None, 8, 8, 384) 0 ['block_9_depthwise_BN[0][0]'] \n",
" \n",
" block_9_project (Conv2D) (None, 8, 8, 64) 24576 ['block_9_depthwise_relu[0][0]'] \n",
" \n",
" block_9_project_BN (BatchNorma (None, 8, 8, 64) 256 ['block_9_project[0][0]'] \n",
" lization) \n",
" \n",
" block_9_add (Add) (None, 8, 8, 64) 0 ['block_8_add[0][0]', \n",
" 'block_9_project_BN[0][0]'] \n",
" \n",
" block_10_expand (Conv2D) (None, 8, 8, 384) 24576 ['block_9_add[0][0]'] \n",
" \n",
" block_10_expand_BN (BatchNorma (None, 8, 8, 384) 1536 ['block_10_expand[0][0]'] \n",
" lization) \n",
" \n",
" block_10_expand_relu (ReLU) (None, 8, 8, 384) 0 ['block_10_expand_BN[0][0]'] \n",
" \n",
" block_10_depthwise (DepthwiseC (None, 8, 8, 384) 3456 ['block_10_expand_relu[0][0]'] \n",
" onv2D) \n",
" \n",
" block_10_depthwise_BN (BatchNo (None, 8, 8, 384) 1536 ['block_10_depthwise[0][0]'] \n",
" rmalization) \n",
" \n",
" block_10_depthwise_relu (ReLU) (None, 8, 8, 384) 0 ['block_10_depthwise_BN[0][0]'] \n",
" \n",
" block_10_project (Conv2D) (None, 8, 8, 96) 36864 ['block_10_depthwise_relu[0][0]']\n",
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" block_10_project_BN (BatchNorm (None, 8, 8, 96) 384 ['block_10_project[0][0]'] \n",
" alization) \n",
" \n",
" block_11_expand (Conv2D) (None, 8, 8, 576) 55296 ['block_10_project_BN[0][0]'] \n",
" \n",
" block_11_expand_BN (BatchNorma (None, 8, 8, 576) 2304 ['block_11_expand[0][0]'] \n",
" lization) \n",
" \n",
" block_11_expand_relu (ReLU) (None, 8, 8, 576) 0 ['block_11_expand_BN[0][0]'] \n",
" \n",
" block_11_depthwise (DepthwiseC (None, 8, 8, 576) 5184 ['block_11_expand_relu[0][0]'] \n",
" onv2D) \n",
" \n",
" block_11_depthwise_BN (BatchNo (None, 8, 8, 576) 2304 ['block_11_depthwise[0][0]'] \n",
" rmalization) \n",
" \n",
" block_11_depthwise_relu (ReLU) (None, 8, 8, 576) 0 ['block_11_depthwise_BN[0][0]'] \n",
" \n",
" block_11_project (Conv2D) (None, 8, 8, 96) 55296 ['block_11_depthwise_relu[0][0]']\n",
" \n",
" block_11_project_BN (BatchNorm (None, 8, 8, 96) 384 ['block_11_project[0][0]'] \n",
" alization) \n",
" \n",
" block_11_add (Add) (None, 8, 8, 96) 0 ['block_10_project_BN[0][0]', \n",
" 'block_11_project_BN[0][0]'] \n",
" \n",
" block_12_expand (Conv2D) (None, 8, 8, 576) 55296 ['block_11_add[0][0]'] \n",
" \n",
" block_12_expand_BN (BatchNorma (None, 8, 8, 576) 2304 ['block_12_expand[0][0]'] \n",
" lization) \n",
" \n",
" block_12_expand_relu (ReLU) (None, 8, 8, 576) 0 ['block_12_expand_BN[0][0]'] \n",
" \n",
" block_12_depthwise (DepthwiseC (None, 8, 8, 576) 5184 ['block_12_expand_relu[0][0]'] \n",
" onv2D) \n",
" \n",
" block_12_depthwise_BN (BatchNo (None, 8, 8, 576) 2304 ['block_12_depthwise[0][0]'] \n",
" rmalization) \n",
" \n",
" block_12_depthwise_relu (ReLU) (None, 8, 8, 576) 0 ['block_12_depthwise_BN[0][0]'] \n",
" \n",
" block_12_project (Conv2D) (None, 8, 8, 96) 55296 ['block_12_depthwise_relu[0][0]']\n",
" \n",
" block_12_project_BN (BatchNorm (None, 8, 8, 96) 384 ['block_12_project[0][0]'] \n",
" alization) \n",
" \n",
" block_12_add (Add) (None, 8, 8, 96) 0 ['block_11_add[0][0]', \n",
" 'block_12_project_BN[0][0]'] \n",
" \n",
" block_13_expand (Conv2D) (None, 8, 8, 576) 55296 ['block_12_add[0][0]'] \n",
" \n",
" block_13_expand_BN (BatchNorma (None, 8, 8, 576) 2304 ['block_13_expand[0][0]'] \n",
" lization) \n",
" \n",
" block_13_expand_relu (ReLU) (None, 8, 8, 576) 0 ['block_13_expand_BN[0][0]'] \n",
" \n",
" block_13_pad (ZeroPadding2D) (None, 9, 9, 576) 0 ['block_13_expand_relu[0][0]'] \n",
" \n",
" block_13_depthwise (DepthwiseC (None, 4, 4, 576) 5184 ['block_13_pad[0][0]'] \n",
" onv2D) \n",
" \n",
" block_13_depthwise_BN (BatchNo (None, 4, 4, 576) 2304 ['block_13_depthwise[0][0]'] \n",
" rmalization) \n",
" \n",
" block_13_depthwise_relu (ReLU) (None, 4, 4, 576) 0 ['block_13_depthwise_BN[0][0]'] \n",
" \n",
" block_13_project (Conv2D) (None, 4, 4, 160) 92160 ['block_13_depthwise_relu[0][0]']\n",
" \n",
" block_13_project_BN (BatchNorm (None, 4, 4, 160) 640 ['block_13_project[0][0]'] \n",
" alization) \n",
" \n",
" block_14_expand (Conv2D) (None, 4, 4, 960) 153600 ['block_13_project_BN[0][0]'] \n",
" \n",
" block_14_expand_BN (BatchNorma (None, 4, 4, 960) 3840 ['block_14_expand[0][0]'] \n",
" lization) \n",
" \n",
" block_14_expand_relu (ReLU) (None, 4, 4, 960) 0 ['block_14_expand_BN[0][0]'] \n",
" \n",
" block_14_depthwise (DepthwiseC (None, 4, 4, 960) 8640 ['block_14_expand_relu[0][0]'] \n",
" onv2D) \n",
" \n",
" block_14_depthwise_BN (BatchNo (None, 4, 4, 960) 3840 ['block_14_depthwise[0][0]'] \n",
" rmalization) \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" \n",
" block_14_depthwise_relu (ReLU) (None, 4, 4, 960) 0 ['block_14_depthwise_BN[0][0]'] \n",
" \n",
" block_14_project (Conv2D) (None, 4, 4, 160) 153600 ['block_14_depthwise_relu[0][0]']\n",
" \n",
" block_14_project_BN (BatchNorm (None, 4, 4, 160) 640 ['block_14_project[0][0]'] \n",
" alization) \n",
" \n",
" block_14_add (Add) (None, 4, 4, 160) 0 ['block_13_project_BN[0][0]', \n",
" 'block_14_project_BN[0][0]'] \n",
" \n",
" block_15_expand (Conv2D) (None, 4, 4, 960) 153600 ['block_14_add[0][0]'] \n",
" \n",
" block_15_expand_BN (BatchNorma (None, 4, 4, 960) 3840 ['block_15_expand[0][0]'] \n",
" lization) \n",
" \n",
" block_15_expand_relu (ReLU) (None, 4, 4, 960) 0 ['block_15_expand_BN[0][0]'] \n",
" \n",
" block_15_depthwise (DepthwiseC (None, 4, 4, 960) 8640 ['block_15_expand_relu[0][0]'] \n",
" onv2D) \n",
" \n",
" block_15_depthwise_BN (BatchNo (None, 4, 4, 960) 3840 ['block_15_depthwise[0][0]'] \n",
" rmalization) \n",
" \n",
" block_15_depthwise_relu (ReLU) (None, 4, 4, 960) 0 ['block_15_depthwise_BN[0][0]'] \n",
" \n",
" block_15_project (Conv2D) (None, 4, 4, 160) 153600 ['block_15_depthwise_relu[0][0]']\n",
" \n",
" block_15_project_BN (BatchNorm (None, 4, 4, 160) 640 ['block_15_project[0][0]'] \n",
" alization) \n",
" \n",
" block_15_add (Add) (None, 4, 4, 160) 0 ['block_14_add[0][0]', \n",
" 'block_15_project_BN[0][0]'] \n",
" \n",
" block_16_expand (Conv2D) (None, 4, 4, 960) 153600 ['block_15_add[0][0]'] \n",
" \n",
" block_16_expand_BN (BatchNorma (None, 4, 4, 960) 3840 ['block_16_expand[0][0]'] \n",
" lization) \n",
" \n",
" block_16_expand_relu (ReLU) (None, 4, 4, 960) 0 ['block_16_expand_BN[0][0]'] \n",
" \n",
" block_16_depthwise (DepthwiseC (None, 4, 4, 960) 8640 ['block_16_expand_relu[0][0]'] \n",
" onv2D) \n",
" \n",
" block_16_depthwise_BN (BatchNo (None, 4, 4, 960) 3840 ['block_16_depthwise[0][0]'] \n",
" rmalization) \n",
" \n",
" block_16_depthwise_relu (ReLU) (None, 4, 4, 960) 0 ['block_16_depthwise_BN[0][0]'] \n",
" \n",
" block_16_project (Conv2D) (None, 4, 4, 320) 307200 ['block_16_depthwise_relu[0][0]']\n",
" \n",
" block_16_project_BN (BatchNorm (None, 4, 4, 320) 1280 ['block_16_project[0][0]'] \n",
" alization) \n",
" \n",
" Conv_1 (Conv2D) (None, 4, 4, 1280) 409600 ['block_16_project_BN[0][0]'] \n",
" \n",
" Conv_1_bn (BatchNormalization) (None, 4, 4, 1280) 5120 ['Conv_1[0][0]'] \n",
" \n",
" out_relu (ReLU) (None, 4, 4, 1280) 0 ['Conv_1_bn[0][0]'] \n",
" \n",
" average_pooling2d_22 (AverageP (None, 1, 1, 1280) 0 ['out_relu[0][0]'] \n",
" ooling2D) \n",
" \n",
" flatten_9 (Flatten) (None, 1280) 0 ['average_pooling2d_22[0][0]'] \n",
" \n",
" dense_27 (Dense) (None, 256) 327936 ['flatten_9[0][0]'] \n",
" \n",
" dropout_9 (Dropout) (None, 256) 0 ['dense_27[0][0]'] \n",
" \n",
" dense_28 (Dense) (None, 64) 16448 ['dropout_9[0][0]'] \n",
" \n",
" dense_29 (Dense) (None, 3) 195 ['dense_28[0][0]'] \n",
" \n",
"==================================================================================================\n",
"Total params: 2,602,563\n",
"Trainable params: 344,579\n",
"Non-trainable params: 2,257,984\n",
"__________________________________________________________________________________________________\n"
]
}
],
"source": [
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": 154,
"id": "e361de12",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"26/26 [==============================] - 6s 213ms/step - loss: 0.2541 - accuracy: 0.9117\n",
"Test loss: 0.2540619671344757 / Test accuracy: 0.9116564393043518\n"
]
}
],
"source": [
"score = model.evaluate(test_generator)\n",
"print(f'Test loss: {score[0]} / Test accuracy: {score[1]}')"
]
},
{
"cell_type": "code",
"execution_count": 172,
"id": "d911dded",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x22b800e0a90>"
]
},
"execution_count": 172,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAACgCAYAAAAWy/vJAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAtUklEQVR4nO3dd3yV9fn4/9eVkBBCQgJJgECAIIShsgQZKoqiOBBHbakD62irVq22H22t/dTa8ennZz/falvbumpVrLgXKKCIomBFkQ2ygggkhJFBQ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BRmQeIQiO3tffaEWydxiJcwvKQR1ze0MdeqLIX9m2C3Tx1CWb5b1i0FBp3r4h1wJiQMdhUwIRbUBCEiFwF/BcKBp1X1oXrLuwPPAIOAMuBmVd3oz7bGmIblFJW7ZJBZwIY9+azPLOCA10krTCCtZyxThvZkZEocI/rGMTy5W5M6i4VE7tcuAayZA5XFcNIUuOxRGDTVXVlXVcDetXVX4hvfgFXPum3jB7iTbqqXMLoPDO7Jt6wAsrdBzlbI3lL3+uAuwOtp3WMQDJ9Rl8S6DwhePCdAVPX4azVnxyLhwDbgAiAT+BK4RlU3+azz/4AiVf2tiAwD/qGqU/3ZtiHjxo1Tm3LUdCR5xRVs2OMVE2XmsyGzgKyCMsCdAwclxTCybxwjvGRwcp9ubacJqKprwrn8H7BlPoR1gpEzYeKPoPeIxretqYb9G4+s4C3Nc8tik70rde9qPWlY8xJGcY6XALa6R473XLi3bp3wSEhIg6Sh3mMY9J/o7npaCRFZparjGloWzL+U8cB2Vd3hBfEycDnge5I/Gfj/AFR1i4ikikg
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"from matplotlib import pyplot as plt\n",
"plt.subplot(2,1,1)\n",
"plt.plot(history_1.history['accuracy'])\n",
"plt.plot(history_1.history['val_accuracy'])\n",
"plt.title('model accuracy')\n",
"plt.ylabel('accuracy')\n",
"plt.xlabel('epoch')\n",
"plt.legend(['train', 'test'], loc='lower right')"
]
},
{
"cell_type": "code",
"execution_count": 174,
"id": "537b6db4",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAA8BElEQVR4nO3dd3xUZfb48c/JJCGVUJJQEpqU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W3aNO655x5Wr179g7LGGBNoNt13FY53dz1yrLROzUye032PHz+eKVOmcPbZZwMQExPDa6+9xo4dO7j33nsJCQkhLCyMp59+GoDp06czfvx42rVrZzepjTEBZ9N9V+NIYSl7co5yRnw0MRFhvgjRr2y6b2NMbdl036cpplkoIkJ+sU3eZ4xpeixBVMMVIkSH2+yuxpimqUkkiLo0o8VGhFFUWk5JWf2e3bUxNRUaY+qHRp8gIiIiyMnJOe0P0NgI5z5+fZ68T1XJyckhIiIi2KEYYxqRRt+LKTk5mfT0dOoykV/OkSLy9gmtY3wzHsIfIiIiSE5ODnYYxphGpNEniLCwMLp06VKnc8x8Zz1vr87g24fG0CzU5aPIjDGmfmv0TUy+MDolkWMl5az47nCwQzHGmICxBFEDZ3dtTbgrhEVbs4IdijHGBIwliBqICg9l2BmtWGgJwhjThFiCqKFRKYnszD5K2iFbwMcY0zRYgqih0SnOanXWzGSMaSosQdRQl/hoOraKYtHWuq97bYwxDYEliBoSEUanJPDVzoMUldZ9rWpjjKnvLEHUwqiURIpKK1j+3aFgh2KMMX7n1wQ
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(history_1.history['loss'])\n",
"plt.plot(history_1.history['val_loss'])\n",
"plt.title('model loss')\n",
"plt.ylabel('loss')\n",
"plt.xlabel('epoch')\n",
"plt.legend(['train', 'test'], loc='upper left')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "90bd07ae",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}