Skip to content

Commit

Permalink
chore: add notebook to test 2024-11-17-rev1-000 (#19)
Browse files Browse the repository at this point in the history
* chore: add notebook to test `2024-11-17-rev1-000`

* clear

* adjust order
  • Loading branch information
ghaiszaher authored Nov 23, 2024
1 parent 8adecfd commit 1b2dbf7
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 3 deletions.
133 changes: 133 additions & 0 deletions 2024-11-17-rev1-000-test.ipynb
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
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Dissertation:
The full source code is available under GPL-3.0 License in my Github repository <a href="https://github.com/ghaiszaher/Foggy-CycleGAN" target="_blank">ghaiszaher/Foggy-CycleGAN</a>

## Notebook <a href="https://colab.research.google.com/github/ghaiszaher/Foggy-CycleGAN/blob/master/Foggy_CycleGAN.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
A Jupyter Notebook file <a href="https://github.com/ghaiszaher/Foggy-CycleGAN/blob/master/Foggy_CycleGAN.ipynb" target="_blank">Foggy_CycleGAN.ipynb</a> is available in the repository.
A Jupyter Notebook file <a href="./Foggy_CycleGAN.ipynb" target="_blank">Foggy_CycleGAN.ipynb</a> is available in the repository.

## Results (2020)
<p align="center">
Expand Down Expand Up @@ -168,3 +168,6 @@ The results of the new models are similar to the previous ones, here are some sa
</tbody>
</table>
</div>

### 2024-11-17-rev1-000 Test Notebook <a href="https://colab.research.google.com/github/ghaiszaher/Foggy-CycleGAN/blob/master/2024-11-17-rev1-000-test.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
A Jupyter Notebook file <a href="./2024-11-17-rev1-000-test.ipynb" target="_blank">2024-11-17-rev1-000-test.ipynb</a> is available in the repository to test the 2024-11-17-rev1-000 model.
53 changes: 51 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pydot = "^3.0.1"
graphviz = "^0.20.3"
ipython = "^8.26.0"
pandas = "^2.2.2"
gdown = "^5.2.0"


[build-system]
Expand Down

0 comments on commit 1b2dbf7

Please sign in to comment.