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|
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"from tensorflow.keras.models import Sequential\n",
|
| 11 |
+
"from tensorflow.keras.layers import Dense, Activation, Conv2D, Flatten, Dropout, MaxPooling2D, BatchNormalization\n",
|
| 12 |
+
"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
|
| 13 |
+
"from keras import regularizers, optimizers\n",
|
| 14 |
+
"import os\n",
|
| 15 |
+
"import numpy as np\n",
|
| 16 |
+
"import matplotlib.pyplot as plt\n",
|
| 17 |
+
"import pandas as pd\n",
|
| 18 |
+
"import tensorflow as tf"
|
| 19 |
+
]
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"cell_type": "code",
|
| 23 |
+
"execution_count": 24,
|
| 24 |
+
"id": "115fbe9d-ffac-4286-99c6-aef6daf10e98",
|
| 25 |
+
"metadata": {},
|
| 26 |
+
"outputs": [],
|
| 27 |
+
"source": [
|
| 28 |
+
"traindf = pd.read_csv('train.csv', dtype=str)"
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"cell_type": "code",
|
| 33 |
+
"execution_count": 25,
|
| 34 |
+
"id": "3b7916cf-92c3-4283-a399-79f562ac05d7",
|
| 35 |
+
"metadata": {},
|
| 36 |
+
"outputs": [
|
| 37 |
+
{
|
| 38 |
+
"data": {
|
| 39 |
+
"text/html": [
|
| 40 |
+
"<div>\n",
|
| 41 |
+
"<style scoped>\n",
|
| 42 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 43 |
+
" vertical-align: middle;\n",
|
| 44 |
+
" }\n",
|
| 45 |
+
"\n",
|
| 46 |
+
" .dataframe tbody tr th {\n",
|
| 47 |
+
" vertical-align: top;\n",
|
| 48 |
+
" }\n",
|
| 49 |
+
"\n",
|
| 50 |
+
" .dataframe thead th {\n",
|
| 51 |
+
" text-align: right;\n",
|
| 52 |
+
" }\n",
|
| 53 |
+
"</style>\n",
|
| 54 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 55 |
+
" <thead>\n",
|
| 56 |
+
" <tr style=\"text-align: right;\">\n",
|
| 57 |
+
" <th></th>\n",
|
| 58 |
+
" <th>id</th>\n",
|
| 59 |
+
" <th>label</th>\n",
|
| 60 |
+
" </tr>\n",
|
| 61 |
+
" </thead>\n",
|
| 62 |
+
" <tbody>\n",
|
| 63 |
+
" <tr>\n",
|
| 64 |
+
" <th>0</th>\n",
|
| 65 |
+
" <td>0.jpg</td>\n",
|
| 66 |
+
" <td>1</td>\n",
|
| 67 |
+
" </tr>\n",
|
| 68 |
+
" <tr>\n",
|
| 69 |
+
" <th>1</th>\n",
|
| 70 |
+
" <td>1.jpg</td>\n",
|
| 71 |
+
" <td>1</td>\n",
|
| 72 |
+
" </tr>\n",
|
| 73 |
+
" <tr>\n",
|
| 74 |
+
" <th>2</th>\n",
|
| 75 |
+
" <td>2.jpg</td>\n",
|
| 76 |
+
" <td>1</td>\n",
|
| 77 |
+
" </tr>\n",
|
| 78 |
+
" <tr>\n",
|
| 79 |
+
" <th>3</th>\n",
|
| 80 |
+
" <td>3.jpg</td>\n",
|
| 81 |
+
" <td>0</td>\n",
|
| 82 |
+
" </tr>\n",
|
| 83 |
+
" <tr>\n",
|
| 84 |
+
" <th>4</th>\n",
|
| 85 |
+
" <td>4.jpg</td>\n",
|
| 86 |
+
" <td>1</td>\n",
|
| 87 |
+
" </tr>\n",
|
| 88 |
+
" </tbody>\n",
|
| 89 |
+
"</table>\n",
|
| 90 |
+
"</div>"
|
| 91 |
+
],
|
| 92 |
+
"text/plain": [
|
| 93 |
+
" id label\n",
|
| 94 |
+
"0 0.jpg 1\n",
|
| 95 |
+
"1 1.jpg 1\n",
|
| 96 |
+
"2 2.jpg 1\n",
|
| 97 |
+
"3 3.jpg 0\n",
|
| 98 |
+
"4 4.jpg 1"
|
| 99 |
+
]
|
| 100 |
+
},
|
| 101 |
+
"execution_count": 25,
|
| 102 |
+
"metadata": {},
|
| 103 |
+
"output_type": "execute_result"
|
| 104 |
+
}
|
| 105 |
+
],
|
| 106 |
+
"source": [
|
| 107 |
+
"traindf.head()"
|
| 108 |
+
]
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"cell_type": "code",
|
| 112 |
+
"execution_count": 26,
|
| 113 |
+
"id": "fdc54499-54c8-4493-9745-c49bb3990563",
|
| 114 |
+
"metadata": {},
|
| 115 |
+
"outputs": [],
|
| 116 |
+
"source": [
|
| 117 |
+
"batch_size=32"
|
| 118 |
+
]
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"cell_type": "code",
|
| 122 |
+
"execution_count": 27,
|
| 123 |
+
"id": "4503212b-c3cd-419f-be8b-cd22b8b2d9b9",
|
| 124 |
+
"metadata": {},
|
| 125 |
+
"outputs": [
|
| 126 |
+
{
|
| 127 |
+
"name": "stdout",
|
| 128 |
+
"output_type": "stream",
|
| 129 |
+
"text": [
|
| 130 |
+
"Found 13964 validated image filenames belonging to 2 classes.\n"
|
| 131 |
+
]
|
| 132 |
+
}
|
| 133 |
+
],
|
| 134 |
+
"source": [
|
| 135 |
+
"datagen=ImageDataGenerator(rescale=1./255.,validation_split=0.25)\n",
|
| 136 |
+
"\n",
|
| 137 |
+
"train_generator=datagen.flow_from_dataframe(\n",
|
| 138 |
+
" dataframe=traindf,\n",
|
| 139 |
+
" directory=\"train\",\n",
|
| 140 |
+
" x_col=\"id\",\n",
|
| 141 |
+
" y_col=\"label\",\n",
|
| 142 |
+
" subset=\"training\",\n",
|
| 143 |
+
" batch_size=32,\n",
|
| 144 |
+
" seed=42,\n",
|
| 145 |
+
" shuffle=True,\n",
|
| 146 |
+
" class_mode=\"binary\",\n",
|
| 147 |
+
" target_size=(150,150))"
|
| 148 |
+
]
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"cell_type": "code",
|
| 152 |
+
"execution_count": 28,
|
| 153 |
+
"id": "e27ae24f-f80a-4854-8de0-2e4370d72436",
|
| 154 |
+
"metadata": {},
|
| 155 |
+
"outputs": [
|
| 156 |
+
{
|
| 157 |
+
"name": "stdout",
|
| 158 |
+
"output_type": "stream",
|
| 159 |
+
"text": [
|
| 160 |
+
"Found 4654 validated image filenames belonging to 2 classes.\n"
|
| 161 |
+
]
|
| 162 |
+
}
|
| 163 |
+
],
|
| 164 |
+
"source": [
|
| 165 |
+
"validation_generator=datagen.flow_from_dataframe(\n",
|
| 166 |
+
" dataframe=traindf,\n",
|
| 167 |
+
" directory=\"train\",\n",
|
| 168 |
+
" x_col=\"id\",\n",
|
| 169 |
+
" y_col=\"label\",\n",
|
| 170 |
+
" subset=\"validation\",\n",
|
| 171 |
+
" batch_size=32,\n",
|
| 172 |
+
" seed=42,\n",
|
| 173 |
+
" shuffle=True,\n",
|
| 174 |
+
" class_mode=\"binary\",\n",
|
| 175 |
+
" target_size=(150,150))"
|
| 176 |
+
]
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"cell_type": "code",
|
| 180 |
+
"execution_count": 29,
|
| 181 |
+
"id": "cfba6463-0d9c-4ee1-b95d-d4dbc5d6ed9a",
|
| 182 |
+
"metadata": {},
|
| 183 |
+
"outputs": [],
|
| 184 |
+
"source": [
|
| 185 |
+
"model = tf.keras.Sequential([\n",
|
| 186 |
+
" # tf.keras.Input((150, 150)),\n",
|
| 187 |
+
" tf.keras.layers.Dense(units=63, activation='relu'),\n",
|
| 188 |
+
" tf.keras.layers.Dropout(0.2),\n",
|
| 189 |
+
" tf.keras.layers.Dense(units=128, activation='relu'),\n",
|
| 190 |
+
" tf.keras.layers.Dense(units=256, activation='relu'),\n",
|
| 191 |
+
" tf.keras.layers.Dense(units=512, activation='relu'),\n",
|
| 192 |
+
" tf.keras.layers.Dense(units=512, activation='relu'),\n",
|
| 193 |
+
" tf.keras.layers.Dropout(0.2),\n",
|
| 194 |
+
" tf.keras.layers.Dense(units=256, activation='relu'),\n",
|
| 195 |
+
" tf.keras.layers.Dense(units=128, activation='relu'),\n",
|
| 196 |
+
" tf.keras.layers.Dropout(0.2),\n",
|
| 197 |
+
" tf.keras.layers.Dense(units=64, activation='relu'),\n",
|
| 198 |
+
" tf.keras.layers.Flatten(),\n",
|
| 199 |
+
" tf.keras.layers.Dense(1, activation=\"sigmoid\")\n",
|
| 200 |
+
"])"
|
| 201 |
+
]
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
"cell_type": "code",
|
| 205 |
+
"execution_count": 30,
|
| 206 |
+
"id": "a69f9725-42ed-442a-87b5-8e425354fb7c",
|
| 207 |
+
"metadata": {},
|
| 208 |
+
"outputs": [],
|
| 209 |
+
"source": [
|
| 210 |
+
"# Define a Callback class that stops training once accuracy reaches 99.9%\n",
|
| 211 |
+
"class myCallback(tf.keras.callbacks.Callback):\n",
|
| 212 |
+
" def on_epoch_end(self, epoch, logs={}):\n",
|
| 213 |
+
" if(logs.get('accuracy')>0.999):\n",
|
| 214 |
+
" print(\"\\nReached 99.9% accuracy so cancelling training!\")\n",
|
| 215 |
+
" self.model.stop_training = True"
|
| 216 |
+
]
|
| 217 |
+
},
|
| 218 |
+
{
|
| 219 |
+
"cell_type": "code",
|
| 220 |
+
"execution_count": 31,
|
| 221 |
+
"id": "cdbba06b-f587-4b6a-9bd6-eb4d8ac09d57",
|
| 222 |
+
"metadata": {},
|
| 223 |
+
"outputs": [],
|
| 224 |
+
"source": [
|
| 225 |
+
"model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])"
|
| 226 |
+
]
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"cell_type": "code",
|
| 230 |
+
"execution_count": 32,
|
| 231 |
+
"id": "77890825-86c0-4dae-b3f2-83829c0926f3",
|
| 232 |
+
"metadata": {},
|
| 233 |
+
"outputs": [
|
| 234 |
+
{
|
| 235 |
+
"name": "stdout",
|
| 236 |
+
"output_type": "stream",
|
| 237 |
+
"text": [
|
| 238 |
+
"Epoch 1/20\n",
|
| 239 |
+
" 7/436 [..............................] - ETA: 4:25:45 - loss: 0.7909 - accuracy: 0.5938"
|
| 240 |
+
]
|
| 241 |
+
},
|
| 242 |
+
{
|
| 243 |
+
"ename": "KeyboardInterrupt",
|
| 244 |
+
"evalue": "",
|
| 245 |
+
"output_type": "error",
|
| 246 |
+
"traceback": [
|
| 247 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 248 |
+
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
| 249 |
+
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_23852\\693444859.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m model.fit(\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[0mtrain_generator\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0msteps_per_epoch\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtrain_generator\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msamples\u001b[0m \u001b[1;33m//\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 250 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\keras\\utils\\traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 63\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 65\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 66\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 67\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 251 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[0;32m 1648\u001b[0m ):\n\u001b[0;32m 1649\u001b[0m \u001b[0mcallbacks\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mon_train_batch_begin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstep\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1650\u001b[1;33m \u001b[0mtmp_logs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtrain_function\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1651\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshould_sync\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1652\u001b[0m \u001b[0mcontext\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0masync_wait\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 252 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\tensorflow\\python\\util\\traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 148\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 149\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 150\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 151\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 152\u001b[0m \u001b[0mfiltered_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 253 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\polymorphic_function.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m 878\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 879\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mOptionalXlaContext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_jit_compile\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 880\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 881\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 882\u001b[0m \u001b[0mnew_tracing_count\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexperimental_get_tracing_count\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 254 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\polymorphic_function.py\u001b[0m in \u001b[0;36m_call\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m 910\u001b[0m \u001b[1;31m# In this case we have created variables on the first call, so we run the\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 911\u001b[0m \u001b[1;31m# defunned version which is guaranteed to never create variables.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 912\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_no_variable_creation_fn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# pylint: disable=not-callable\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 913\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_variable_creation_fn\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 914\u001b[0m \u001b[1;31m# Release the lock early so that multiple threads can perform the call\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 255 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\tracing_compiler.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 132\u001b[0m (concrete_function,\n\u001b[0;32m 133\u001b[0m filtered_flat_args) = self._maybe_define_function(args, kwargs)\n\u001b[1;32m--> 134\u001b[1;33m return concrete_function._call_flat(\n\u001b[0m\u001b[0;32m 135\u001b[0m filtered_flat_args, captured_inputs=concrete_function.captured_inputs) # pylint: disable=protected-access\n\u001b[0;32m 136\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 256 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\monomorphic_function.py\u001b[0m in \u001b[0;36m_call_flat\u001b[1;34m(self, args, captured_inputs, cancellation_manager)\u001b[0m\n\u001b[0;32m 1743\u001b[0m and executing_eagerly):\n\u001b[0;32m 1744\u001b[0m \u001b[1;31m# No tape is watching; skip to running the function.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1745\u001b[1;33m return self._build_call_outputs(self._inference_function.call(\n\u001b[0m\u001b[0;32m 1746\u001b[0m ctx, args, cancellation_manager=cancellation_manager))\n\u001b[0;32m 1747\u001b[0m forward_backward = self._select_forward_and_backward_functions(\n",
|
| 257 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\monomorphic_function.py\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self, ctx, args, cancellation_manager)\u001b[0m\n\u001b[0;32m 376\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0m_InterpolateFunctionError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 377\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcancellation_manager\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 378\u001b[1;33m outputs = execute.execute(\n\u001b[0m\u001b[0;32m 379\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msignature\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 380\u001b[0m \u001b[0mnum_outputs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_num_outputs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 258 |
+
"\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\tensorflow\\python\\eager\\execute.py\u001b[0m in \u001b[0;36mquick_execute\u001b[1;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[0;32m 50\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 51\u001b[0m \u001b[0mctx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mensure_initialized\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 52\u001b[1;33m tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,\n\u001b[0m\u001b[0;32m 53\u001b[0m inputs, attrs, num_outputs)\n\u001b[0;32m 54\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_NotOkStatusException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 259 |
+
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
| 260 |
+
]
|
| 261 |
+
}
|
| 262 |
+
],
|
| 263 |
+
"source": [
|
| 264 |
+
"callbacks = myCallback()\n",
|
| 265 |
+
"\n",
|
| 266 |
+
"\n",
|
| 267 |
+
"model.fit(\n",
|
| 268 |
+
" train_generator,\n",
|
| 269 |
+
" steps_per_epoch = train_generator.samples // batch_size,\n",
|
| 270 |
+
" validation_data = validation_generator, \n",
|
| 271 |
+
" validation_steps = validation_generator.samples // batch_size,\n",
|
| 272 |
+
" epochs = 20,\n",
|
| 273 |
+
" verbose = 1,\n",
|
| 274 |
+
" callbacks=[callbacks]\n",
|
| 275 |
+
")"
|
| 276 |
+
]
|
| 277 |
+
},
|
| 278 |
+
{
|
| 279 |
+
"cell_type": "code",
|
| 280 |
+
"execution_count": null,
|
| 281 |
+
"id": "dd79a5c8-f4e5-40cf-bea4-416177f19347",
|
| 282 |
+
"metadata": {},
|
| 283 |
+
"outputs": [],
|
| 284 |
+
"source": []
|
| 285 |
+
}
|
| 286 |
+
],
|
| 287 |
+
"metadata": {
|
| 288 |
+
"kernelspec": {
|
| 289 |
+
"display_name": "Python 3 (ipykernel)",
|
| 290 |
+
"language": "python",
|
| 291 |
+
"name": "python3"
|
| 292 |
+
},
|
| 293 |
+
"language_info": {
|
| 294 |
+
"codemirror_mode": {
|
| 295 |
+
"name": "ipython",
|
| 296 |
+
"version": 3
|
| 297 |
+
},
|
| 298 |
+
"file_extension": ".py",
|
| 299 |
+
"mimetype": "text/x-python",
|
| 300 |
+
"name": "python",
|
| 301 |
+
"nbconvert_exporter": "python",
|
| 302 |
+
"pygments_lexer": "ipython3",
|
| 303 |
+
"version": "3.9.13"
|
| 304 |
+
}
|
| 305 |
+
},
|
| 306 |
+
"nbformat": 4,
|
| 307 |
+
"nbformat_minor": 5
|
| 308 |
+
}
|