{"id":21858449,"url":"https://github.com/darkfanxing/gan","last_synced_at":"2026-05-16T13:35:12.123Z","repository":{"id":46227979,"uuid":"424847763","full_name":"darkfanxing/GAN","owner":"darkfanxing","description":"Restore image using GAN model","archived":false,"fork":false,"pushed_at":"2021-11-08T07:29:15.000Z","size":102435,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T14:24:55.678Z","etag":null,"topics":["gan","image-restoration","mit-license","python-3-7","tensorflow2","unsupervised-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darkfanxing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-05T06:19:48.000Z","updated_at":"2025-01-07T14:28:39.000Z","dependencies_parsed_at":"2022-08-31T02:41:11.951Z","dependency_job_id":null,"html_url":"https://github.com/darkfanxing/GAN","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkfanxing%2FGAN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkfanxing%2FGAN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkfanxing%2FGAN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkfanxing%2FGAN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darkfanxing","download_url":"https://codeload.github.com/darkfanxing/GAN/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244858200,"owners_count":20522173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gan","image-restoration","mit-license","python-3-7","tensorflow2","unsupervised-learning"],"created_at":"2024-11-28T02:45:34.311Z","updated_at":"2026-05-16T13:35:07.088Z","avatar_url":"https://github.com/darkfanxing.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Table of contents\n- [Project Description](#project-description)\n- [Project Setup](#project-setup)\n- [How To Train Model In this Project](#how-to-train-model-in-this-project)\n- [How To Restore Images In this Project](#how-to-restore-images-in-this-project)\n- [How To Check Model Architecture](#how-to-check-model-architecture)\n\n## Project Description\nThe GAN (Generative Adversarial Netwrok) algorithm is a class of machine learning frameworks designed by Ian Goodfellow and his colleagues in June 2014. It's based on \"Game Theory\", to make two neural networks contest with each other.\n\nThis project will restore image using GAN model, and here is how it works:\n1. Model setup:\n    - Build discriminator and generator by using high-level API of Tensorflow 2, the model architecture is shown below:\n        - \"k(number)\" means a kernel size of \"number by number\"\n        - \"n(number)\" means the corresponding block has \"number\" channels\n        \n        ![](https://i.imgur.com/IQHdCC8.png)\n2. Train model:\n    1. Yields batches of images from `training_data`. The `training_data`'s shape is `(image_count, image_width, image_hight, image_channel)`\n    2. Put the random mask over data (each picture)\n    3. Customize the loss function of discriminator and generator\n        - discriminator's loss function\n            - ![](https://i.imgur.com/bd0OoXI.png)\n        - generator's loss function\n            - ![](https://i.imgur.com/TbQ7Fia.png)\n    4. Gradient descent with respect to variables of discriminator and generator\n        - using `tensorflow.GradientTape` to implement gradient descent\n    5. Plot training progress bar in terminal\n        -  using `rich` packages of Python to plot `epochs`, `completeness`, `generator loss` and `discriminator loss`\n    6. Save model structure and parameters when it finish model training\n3. Image Restoration\n    1. Load trained model\n    2. Get any image with mask fits `training_data`'s shape, e.g. `(image_count, image_width, image_hight, image_channel)`\n    3. Restore image\n\n## Project Setup\nTo avoid TensorFlow version conflicts, the project use pipenv (Python vitural environment) to install Python packages.\n\n\u003e **Notice**: Before executing the following command, please refer to [TensorFlow Installation Source](https://www.tensorflow.org/install/source#linux) and modify the TensorFlow version in `Pipfile` and `Pipfile.lock` (or modify `Pipfile` and remove `Pipfile.lock`)\n\n```console\npip install pipenv\npipenv shell\npipenv install\n```\n\n## How To Train Model In This Project\nIn model training stage, you can modify the model architecture or the hyperparameter in `src/model/GAN.py` like epochs, learning_rate, learning_rate_decay, etc.\n\n```console\npython src/train.py\n```\n\n## How To Restore Images In This Project\nYou can use model you trained or apply the following model to restore images:\n- The example model `generator_example.h5` at `src/model/trained_model/` \n- [Other trained model on Google Drive](https://drive.google.com/drive/folders/1d431KDCVXYkCfmrGskXQ5vD4FXIJ8nUH?usp=sharing)\n\n```console\npython src/predict.py\n```\n\n# How To Check Model Architecture\nYou can modify `model_path` in `src/watch_model_architecture.py` to watch any model you want\n\n```console\npython src/watch_model_architecture.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkfanxing%2Fgan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkfanxing%2Fgan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkfanxing%2Fgan/lists"}