{"id":13617543,"url":"https://github.com/angeluriot/Generative_adversarial_network","last_synced_at":"2025-04-14T06:34:24.668Z","repository":{"id":65297174,"uuid":"589356352","full_name":"angeluriot/Generative_adversarial_network","owner":"angeluriot","description":"A deep learning model that can create high quality images by training on a dataset.","archived":false,"fork":false,"pushed_at":"2024-05-06T00:03:28.000Z","size":754452,"stargazers_count":52,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-01T20:47:54.248Z","etag":null,"topics":["deep-learning","gan","generative-ai","pytorch"],"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/angeluriot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-15T22:25:55.000Z","updated_at":"2024-07-30T04:31:15.000Z","dependencies_parsed_at":"2024-08-01T20:46:23.942Z","dependency_job_id":"610fef6a-8ef6-4f31-bf7d-cf9f92ca834e","html_url":"https://github.com/angeluriot/Generative_adversarial_network","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/angeluriot%2FGenerative_adversarial_network","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeluriot%2FGenerative_adversarial_network/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeluriot%2FGenerative_adversarial_network/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeluriot%2FGenerative_adversarial_network/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/angeluriot","download_url":"https://codeload.github.com/angeluriot/Generative_adversarial_network/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223621841,"owners_count":17174768,"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":["deep-learning","gan","generative-ai","pytorch"],"created_at":"2024-08-01T20:01:43.420Z","updated_at":"2024-11-08T02:30:40.835Z","avatar_url":"https://github.com/angeluriot.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# 🎨 Generative Adversarial Network (GAN)\n\n![Release](https://img.shields.io/badge/Release-v2.1-blueviolet)\n![Language](https://img.shields.io/badge/Language-Python-f2cb1b)\n![Libraries](https://img.shields.io/badge/Libraries-PyTorch-00cf2c)\n![Size](https://img.shields.io/badge/Size-15Mo-f12222)\n![Open Source](https://badges.frapsoft.com/os/v2/open-source.svg?v=103)\n\n\u003cbr/\u003e\n\nThis project is a deep convolutional generative adversarial network that can create high quality images from a random seed like portraits, animals, drawings and more.\n\n\u003cbr/\u003e\n\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"resources/misc/thumbnail.png\" width=\"750\"\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n# 📋 Summary\n\n* **[📋 Summary](#-summary)**\n* **[🤖 Model](#-model)**\n\t* [🏗️ Architecture](#%EF%B8%8F-architecture)\n\t* [🧪 Tests](#-tests)\n\t* [🎛️ Trained weights](#%EF%B8%8F-trained-weights)\n* **[📦 Dependencies](#-dependencies)**\n* **[🦾 Training](#-training)**\n* **[⚗️ Testing](#%EF%B8%8F-testing)**\n* **[🙏 Credits](#-credits)**\n\n\u003cbr/\u003e\n\n# 🤖 Model\n\n## 🏗️ Architecture\n\nThe model is a Generative Adversarial Network (GAN) like described in the paper [**Generative Adversarial Nets**](https://doi.org/10.48550/arXiv.1406.2661) from **Montreal University** (2014)\n\nThe generator and the discriminator are both deep convolutional neural networks like in the paper [**Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks**](https://doi.org/10.48550/arXiv.1511.06434) from **Facebook AI Research** (2015) but with a few improvements:\n\n### For both networks:\n\n* I added **Equalized Learning Rate Layers** from the paper [**Progressive Growing of GANs for Improved Quality, Stability, and Variation**](https://doi.org/10.48550/arXiv.1710.10196) by **Nvidia** (2017)\n\n* I added **Bilinear Upsampling / Downsampling** from the paper [**Making Convolutional Networks Shift-Invariant Again**](https://doi.org/10.48550/arXiv.1904.11486) by **Adobe Research** (2019)\n\n* I implemented **Wavelet Transform** from the paper [**SWAGAN: A Style-based Wavelet-driven Generative Model**](https://doi.org/10.48550/arXiv.2102.06108) by **Tel-Aviv University** (2021)\n\n### For the generator:\n\n* I used a **Style-Based Architecture** with a **Constant Input**, **Learned Styles** from a **Mapping Network** and **Noise Injection** from the paper [**A Style-Based Generator Architecture for Generative Adversarial Networks**](https://doi.org/10.48550/arXiv.1812.04948) by **Nvidia** (2018)\n\n* I added **Skip Connections** from the paper [**MSG-GAN: Multi-Scale Gradients for Generative Adversarial Networks**](https://doi.org/10.48550/arXiv.1903.06048) by **TomTom** and **Adobe** (2019)\n\n### For the discriminator:\n\n* I added **Residual Blocks** from the paper [**Deep Residual Learning for Image Recognition**](https://doi.org/10.48550/arXiv.1512.03385) by **Microsoft Research** (2015)\n\n* I added **Minibatch Standard Deviation** at the end of the discriminator from the paper [**Improved Techniques for Training GANs**](https://doi.org/10.48550/arXiv.1606.03498) by **OpenAI** (2016)\n\n### For training:\n\n* I kept the original **Non-Saturating Loss** from the paper [**Generative Adversarial Nets**](https://doi.org/10.48550/arXiv.1406.2661) by **Montreal University** (2014)\n\n* I added **Path Length Regularization** on the generator from the paper [**Analyzing and Improving the Image Quality of StyleGAN**](https://doi.org/10.48550/arXiv.1912.04958) by **Nvidia** (2019)\n\n* I added **Gradient Penalty Regularization** on the discriminator from the paper [**Improved Training of Wasserstein GANs**](https://doi.org/10.48550/arXiv.1704.00028) by **Google Brain** (2017)\n\n* I added **Adaptive Discriminator Augmentation (ADA)** from the paper [**Training Generative Adversarial Networks with Limited Data**](https://doi.org/10.48550/arXiv.2006.06676) by **Nvidia** (2020) but the augmentation probability is not trained and has to be set manually *(and some augmentations are disabled because of a missing PyTorch implementation)*\n\n### For testing:\n\n* I added the computation of the **Fréchet Inception Distance (FID)** during training from the paper [**GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium**](https://doi.org/10.48550/arXiv.1706.08500) by **University Linz** (2017) using the **pytorch-fid** module\n\n* I added a **Projector** like in the paper [**Analyzing and Improving the Image Quality of StyleGAN**](https://doi.org/10.48550/arXiv.1912.04958) by **Nvidia** (2019)\n\n\u003cbr/\u003e\n\n## 🧪 Tests\n\n\u003cp align=\"center\"\u003e\u003cb\u003eHuman faces 256*256 (FID: 5.97)\u003c/b\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"resources/misc/faces.png\" width=\"650\"\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n\u003cp align=\"center\"\u003e\u003cb\u003eAnimal faces 256*256 (FID: 6.56)\u003c/b\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"resources/misc/animals.png\" width=\"650\"\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n\u003cp align=\"center\"\u003e\u003cb\u003eAnime faces 256*256 (FID: 3.74)\u003c/b\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"resources/misc/anime.png\" width=\"650\"\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n\u003cp align=\"center\"\u003e\u003cb\u003ePainting faces 256*256 (FID: 20.32)\u003c/b\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"resources/misc/paintings.png\" width=\"650\"\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n## 🎛️ Trained weights\n\nThe trained weights on multiple datasets are available on [**Google Drive**](https://drive.google.com/drive/folders/1m4Puqmb9OD8dcbgr7HStpT7QIFksJ8LR?usp=sharing), you just need to download the `.pt` files and put them in the `models` folder.\n\n\u003cbr/\u003e\n\n# 📦 Dependencies\n\n* [**Python**](https://www.python.org/)\n* [**PyTorch**](https://pytorch.org/)\n* [**Matplotlib**](https://matplotlib.org/)\n* [**Pillow**](https://pillow.readthedocs.io/)\n* [**Scipy**](https://www.scipy.org/)\n* [**PSUtil**](https://github.com/giampaolo/psutil)\n* [**PyTorch FID**](https://github.com/mseitzer/pytorch-fid)\n\n\u003cbr/\u003e\n\nRun the following command to install the dependencies:\n```shell\n$ pip install -r requirements.txt\n```\n*(You may need to use a [**specific command**](https://pytorch.org/get-started/locally/) for PyTorch if you want to use CUDA)*\n\n\u003cbr/\u003e\n\n# 🦾 Training\n\n* First, you need to find and download a dataset of images *(less than 5,000 may be too little and more than 150,000 is not necessary)*. You can find a lot of datasets on [**Kaggle**](https://www.kaggle.com/datasets) and the ones I used on [**my Google Drive**](https://drive.google.com/drive/u/1/folders/15nmil1s50AKEL4PvNPsZ1VSGC_jGGLGE).\n\n* Then, in the `training/settings.py` file, specify the **path** to the dataset\n\n* If you don't have an overpriced 24GB GPU like me, the default settings may not work for you. You can try to:\n\t* Lower the **batch size** *(less stable and worse lower point)*\n\t* Increase the **accumulation steps** *(fix previous problems but slower)*\n\t* Lower the **min features** *(worse results)*\n\t* Decrease the **image size**\n\n* Run the `training.ipynb` file *(you can stop the training at any time and resume it later thanks to the checkpoints)*\n\n\u003cbr/\u003e\n\n# ⚗️ Testing\n\n* Run the `testing.ipynb` file to generate random images\n\n* Run the `testing/interpolation.ipynb` file to generate the images of a smooth interpolation video\n\n* Run the `testing/projector.ipynb` file to project real images into the latent space\n\n* Run the `testing/style_mixing.ipynb` file to generate the images of a style mixing interpolation video\n\n* Run the `testing/timelapse.ipynb` file to generate the images of a training timelapse video\n\n\u003cbr/\u003e\n\n# 🙏 Credits\n\n* [**Angel Uriot**](https://github.com/angeluriot) : Creator of the project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangeluriot%2FGenerative_adversarial_network","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangeluriot%2FGenerative_adversarial_network","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangeluriot%2FGenerative_adversarial_network/lists"}