predict
This commit is contained in:
parent
f5da173dc9
commit
b35f0b879e
51
main.ipynb
51
main.ipynb
@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": 21,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -10,7 +10,7 @@
|
|||||||
"from src.Unet import Unet\n",
|
"from src.Unet import Unet\n",
|
||||||
"from src.loss import jaccard_loss\n",
|
"from src.loss import jaccard_loss\n",
|
||||||
"from src.metrics import IOU\n",
|
"from src.metrics import IOU\n",
|
||||||
"from src.consts import EPOCHS, STEPS, SEED, RGB_DIR, JPG_IMAGES, MASK_DIR\n",
|
"from src.consts import EPOCHS, STEPS, SEED, RGB_DIR, JPG_IMAGES, MASK_DIR, FC_DIR\n",
|
||||||
"from src.helpers import create_folder\n",
|
"from src.helpers import create_folder\n",
|
||||||
"from tensorflow.keras.callbacks import ModelCheckpoint\n",
|
"from tensorflow.keras.callbacks import ModelCheckpoint\n",
|
||||||
"import tensorflow as tf "
|
"import tensorflow as tf "
|
||||||
@ -171,32 +171,55 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 29,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"['wlfr.jpeg', 'tfxr.jpeg', 'yeaw.jpeg']\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ename": "ValueError",
|
||||||
|
"evalue": "in user code:\n\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1801, in predict_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 1790, 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 1783, in run_step **\n outputs = model.predict_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 1751, in predict_step\n return self(x, training=False)\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 67, in error_handler\n raise e.with_traceback(filtered_tb) from None\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\input_spec.py\", line 264, in assert_input_compatibility\n raise ValueError(f'Input {input_index} of layer \"{layer_name}\" is '\n\n ValueError: Input 0 of layer \"model\" is incompatible with the layer: expected shape=(None, 512, 512, 3), found shape=(32, 512, 3)\n",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"\u001b[1;32mc:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\main.ipynb Cell 7'\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/main.ipynb#ch0000005?line=6'>7</a>\u001b[0m r_img \u001b[39m=\u001b[39m cv2\u001b[39m.\u001b[39mimread(os\u001b[39m.\u001b[39mpath\u001b[39m.\u001b[39mjoin(\u001b[39m'\u001b[39m\u001b[39m./images/\u001b[39m\u001b[39m'\u001b[39m, RGB_DIR, img_names[\u001b[39m0\u001b[39m]))\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/main.ipynb#ch0000005?line=7'>8</a>\u001b[0m m_img \u001b[39m=\u001b[39m cv2\u001b[39m.\u001b[39mimread(os\u001b[39m.\u001b[39mpath\u001b[39m.\u001b[39mjoin(\u001b[39m'\u001b[39m\u001b[39m./images/\u001b[39m\u001b[39m'\u001b[39m, MASK_DIR, img_names[\u001b[39m0\u001b[39m]))\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/main.ipynb#ch0000005?line=8'>9</a>\u001b[0m pred \u001b[39m=\u001b[39m model\u001b[39m.\u001b[39;49mpredict(r_img)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/main.ipynb#ch0000005?line=10'>11</a>\u001b[0m fig,ax\u001b[39m=\u001b[39mplt\u001b[39m.\u001b[39msubplots(\u001b[39m1\u001b[39m,\u001b[39m3\u001b[39m,figsize\u001b[39m=\u001b[39m(\u001b[39m16\u001b[39m,\u001b[39m8\u001b[39m))\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/main.ipynb#ch0000005?line=12'>13</a>\u001b[0m ax[\u001b[39m0\u001b[39m]\u001b[39m.\u001b[39mset_title(\u001b[39m'\u001b[39m\u001b[39mRGB Image\u001b[39m\u001b[39m'\u001b[39m)\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.<locals>.error_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/keras/utils/traceback_utils.py?line=64'>65</a>\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 <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/keras/utils/traceback_utils.py?line=65'>66</a>\u001b[0m filtered_tb \u001b[39m=\u001b[39m _process_traceback_frames(e\u001b[39m.\u001b[39m__traceback__)\n\u001b[1;32m---> <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/keras/utils/traceback_utils.py?line=66'>67</a>\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 <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/keras/utils/traceback_utils.py?line=67'>68</a>\u001b[0m \u001b[39mfinally\u001b[39;00m:\n\u001b[0;32m <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/keras/utils/traceback_utils.py?line=68'>69</a>\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\\framework\\func_graph.py:1147\u001b[0m, in \u001b[0;36mfunc_graph_from_py_func.<locals>.autograph_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/tensorflow/python/framework/func_graph.py?line=1144'>1145</a>\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 <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/tensorflow/python/framework/func_graph.py?line=1145'>1146</a>\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(e, \u001b[39m\"\u001b[39m\u001b[39mag_error_metadata\u001b[39m\u001b[39m\"\u001b[39m):\n\u001b[1;32m-> <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/tensorflow/python/framework/func_graph.py?line=1146'>1147</a>\u001b[0m \u001b[39mraise\u001b[39;00m e\u001b[39m.\u001b[39mag_error_metadata\u001b[39m.\u001b[39mto_exception(e)\n\u001b[0;32m <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/tensorflow/python/framework/func_graph.py?line=1147'>1148</a>\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m <a href='file:///c%3A/Users/masob/Desktop/STUDIA/WIDZENIE%20KOMPUTEROWE/Projekt%20ON%20CLOUD/cloud-detection-challenge/venv/lib/site-packages/tensorflow/python/framework/func_graph.py?line=1148'>1149</a>\u001b[0m \u001b[39mraise\u001b[39;00m\n",
|
||||||
|
"\u001b[1;31mValueError\u001b[0m: in user code:\n\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\training.py\", line 1801, in predict_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 1790, 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 1783, in run_step **\n outputs = model.predict_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 1751, in predict_step\n return self(x, training=False)\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 67, in error_handler\n raise e.with_traceback(filtered_tb) from None\n File \"c:\\Users\\masob\\Desktop\\STUDIA\\WIDZENIE KOMPUTEROWE\\Projekt ON CLOUD\\cloud-detection-challenge\\venv\\lib\\site-packages\\keras\\engine\\input_spec.py\", line 264, in assert_input_compatibility\n raise ValueError(f'Input {input_index} of layer \"{layer_name}\" is '\n\n ValueError: Input 0 of layer \"model\" is incompatible with the layer: expected shape=(None, 512, 512, 3), found shape=(32, 512, 3)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"import random, os\n",
|
"import random, os\n",
|
||||||
"import cv2\n",
|
"import cv2\n",
|
||||||
"dp = create_folder(RGB_DIR, JPG_IMAGES)\n",
|
"import numpy as np\n",
|
||||||
"img_names = [random.choice(os.listdir(dp)) for _ in range(3)]\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"r_img = cv2.imread(os.path.join(JPG_IMAGES, RGB_DIR, img_names[0]))\n",
|
"img_names = [random.choice(os.listdir('./images/rgb/img')) for _ in range(3)]\n",
|
||||||
"m_img = cv2.imread(os.path.join(JPG_IMAGES, MASK_DIR, img))\n",
|
"print(img_names)\n",
|
||||||
|
"\n",
|
||||||
|
"r_img = cv2.imread(os.path.join('./images/', RGB_DIR, img_names[0]))\n",
|
||||||
|
"m_img = cv2.imread(os.path.join('./images/', MASK_DIR, img_names[0]))\n",
|
||||||
|
"img = np.expand_dims(r_img,axis=0)\n",
|
||||||
"pred = model.predict(r_img)\n",
|
"pred = model.predict(r_img)\n",
|
||||||
"\n",
|
|
||||||
"fig,ax=plt.subplots(1,3,figsize=(16,8))\n",
|
"fig,ax=plt.subplots(1,3,figsize=(16,8))\n",
|
||||||
"\n",
|
"\n",
|
||||||
"ax[0].set_title('RGB Image')\n",
|
"ax[0].set_title('RGB Image')\n",
|
||||||
"ax[0].imshow(img[0][0,:,:,::-1])\n",
|
"ax[0].imshow(r_img)\n",
|
||||||
"ax[0].axis('off')\n",
|
"ax[0].axis('off')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"ax[1].set_title('Original Mask')\n",
|
"ax[1].set_title('Original Mask')\n",
|
||||||
"ax[1].imshow(msk)\n",
|
"ax[1].imshow(m_img)\n",
|
||||||
"ax[1].axis('off')\n",
|
"ax[1].axis('off')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"ax[2].set_title('Predicted Mask')\n",
|
"# ax[2].set_title('Predicted Mask')\n",
|
||||||
"ax[2].axis('off')\n",
|
"# ax[2].axis('off')\n",
|
||||||
"ax[2].imshow(tf.keras.preprocessing.image.array_to_img(pred[0]>0.5),cmap='gray')\n",
|
"# ax[2].imshow(tf.keras.preprocessing.image.array_to_img(pred[0]>0.5),cmap='gray')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.show()\n"
|
"plt.show()\n"
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user