-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add notebook to test
2024-11-17-rev1-000
(#19)
* chore: add notebook to test `2024-11-17-rev1-000` * clear * adjust order
- Loading branch information
1 parent
8adecfd
commit 1b2dbf7
Showing
4 changed files
with
189 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"metadata": {}, | ||
"cell_type": "markdown", | ||
"source": "# Testing `2024-11-17-rev1-000` Model", | ||
"id": "f65cd8acf6ceeda7" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"source": [ | ||
"import sys\n", | ||
"import os\n", | ||
"\n", | ||
"colab = 'google.colab' in sys.modules" | ||
], | ||
"id": "8bbed4542154e55a", | ||
"outputs": [], | ||
"execution_count": null | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"source": [ | ||
"if colab:\n", | ||
" os.environ['PROJECT_DIR'] = project_dir = '/content/Foggy-CycleGAN'\n", | ||
" replace = True\n", | ||
" if os.path.isdir(project_dir):\n", | ||
" choice = input(\"Project already exists in folder \" +\n", | ||
" \"{}\\nDelete the files and pull again? Enter Y/(N):\\n\"\n", | ||
" .format(project_dir))\n", | ||
" if choice.lower() == 'y':\n", | ||
" !rm -r $PROJECT_DIR\n", | ||
" print(\"Deleted folder {}\".format(project_dir))\n", | ||
" else:\n", | ||
" replace = False\n", | ||
" print(\"Nothing was changed.\")\n", | ||
" if replace:\n", | ||
" !cd /content && git clone https://github.com/ghaiszaher/Foggy-CycleGAN.git\n", | ||
" print(\"Project cloned to \" + project_dir)\n", | ||
" os.chdir(project_dir)\n", | ||
" print(\"Done.\")" | ||
], | ||
"id": "febf3f49d71bb78a", | ||
"outputs": [], | ||
"execution_count": null | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"source": [ | ||
"from lib.tools import create_dir\n", | ||
"\n", | ||
"output = './weights/generator_clear2fog.weights.h5'\n", | ||
"if not os.path.exists(output):\n", | ||
" import gdown\n", | ||
" file_id = '10cBLNuofYGbyrC6DKRycD-fmx0Wh7BCr'\n", | ||
" create_dir('./weights/')\n", | ||
" print(\"Downloading weights...\")\n", | ||
" gdown.download(f'https://drive.google.com/uc?id={file_id}', output, quiet=False)\n", | ||
" print(\"Weights downloaded.\")\n", | ||
"else:\n", | ||
" print(\"Weights already downloaded.\")" | ||
], | ||
"id": "40bb017068d0d5a3", | ||
"outputs": [], | ||
"execution_count": null | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"source": [ | ||
"from lib.models import ModelsBuilder\n", | ||
"\n", | ||
"models_builder = ModelsBuilder()\n", | ||
"generator_clear2fog = models_builder.build_generator()\n", | ||
"generator_clear2fog.load_weights('./weights/generator_clear2fog.weights.h5')" | ||
], | ||
"id": "d3ffc8f1b4f3f6db", | ||
"outputs": [], | ||
"execution_count": null | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"source": [ | ||
"from lib.plot import plot_clear2fog_intensity\n", | ||
"import tensorflow as tf\n", | ||
"from lib.dataset import DatasetInitializer\n", | ||
"\n", | ||
"datasetInit = DatasetInitializer(256, 256)\n", | ||
"\n", | ||
"input_path = './custom-images/input/image.png' #@param {type:\"string\"}\n", | ||
"fog_intensity = 0.4 #@param {type:\"slider\", min:0.05, max:1.00, step:0.05}\n", | ||
"output_path = './custom-images/output/image.png' #@param {type:\"string\"}\n", | ||
"\n", | ||
"image_clear = tf.io.decode_png(tf.io.read_file(input_path), channels=3)\n", | ||
"image_clear, _ = datasetInit.preprocess_image_test(image_clear, 0)\n", | ||
"\n", | ||
"fig, foggy_image = plot_clear2fog_intensity(generator_clear2fog, image_clear, fog_intensity)\n", | ||
"foggy_image_uint8 = tf.image.convert_image_dtype(foggy_image, dtype=tf.uint8)\n", | ||
"encoded_image = tf.io.encode_png(foggy_image_uint8)\n", | ||
"tf.io.write_file(output_path, encoded_image)\n", | ||
"print(f\"Saved foggy image to {output_path}\")" | ||
], | ||
"id": "ed5c34bc882f2c05", | ||
"outputs": [], | ||
"execution_count": null | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters