From 59b2b9e6871e46d209b36972c74d0502901a973d Mon Sep 17 00:00:00 2001 From: Maciej Sobkowiak Date: Wed, 16 Feb 2022 22:08:44 +0100 Subject: [PATCH] working generators + model tests --- src/__import__.py | 3 +- src/consts.py | 8 +-- src/loss.py | 2 +- src/setup.py | 1 - unet.ipynb | 125 +++++++++++++++++++++++++++++++++++++++------- 5 files changed, 114 insertions(+), 25 deletions(-) diff --git a/src/__import__.py b/src/__import__.py index 503a4f6..063293f 100644 --- a/src/__import__.py +++ b/src/__import__.py @@ -1,2 +1,3 @@ from consts import * -from helpers import * \ No newline at end of file +from helpers import * +from metrics import * \ No newline at end of file diff --git a/src/consts.py b/src/consts.py index 0234dbd..580f9b9 100644 --- a/src/consts.py +++ b/src/consts.py @@ -2,10 +2,10 @@ import pandas as pd FEATURES ='../data/train_features' LABELS = '../data/train_labels' JPG_IMAGES = '../images' -RGB_DIR = "rgb" -FC_DIR = "fc" -MASK_DIR = "mask" -METADATA = pd.read_csv('../data/train_metadata.csv') +RGB_DIR = "rgb/img" +FC_DIR = "fc/img" +MASK_DIR = "mask/img" +# METADATA = pd.read_csv('../data/train_metadata.csv') BATCH = 8 IMG_SIZE = (512,512) diff --git a/src/loss.py b/src/loss.py index 242037b..49a91c5 100644 --- a/src/loss.py +++ b/src/loss.py @@ -1,5 +1,5 @@ import tensorflow as tf -from metrics import IOU +from src.metrics import IOU class jaccard_loss(tf.keras.losses.Loss): diff --git a/src/setup.py b/src/setup.py index 8db2fa4..33ca1bc 100644 --- a/src/setup.py +++ b/src/setup.py @@ -25,6 +25,5 @@ if __name__ == "__main__": if(not os.path.exists(os.path.join(dp, d +'.jpeg')) or not os.path.exists(os.path.join(fc, d +'.jpeg')) or not os.path.exists(os.path.join(mk, d +'.jpeg'))): convert_tif_to_jpg(os.path.join(FEATURES, d), os.path.join(LABELS, d + ".tif"), dp, fc, mk) elif(sys.argv[1] == '--show'): - img_names = [random.choice(os.listdir(dp)) for _ in range(3)] plot_image_grid(img_names) \ No newline at end of file diff --git a/unet.ipynb b/unet.ipynb index 1efc301..6b3ed52 100644 --- a/unet.ipynb +++ b/unet.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 20, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -14,6 +14,7 @@ "from tensorflow.keras.layers import Dense, Flatten, Input\n", "from tensorflow.keras.models import Model, Sequential, load_model\n", "from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau\n", + "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", @@ -25,27 +26,92 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "from src.metrics import IOU\n" + "from src.metrics import IOU\n", + "from src.consts import JPG_IMAGES, RGB_DIR, MASK_DIR\n" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "Found 9399 images belonging to 1 classes.\n", + "Found 9399 images belonging to 1 classes.\n", + "Found 2349 images belonging to 1 classes.\n", + "Found 2349 images belonging to 1 classes.\n" + ] + } + ], + "source": [ + "\n", + "# we create two instances with the same arguments\n", + "print(os.path.exists('./images/rgb'))\n", + "img_size = (512,512)\n", + "rgb_dir = os.path.join(\"images\", RGB_DIR)\n", + "mask_dir = os.path.join(\"images\", MASK_DIR)\n", + "\n", + "train_datagen = ImageDataGenerator(rescale=1 / 255.0,\n", + " horizontal_flip=True,\n", + " vertical_flip=True,\n", + " validation_split=0.2)\n", + "\n", + "# Provide the same seed and keyword arguments to the fit and flow methods\n", + "seed = 1\n", + "\n", + "image_generator = train_datagen.flow_from_directory(\n", + " './images/rgb',\n", + " class_mode=None,\n", + " # class_mode='binary',\n", + " seed=seed,\n", + " subset='training'\n", + " )\n", + "mask_generator = train_datagen.flow_from_directory(\n", + " './images/mask',\n", + " class_mode=None,\n", + " seed=seed,\n", + " subset='training'\n", + " )\n", + "image_generator_val = train_datagen.flow_from_directory(\n", + " './images/rgb',\n", + " class_mode=None,\n", + " # class_mode='binary',\n", + " seed=seed,\n", + " subset='validation'\n", + " )\n", + "mask_generator_val = train_datagen.flow_from_directory(\n", + " './images/mask',\n", + " class_mode=None,\n", + " seed=seed,\n", + " subset='validation'\n", + " )\n", + "\n", + "train_gen = zip(image_generator, mask_generator)\n", + "val_gen = zip(image_generator_val, mask_generator_val)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "IMG_HEIGHT = 512\n", "IMG_WIDTH = 512\n", - "img_dir = '/images'" + "# img_dir = '/images'" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -62,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -117,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -126,18 +192,43 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 15, "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'jaccard_loss' is not defined", + "name": "stdout", + "output_type": "stream", + "text": [ + "You must install pydot (`pip install pydot`) and install graphviz (see instructions at https://graphviz.gitlab.io/download/) for plot_model/model_to_dot to work.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\masob\\AppData\\Local\\Temp\\ipykernel_21092\\68410389.py:22: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.\n", + " history = model.fit_generator(train_gen,\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epoch 1/30\n" + ] + }, + { + "ename": "InvalidArgumentError", + "evalue": "Graph execution error:\n\nDetected at node 'gradient_tape/model_6/concatenate_18/ConcatOffset' defined at (most recent call last):\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\runpy.py\", line 197, in _run_module_as_main\n return _run_code(code, main_globals, None,\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel_launcher.py\", line 16, in \n app.launch_new_instance()\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\traitlets\\config\\application.py\", line 846, in launch_instance\n app.start()\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 677, in start\n self.io_loop.start()\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 199, in start\n self.asyncio_loop.run_forever()\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\asyncio\\base_events.py\", line 596, in run_forever\n self._run_once()\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\asyncio\\base_events.py\", line 1890, in _run_once\n handle._run()\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\asyncio\\events.py\", line 80, in _run\n self._context.run(self._callback, *self._args)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 461, in dispatch_queue\n await self.process_one()\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 450, in process_one\n await dispatch(*args)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 357, in dispatch_shell\n await result\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 652, in execute_request\n reply_content = await reply_content\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\ipkernel.py\", line 359, in do_execute\n res = shell.run_cell(code, store_history=store_history, silent=silent)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\zmqshell.py\", line 532, in run_cell\n return super().run_cell(*args, **kwargs)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2768, in run_cell\n result = self._run_cell(\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2814, in _run_cell\n return runner(coro)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\async_helpers.py\", line 129, in _pseudo_sync_runner\n coro.send(None)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3012, in run_cell_async\n has_raised = await self.run_ast_nodes(code_ast.body, cell_name,\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3191, in run_ast_nodes\n if await self.run_code(code, result, async_=asy):\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3251, in run_code\n exec(code_obj, self.user_global_ns, self.user_ns)\n File \"C:\\Users\\masob\\AppData\\Local\\Temp\\ipykernel_21092\\68410389.py\", line 22, in \n history = model.fit_generator(train_gen,\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 2209, in fit_generator\n return self.fit(\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\utils\\traceback_utils.py\", line 64, in error_handler\n return fn(*args, **kwargs)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1384, in fit\n tmp_logs = self.train_function(iterator)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1021, in train_function\n return step_function(self, iterator)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1010, in step_function\n outputs = model.distribute_strategy.run(run_step, args=(data,))\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1000, in run_step\n outputs = model.train_step(data)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 863, in train_step\n self.optimizer.minimize(loss, self.trainable_variables, tape=tape)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\optimizer_v2\\optimizer_v2.py\", line 530, in minimize\n grads_and_vars = self._compute_gradients(\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\optimizer_v2\\optimizer_v2.py\", line 583, in _compute_gradients\n grads_and_vars = self._get_gradients(tape, loss, var_list, grad_loss)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\optimizer_v2\\optimizer_v2.py\", line 464, in _get_gradients\n grads = tape.gradient(loss, var_list, grad_loss)\nNode: 'gradient_tape/model_6/concatenate_18/ConcatOffset'\nAll dimensions except 3 must match. Input 1 has shape [32 64 64 128] and doesn't match input 0 with shape [32 128 128 128].\n\t [[{{node gradient_tape/model_6/concatenate_18/ConcatOffset}}]] [Op:__inference_train_function_8358]", "output_type": "error", "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/Users/patrycjalazna/Desktop/wko-projekt/unet.ipynb Cell 7'\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m model \u001b[39m=\u001b[39m Unet(num_classes\u001b[39m=\u001b[39m\u001b[39m1\u001b[39m)\u001b[39m.\u001b[39mbuild_model()\n\u001b[1;32m 3\u001b[0m compile_params \u001b[39m=\u001b[39m{\n\u001b[0;32m----> 4\u001b[0m \u001b[39m'\u001b[39m\u001b[39mloss\u001b[39m\u001b[39m'\u001b[39m:jaccard_loss(smooth\u001b[39m=\u001b[39m\u001b[39m90\u001b[39m), \n\u001b[1;32m 5\u001b[0m \u001b[39m'\u001b[39m\u001b[39moptimizer\u001b[39m\u001b[39m'\u001b[39m:\u001b[39m'\u001b[39m\u001b[39mrmsprop\u001b[39m\u001b[39m'\u001b[39m,\n\u001b[1;32m 6\u001b[0m \u001b[39m'\u001b[39m\u001b[39mmetrics\u001b[39m\u001b[39m'\u001b[39m:[IOU]\n\u001b[1;32m 7\u001b[0m }\n\u001b[1;32m 10\u001b[0m model\u001b[39m.\u001b[39mcompile(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mcompile_params)\n\u001b[1;32m 12\u001b[0m tf\u001b[39m.\u001b[39mkeras\u001b[39m.\u001b[39mutils\u001b[39m.\u001b[39mplot_model(model, show_shapes\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n", - "\u001b[0;31mNameError\u001b[0m: name 'jaccard_loss' is not defined" + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mInvalidArgumentError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32mc:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\unet.ipynb Cell 9'\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 14\u001b[0m model_name \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mmodels/unet.h5\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 15\u001b[0m modelcheckpoint \u001b[39m=\u001b[39m ModelCheckpoint(model_name,\n\u001b[0;32m 16\u001b[0m monitor\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mval_loss\u001b[39m\u001b[39m'\u001b[39m,\n\u001b[0;32m 17\u001b[0m mode\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mauto\u001b[39m\u001b[39m'\u001b[39m,\n\u001b[0;32m 18\u001b[0m verbose\u001b[39m=\u001b[39m\u001b[39m1\u001b[39m,\n\u001b[0;32m 19\u001b[0m save_best_only\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n\u001b[1;32m---> 22\u001b[0m history \u001b[39m=\u001b[39m model\u001b[39m.\u001b[39;49mfit_generator(train_gen,\n\u001b[0;32m 23\u001b[0m validation_data\u001b[39m=\u001b[39;49mval_gen,\n\u001b[0;32m 24\u001b[0m epochs\u001b[39m=\u001b[39;49mEPOCHS,\n\u001b[0;32m 25\u001b[0m steps_per_epoch\u001b[39m=\u001b[39;49m\u001b[39m100\u001b[39;49m,\n\u001b[0;32m 26\u001b[0m validation_steps \u001b[39m=\u001b[39;49m \u001b[39m100\u001b[39;49m,\n\u001b[0;32m 27\u001b[0m shuffle\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m,\n\u001b[0;32m 28\u001b[0m )\n", + "File \u001b[1;32mc:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py:2209\u001b[0m, in \u001b[0;36mModel.fit_generator\u001b[1;34m(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)\u001b[0m\n\u001b[0;32m 2198\u001b[0m \u001b[39m\"\"\"Fits the model on data yielded batch-by-batch by a Python generator.\u001b[39;00m\n\u001b[0;32m 2199\u001b[0m \n\u001b[0;32m 2200\u001b[0m \u001b[39mDEPRECATED:\u001b[39;00m\n\u001b[0;32m 2201\u001b[0m \u001b[39m `Model.fit` now supports generators, so there is no longer any need to use\u001b[39;00m\n\u001b[0;32m 2202\u001b[0m \u001b[39m this endpoint.\u001b[39;00m\n\u001b[0;32m 2203\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m 2204\u001b[0m warnings\u001b[39m.\u001b[39mwarn(\n\u001b[0;32m 2205\u001b[0m \u001b[39m'\u001b[39m\u001b[39m`Model.fit_generator` is deprecated and \u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m 2206\u001b[0m \u001b[39m'\u001b[39m\u001b[39mwill be removed in a future version. \u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m 2207\u001b[0m \u001b[39m'\u001b[39m\u001b[39mPlease use `Model.fit`, which supports generators.\u001b[39m\u001b[39m'\u001b[39m,\n\u001b[0;32m 2208\u001b[0m stacklevel\u001b[39m=\u001b[39m\u001b[39m2\u001b[39m)\n\u001b[1;32m-> 2209\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mfit(\n\u001b[0;32m 2210\u001b[0m generator,\n\u001b[0;32m 2211\u001b[0m steps_per_epoch\u001b[39m=\u001b[39;49msteps_per_epoch,\n\u001b[0;32m 2212\u001b[0m epochs\u001b[39m=\u001b[39;49mepochs,\n\u001b[0;32m 2213\u001b[0m verbose\u001b[39m=\u001b[39;49mverbose,\n\u001b[0;32m 2214\u001b[0m callbacks\u001b[39m=\u001b[39;49mcallbacks,\n\u001b[0;32m 2215\u001b[0m validation_data\u001b[39m=\u001b[39;49mvalidation_data,\n\u001b[0;32m 2216\u001b[0m validation_steps\u001b[39m=\u001b[39;49mvalidation_steps,\n\u001b[0;32m 2217\u001b[0m validation_freq\u001b[39m=\u001b[39;49mvalidation_freq,\n\u001b[0;32m 2218\u001b[0m class_weight\u001b[39m=\u001b[39;49mclass_weight,\n\u001b[0;32m 2219\u001b[0m max_queue_size\u001b[39m=\u001b[39;49mmax_queue_size,\n\u001b[0;32m 2220\u001b[0m workers\u001b[39m=\u001b[39;49mworkers,\n\u001b[0;32m 2221\u001b[0m use_multiprocessing\u001b[39m=\u001b[39;49muse_multiprocessing,\n\u001b[0;32m 2222\u001b[0m shuffle\u001b[39m=\u001b[39;49mshuffle,\n\u001b[0;32m 2223\u001b[0m initial_epoch\u001b[39m=\u001b[39;49minitial_epoch)\n", + "File \u001b[1;32mc:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\utils\\traceback_utils.py:67\u001b[0m, in \u001b[0;36mfilter_traceback..error_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 65\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m e: \u001b[39m# pylint: disable=broad-except\u001b[39;00m\n\u001b[0;32m 66\u001b[0m filtered_tb \u001b[39m=\u001b[39m _process_traceback_frames(e\u001b[39m.\u001b[39m__traceback__)\n\u001b[1;32m---> 67\u001b[0m \u001b[39mraise\u001b[39;00m e\u001b[39m.\u001b[39mwith_traceback(filtered_tb) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39m\n\u001b[0;32m 68\u001b[0m \u001b[39mfinally\u001b[39;00m:\n\u001b[0;32m 69\u001b[0m \u001b[39mdel\u001b[39;00m filtered_tb\n", + "File \u001b[1;32mc:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\tensorflow\\python\\eager\\execute.py:54\u001b[0m, in \u001b[0;36mquick_execute\u001b[1;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m 53\u001b[0m ctx\u001b[39m.\u001b[39mensure_initialized()\n\u001b[1;32m---> 54\u001b[0m tensors \u001b[39m=\u001b[39m pywrap_tfe\u001b[39m.\u001b[39mTFE_Py_Execute(ctx\u001b[39m.\u001b[39m_handle, device_name, op_name,\n\u001b[0;32m 55\u001b[0m inputs, attrs, num_outputs)\n\u001b[0;32m 56\u001b[0m \u001b[39mexcept\u001b[39;00m core\u001b[39m.\u001b[39m_NotOkStatusException \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m 57\u001b[0m \u001b[39mif\u001b[39;00m name \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n", + "\u001b[1;31mInvalidArgumentError\u001b[0m: Graph execution error:\n\nDetected at node 'gradient_tape/model_6/concatenate_18/ConcatOffset' defined at (most recent call last):\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\runpy.py\", line 197, in _run_module_as_main\n return _run_code(code, main_globals, None,\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel_launcher.py\", line 16, in \n app.launch_new_instance()\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\traitlets\\config\\application.py\", line 846, in launch_instance\n app.start()\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 677, in start\n self.io_loop.start()\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 199, in start\n self.asyncio_loop.run_forever()\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\asyncio\\base_events.py\", line 596, in run_forever\n self._run_once()\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\asyncio\\base_events.py\", line 1890, in _run_once\n handle._run()\n File \"C:\\Users\\masob\\AppData\\Local\\Programs\\Python\\Python39\\lib\\asyncio\\events.py\", line 80, in _run\n self._context.run(self._callback, *self._args)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 461, in dispatch_queue\n await self.process_one()\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 450, in process_one\n await dispatch(*args)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 357, in dispatch_shell\n await result\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 652, in execute_request\n reply_content = await reply_content\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\ipkernel.py\", line 359, in do_execute\n res = shell.run_cell(code, store_history=store_history, silent=silent)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\ipykernel\\zmqshell.py\", line 532, in run_cell\n return super().run_cell(*args, **kwargs)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2768, in run_cell\n result = self._run_cell(\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2814, in _run_cell\n return runner(coro)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\async_helpers.py\", line 129, in _pseudo_sync_runner\n coro.send(None)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3012, in run_cell_async\n has_raised = await self.run_ast_nodes(code_ast.body, cell_name,\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3191, in run_ast_nodes\n if await self.run_code(code, result, async_=asy):\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3251, in run_code\n exec(code_obj, self.user_global_ns, self.user_ns)\n File \"C:\\Users\\masob\\AppData\\Local\\Temp\\ipykernel_21092\\68410389.py\", line 22, in \n history = model.fit_generator(train_gen,\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 2209, in fit_generator\n return self.fit(\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\utils\\traceback_utils.py\", line 64, in error_handler\n return fn(*args, **kwargs)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1384, in fit\n tmp_logs = self.train_function(iterator)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1021, in train_function\n return step_function(self, iterator)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1010, in step_function\n outputs = model.distribute_strategy.run(run_step, args=(data,))\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1000, in run_step\n outputs = model.train_step(data)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 863, in train_step\n self.optimizer.minimize(loss, self.trainable_variables, tape=tape)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\optimizer_v2\\optimizer_v2.py\", line 530, in minimize\n grads_and_vars = self._compute_gradients(\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\optimizer_v2\\optimizer_v2.py\", line 583, in _compute_gradients\n grads_and_vars = self._get_gradients(tape, loss, var_list, grad_loss)\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\optimizer_v2\\optimizer_v2.py\", line 464, in _get_gradients\n grads = tape.gradient(loss, var_list, grad_loss)\nNode: 'gradient_tape/model_6/concatenate_18/ConcatOffset'\nAll dimensions except 3 must match. Input 1 has shape [32 64 64 128] and doesn't match input 0 with shape [32 128 128 128].\n\t [[{{node gradient_tape/model_6/concatenate_18/ConcatOffset}}]] [Op:__inference_train_function_8358]" ] } ], @@ -156,7 +247,6 @@ "tf.keras.utils.plot_model(model, show_shapes=True)\n", "\n", "model_name = \"models/unet.h5\"\n", - "\n", "modelcheckpoint = ModelCheckpoint(model_name,\n", " monitor='val_loss',\n", " mode='auto',\n", @@ -170,7 +260,6 @@ " steps_per_epoch=100,\n", " validation_steps = 100,\n", " shuffle=True,\n", - " validation_freq=1\n", ")" ] } @@ -194,7 +283,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.9.0" }, "orig_nbformat": 4 },